package cdb
Install
Dune Dependency
Authors
Maintainers
Sources
md5=deb487b574cf1a925424b410627a9e05
sha512=fedf279196fa894e7a7fdc47ccc05ad7b32e6e98a2ad51281aab78a3715de42a46efbc2c34861d0df8f5f0280ca5ff3520516bc648dfbc32e3db0c2161507dc7
Description
CDB (Constant Database) is a fast, reliable, simple package for creating and reading constant databases.
Published: 09 Jul 2024
README
README.md
This is Dustin Sallings OCaml CDB library, pulled from the 2007 wayback machine.
It has been updated to work with OCaml 5.2.0 by Jesse.
What is CDB?
CDB is a simple and elegant constant database. Think of it as an associative array on disk. Reads are fast, but writes are slow because the whole file needs to be rebuilt for every change.
It comes from a time when CPUs were much slower, disks were much smaller, and being clever about how you use resources mattered much more. Today, SQLite and/or JSON are probably better choices in most situations.
Further reading:
https://cr.yp.to/cdb/cdb.txt and https://cr.yp.to/cdb.html
http://www.cse.yorku.ca/~oz/hash.html
https://www.unixuser.org/~euske/doc/cdbinternals/index.html
Getting Started
opam install cdb
Read a value
(* Open the CDB for searching *)
let cdb_file = Cdb.open_cdb_in "my_cdb.cdb" in
(* Get matches for a key *)
let matches = Cdb.get_matches cdb_file "key1" in
(* Iterate over the matches and print them *)
Seq.iter (fun value -> print_endline ("Found value: " ^ value)) matches;
(* Close the CDB file *)
Cdb.close_cdb_in cdb_file
Writing values
(* Create and populate a CDB *)
let creator = Cdb.open_out "my_cdb.cdb" in
Cdb.add creator "key1" "value1";
Cdb.add creator "key2" "value2";
Cdb.close_cdb_out creator;
Contributor
dune build
Test
dune exec ./test/main.exe