forked from
futur.blue/pegasus
objective categorical abstract machine language personal data server
1module Cid_map = Map.Make (Cid)
2
3type t = bytes Cid_map.t
4
5type with_missing = {blocks: t; missing: Cid.t list}
6
7let empty : t = Cid_map.empty
8
9let add value m =
10 let cid, bytes = Lex.to_cbor_block value in
11 (Cid_map.add cid bytes m, cid)
12
13let set = Cid_map.add
14
15let get = Cid_map.find_opt
16
17let remove = Cid_map.remove
18
19let get_many cids m =
20 let blocks, missing =
21 List.partition_map
22 (fun cid ->
23 match get cid m with Some data -> Left (cid, data) | None -> Right cid )
24 cids
25 in
26 {blocks= Cid_map.of_list blocks; missing}
27
28let has = Cid_map.mem
29
30let iter = Cid_map.iter
31
32let entries = Cid_map.bindings
33
34let keys m = Cid_map.bindings m |> List.map fst
35
36let merge m m' =
37 let m = Cid_map.fold (fun cid bytes m -> Cid_map.add cid bytes m) m m in
38 Cid_map.fold (fun cid bytes m -> Cid_map.add cid bytes m) m' m
39
40let of_seq = Cid_map.of_seq
41
42let size = Cid_map.cardinal
43
44let length = size
45
46let is_empty = Cid_map.is_empty
47
48let byte_size m = Cid_map.fold (fun _ bytes acc -> acc + Bytes.length bytes) m 0
49
50let equal = Cid_map.equal Bytes.equal