From: Tom Ridge <tom.j.ridge+list@googlemail.com>
To: caml-list <caml-list@inria.fr>, mirageos-devel@lists.xenproject.org
Subject: [Caml-list] [ANN] tjr_btree 0.1.0 (initial release)
Date: Thu, 4 May 2017 09:24:44 +0100 [thread overview]
Message-ID: <CABooLwPPGEsO=+Ycubd0gYZZ9V2jx=RNi8rZXeU0mPvOrGT0tg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1639 bytes --]
tjr_btree is a B-tree library written in OCaml. The examples include a
simple on-disk key-value store.
https://github.com/tomjridge/tjr_btree
Example:
----
(** A simple example of a kv store. *)
open Small_string.O
(* SS is now an alias for Small_string *)
open Ss_ss_map_on_fd
(* filename *)
let fn = Default.default_filename
(* construct keys and values from an int *)
let k x = "k"^(string_of_int x) |> SS.of_string
let v x = "v"^(string_of_int x) |> SS.of_string
(* create and init store, write some values, and close *)
let do_write () = (
print_endline "Writing...";
(* create and initialize *)
let s = ref (from_file ~fn ~create:true ~init:true) in
(* get map operations *)
let map_ops = imperative_map_ops s in
(* write values *)
for x=1 to 1000 do
(* TODO this would be much faster if we used insert_many *)
map_ops.insert (k x) (v x);
done;
(* close *)
close !s
)
(* open store, delete some values, and close *)
let do_delete () = (
print_endline "Deleting...";
let s = ref (from_file ~fn ~create:false ~init:false) in
let map_ops = imperative_map_ops s in
for x=100 to 200 do
map_ops.delete (k x);
done;
close !s
)
(* open store and check whether various keys and values are correct *)
let do_check () = (
print_endline "Checking...";
let s = ref (from_file ~fn ~create:false ~init:false) in
let map_ops = imperative_map_ops s in
assert(map_ops.find (SS.of_string("k100")) = None);
assert(map_ops.find (SS.of_string("k1000")) =
Some(SS.of_string("v1000")));
close !s
)
(* actually execute the above *)
let _ = (
do_write();
do_delete();
do_check()
)
----
[-- Attachment #2: Type: text/html, Size: 2545 bytes --]
reply other threads:[~2017-05-04 8:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABooLwPPGEsO=+Ycubd0gYZZ9V2jx=RNi8rZXeU0mPvOrGT0tg@mail.gmail.com' \
--to=tom.j.ridge+list@googlemail.com \
--cc=caml-list@inria.fr \
--cc=mirageos-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox