cdb.txt 708 B

12345678910111213141516171819202122232425262728293031323334
  1. read_uiui_le
  2. add_entry cdb (key val)
  3. if the file is empty
  4. write 2048 zero bytes
  5. else if the file has set p[0] > 2048
  6. set p[0..255] to 2048 zero bytes
  7. chop it off at p[0]
  8. else
  9. fseek eof
  10. append key val
  11. do_index cdb
  12. if the file has set p[0] > 2048
  13. chop it off
  14. set p[0..255] to 2048 zero bytes
  15. else
  16. fseek 2048
  17. walk all records – from 2048 to eof
  18. feed a map with key -> pos
  19. or maybe a map of maps: hash%256 -> key -> pos
  20. 0..255 each
  21. write pos and count to p[n]
  22. sort acc ((hash / 256) % count), hash, key
  23. http://cr.yp.to/cdb/cdb.txt
  24. https://packages.debian.org/buster/tinycdb
  25. https://github.com/dustin/snippets/blob/master/ocaml/lib/cdb.ml