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).
···168168 mutable refs : 'hash String_map.t;
169169}
170170171171-module Memory_of (H : HASH) = struct
172172- type hash = H.t
173173- type t = hash mem_state
171171+module Memory = struct
172172+ module Of_hash (H : HASH) = struct
173173+ type hash = H.t
174174+ type t = hash mem_state
174175175175- let read s h = String_map.find_opt (H.to_hex h) s.objects
176176- let write s h data = s.objects <- String_map.add (H.to_hex h) data s.objects
177177- let exists s h = String_map.mem (H.to_hex h) s.objects
178178- let get_ref s name = String_map.find_opt name s.refs
179179- let set_ref s name h = s.refs <- String_map.add name h s.refs
176176+ let read s h = String_map.find_opt (H.to_hex h) s.objects
177177+ let write s h data = s.objects <- String_map.add (H.to_hex h) data s.objects
178178+ let exists s h = String_map.mem (H.to_hex h) s.objects
179179+ let get_ref s name = String_map.find_opt name s.refs
180180+ let set_ref s name h = s.refs <- String_map.add name h s.refs
180181181181- let test_and_set_ref s name ~test ~set =
182182- let current = String_map.find_opt name s.refs in
183183- let matches =
184184- match (test, current) with
185185- | None, None -> true
186186- | Some t, Some c -> H.equal t c
187187- | _ -> false
188188- in
189189- if matches then (
190190- (match set with
191191- | None -> s.refs <- String_map.remove name s.refs
192192- | Some h -> s.refs <- String_map.add name h s.refs);
193193- true)
194194- else false
182182+ let test_and_set_ref s name ~test ~set =
183183+ let current = String_map.find_opt name s.refs in
184184+ let matches =
185185+ match (test, current) with
186186+ | None, None -> true
187187+ | Some t, Some c -> H.equal t c
188188+ | _ -> false
189189+ in
190190+ if matches then (
191191+ (match set with
192192+ | None -> s.refs <- String_map.remove name s.refs
193193+ | Some h -> s.refs <- String_map.add name h s.refs);
194194+ true)
195195+ else false
195196196196- let list_refs s = String_map.bindings s.refs |> List.map fst
197197+ let list_refs s = String_map.bindings s.refs |> List.map fst
197198198198- let write_batch s objects =
199199- List.iter
200200- (fun (h, data) -> s.objects <- String_map.add (H.to_hex h) data s.objects)
201201- objects
199199+ let write_batch s objects =
200200+ List.iter
201201+ (fun (h, data) ->
202202+ s.objects <- String_map.add (H.to_hex h) data s.objects)
203203+ objects
202204203203- let flush _ = ()
204204- let close _ = ()
205205- let empty () : t = { objects = String_map.empty; refs = String_map.empty }
206206-end
205205+ let flush _ = ()
206206+ let close _ = ()
207207+ let empty () : t = { objects = String_map.empty; refs = String_map.empty }
208208+ end
207209208208-let memory (type h) (to_hex : h -> string) (equal : h -> h -> bool) : h t =
209209- let module H = struct
210210- type t = h
210210+ let v (type h) (to_hex : h -> string) (equal : h -> h -> bool) : h t =
211211+ let module H = struct
212212+ type t = h
211213212212- let to_hex = to_hex
213213- let equal = equal
214214- end in
215215- let module B = Memory_of (H) in
216216- let module P = Make (B) in
217217- P.v (B.empty ())
214214+ let to_hex = to_hex
215215+ let equal = equal
216216+ end in
217217+ let module B = Of_hash (H) in
218218+ let module P = Make (B) in
219219+ P.v (B.empty ())
218220219219-module Memory = struct
220220- let sha1 () = memory Hash.to_hex Hash.equal
221221- let sha256 () = memory Hash.to_hex Hash.equal
222222- let cid () = memory Atp.Cid.to_string Atp.Cid.equal
221221+ let sha1 () = v Hash.to_hex Hash.equal
222222+ let sha256 () = v Hash.to_hex Hash.equal
223223+ let cid () = v Atp.Cid.to_string Atp.Cid.equal
223224end
224225225226(* ===== Disk backend ===== *)
+5-5
lib/backend.mli
···58585959(** {1 Memory Backend} *)
60606161-module Memory_of (H : HASH) : sig
6262- include S with type hash = H.t
6161+module Memory : sig
6262+ module Of_hash (H : HASH) : sig
6363+ include S with type hash = H.t
63646464- val empty : unit -> t
6565-end
6565+ val empty : unit -> t
6666+ end
66676767-module Memory : sig
6868 val sha1 : unit -> Hash.sha1 t
6969 val sha256 : unit -> Hash.sha256 t
7070 val cid : unit -> Atp.Cid.t t
···1212 let equal = F.hash_equal
1313 end
14141515- module Mem = Backend.Memory_of (Mem_hash)
1515+ module Mem = Backend.Memory.Of_hash (Mem_hash)
1616 module Mem_packed = Backend.Make (Mem)
17171818 type status =