Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move Memory_of functor into Backend.Memory.Of_hash

Backend.Memory.Of_hash(H) replaces Backend.Memory_of(H).
The functor now lives inside the Memory module alongside
the convenience constructors (sha1, sha256, cid).

+52 -51
+45 -44
lib/backend.ml
··· 168 168 mutable refs : 'hash String_map.t; 169 169 } 170 170 171 - module Memory_of (H : HASH) = struct 172 - type hash = H.t 173 - type t = hash mem_state 171 + module Memory = struct 172 + module Of_hash (H : HASH) = struct 173 + type hash = H.t 174 + type t = hash mem_state 174 175 175 - let read s h = String_map.find_opt (H.to_hex h) s.objects 176 - let write s h data = s.objects <- String_map.add (H.to_hex h) data s.objects 177 - let exists s h = String_map.mem (H.to_hex h) s.objects 178 - let get_ref s name = String_map.find_opt name s.refs 179 - let set_ref s name h = s.refs <- String_map.add name h s.refs 176 + let read s h = String_map.find_opt (H.to_hex h) s.objects 177 + let write s h data = s.objects <- String_map.add (H.to_hex h) data s.objects 178 + let exists s h = String_map.mem (H.to_hex h) s.objects 179 + let get_ref s name = String_map.find_opt name s.refs 180 + let set_ref s name h = s.refs <- String_map.add name h s.refs 180 181 181 - let test_and_set_ref s name ~test ~set = 182 - let current = String_map.find_opt name s.refs in 183 - let matches = 184 - match (test, current) with 185 - | None, None -> true 186 - | Some t, Some c -> H.equal t c 187 - | _ -> false 188 - in 189 - if matches then ( 190 - (match set with 191 - | None -> s.refs <- String_map.remove name s.refs 192 - | Some h -> s.refs <- String_map.add name h s.refs); 193 - true) 194 - else false 182 + let test_and_set_ref s name ~test ~set = 183 + let current = String_map.find_opt name s.refs in 184 + let matches = 185 + match (test, current) with 186 + | None, None -> true 187 + | Some t, Some c -> H.equal t c 188 + | _ -> false 189 + in 190 + if matches then ( 191 + (match set with 192 + | None -> s.refs <- String_map.remove name s.refs 193 + | Some h -> s.refs <- String_map.add name h s.refs); 194 + true) 195 + else false 195 196 196 - let list_refs s = String_map.bindings s.refs |> List.map fst 197 + let list_refs s = String_map.bindings s.refs |> List.map fst 197 198 198 - let write_batch s objects = 199 - List.iter 200 - (fun (h, data) -> s.objects <- String_map.add (H.to_hex h) data s.objects) 201 - objects 199 + let write_batch s objects = 200 + List.iter 201 + (fun (h, data) -> 202 + s.objects <- String_map.add (H.to_hex h) data s.objects) 203 + objects 202 204 203 - let flush _ = () 204 - let close _ = () 205 - let empty () : t = { objects = String_map.empty; refs = String_map.empty } 206 - end 205 + let flush _ = () 206 + let close _ = () 207 + let empty () : t = { objects = String_map.empty; refs = String_map.empty } 208 + end 207 209 208 - let memory (type h) (to_hex : h -> string) (equal : h -> h -> bool) : h t = 209 - let module H = struct 210 - type t = h 210 + let v (type h) (to_hex : h -> string) (equal : h -> h -> bool) : h t = 211 + let module H = struct 212 + type t = h 211 213 212 - let to_hex = to_hex 213 - let equal = equal 214 - end in 215 - let module B = Memory_of (H) in 216 - let module P = Make (B) in 217 - P.v (B.empty ()) 214 + let to_hex = to_hex 215 + let equal = equal 216 + end in 217 + let module B = Of_hash (H) in 218 + let module P = Make (B) in 219 + P.v (B.empty ()) 218 220 219 - module Memory = struct 220 - let sha1 () = memory Hash.to_hex Hash.equal 221 - let sha256 () = memory Hash.to_hex Hash.equal 222 - let cid () = memory Atp.Cid.to_string Atp.Cid.equal 221 + let sha1 () = v Hash.to_hex Hash.equal 222 + let sha256 () = v Hash.to_hex Hash.equal 223 + let cid () = v Atp.Cid.to_string Atp.Cid.equal 223 224 end 224 225 225 226 (* ===== Disk backend ===== *)
+5 -5
lib/backend.mli
··· 58 58 59 59 (** {1 Memory Backend} *) 60 60 61 - module Memory_of (H : HASH) : sig 62 - include S with type hash = H.t 61 + module Memory : sig 62 + module Of_hash (H : HASH) : sig 63 + include S with type hash = H.t 63 64 64 - val empty : unit -> t 65 - end 65 + val empty : unit -> t 66 + end 66 67 67 - module Memory : sig 68 68 val sha1 : unit -> Hash.sha1 t 69 69 val sha256 : unit -> Hash.sha256 t 70 70 val cid : unit -> Atp.Cid.t t
+1 -1
lib/proof.ml
··· 190 190 let equal = C.hash_equal 191 191 end 192 192 193 - module Replay_mem = Backend.Memory_of (Replay_hash) 193 + module Replay_mem = Backend.Memory.Of_hash (Replay_hash) 194 194 module Replay_packed = Backend.Make (Replay_mem) 195 195 196 196 (* Hash-keyed tables for recording backend reads. *)
+1 -1
lib/subtree.ml
··· 12 12 let equal = F.hash_equal 13 13 end 14 14 15 - module Mem = Backend.Memory_of (Mem_hash) 15 + module Mem = Backend.Memory.Of_hash (Mem_hash) 16 16 module Mem_packed = Backend.Make (Mem) 17 17 18 18 type status =