···168168 mutable refs : 'hash String_map.t;
169169}
170170171171-module Memory (H : HASH) : S with type hash = H.t and type t = H.t mem_state =
172172-struct
171171+module Memory_of (H : HASH) :
172172+ S with type hash = H.t and type t = H.t mem_state = struct
173173 type hash = H.t
174174 type t = hash mem_state
175175···207207208208let empty_mem_state () = { objects = String_map.empty; refs = String_map.empty }
209209210210-let memory (type h) (to_hex : h -> string) (equal : h -> h -> bool) : h t =
210210+let pack_memory (type h) (to_hex : h -> string) (equal : h -> h -> bool) : h t =
211211 let module H = struct
212212 type t = h
213213214214 let to_hex = to_hex
215215 let equal = equal
216216 end in
217217- let module B = Memory (H) in
217217+ let module B = Memory_of (H) in
218218 let module P = Make (B) in
219219 P.v (empty_mem_state ())
220220221221-let memory_sha1 () = memory Hash.to_hex Hash.equal
222222-let memory_sha256 () = memory Hash.to_hex Hash.equal
223223-let memory_cid () = memory Atp.Cid.to_string Atp.Cid.equal
221221+module Memory = struct
222222+ let sha1 () = pack_memory Hash.to_hex Hash.equal
223223+ let sha256 () = pack_memory Hash.to_hex Hash.equal
224224+ let cid () = pack_memory Atp.Cid.to_string Atp.Cid.equal
225225+end
224226225227(* ===== Disk backend ===== *)
228228+229229+module Pack = Make
226230227231module Disk = struct
228232 module String_map = Map.Make (String)
···508512 s.data_file <- None)
509513 end
510514511511- let create_with_hash (type h) ~sw (root : Eio.Fs.dir_ty Eio.Path.t)
515515+ let pack_disk (type h) ~sw (root : Eio.Fs.dir_ty Eio.Path.t)
512516 (to_hex : h -> string) (of_hex : string -> (h, [ `Msg of string ]) result)
513517 (equal : h -> h -> bool) : h t =
514518 if not (Eio.Path.is_directory root) then
···529533 let equal = equal
530534 end in
531535 let module B = Make (H) in
532532- let module P = Make (B) in
536536+ let module P = Pack (B) in
533537 P.v
534538 {
535539 root;
···544548 mutex = Eio.Mutex.create ();
545549 }
546550547547- let create_sha1 ~sw root =
548548- create_with_hash ~sw root Hash.to_hex Hash.sha1_of_hex Hash.equal
551551+ let sha1 ~sw root = pack_disk ~sw root Hash.to_hex Hash.sha1_of_hex Hash.equal
549552550550- let create_sha256 ~sw root =
551551- create_with_hash ~sw root Hash.to_hex Hash.sha256_of_hex Hash.equal
553553+ let sha256 ~sw root =
554554+ pack_disk ~sw root Hash.to_hex Hash.sha256_of_hex Hash.equal
552555553553- let create_cid ~sw root =
554554- create_with_hash ~sw root Atp.Cid.to_string
556556+ let cid ~sw root =
557557+ pack_disk ~sw root Atp.Cid.to_string
555558 (fun s ->
556559 try Ok (Atp.Cid.of_string s)
557560 with exn ->
+20-26
lib/backend.mli
···2233(** {1 Backend Interface} *)
4455+module type HASH = sig
66+ type t
77+88+ val to_hex : t -> string
99+ val equal : t -> t -> bool
1010+end
1111+512module type S = sig
613 type t
714 type hash
···2027 val flush : t -> unit
2128 val close : t -> unit
2229end
3030+3131+(** {1 Packed Backend} *)
23322433type 'hash t
2525-(** A packed storage backend. *)
3434+(** An abstract storage backend. *)
26352736module Make (B : S) : sig
2837 val v : B.t -> B.hash t
···3948val flush : 'h t -> unit
4049val close : 'h t -> unit
41504242-(** {1 Combinator Functors}
4343-4444- Compose at the module level, then pack with {!Make}:
4545- {[
4646- module My_backend = Backend.Cached (Backend.Disk.Impl (...))
4747- module P = Backend.Make (My_backend)
4848- let backend = P.v state
4949- ]} *)
5151+(** {1 Combinator Functors} *)
50525153module Cached (B : S) : S with type hash = B.hash
5254module Readonly (B : S) : S with type t = B.t and type hash = B.hash
···56585759(** {1 Memory Backend} *)
58606161+module Memory_of (H : HASH) : S with type hash = H.t
6262+5963module Memory : sig
6060- val create_with_hash : ('h -> string) -> ('h -> 'h -> bool) -> 'h t
6161- val create_sha1 : unit -> Hash.sha1 t
6262- val create_sha256 : unit -> Hash.sha256 t
6363- val create_cid : unit -> Atp.Cid.t t
6464+ val sha1 : unit -> Hash.sha1 t
6565+ val sha256 : unit -> Hash.sha256 t
6666+ val cid : unit -> Atp.Cid.t t
6467end
65686669(** {1 Disk Backend} *)
67706871module Disk : sig
6969- val create_with_hash :
7070- sw:Eio.Switch.t ->
7171- Eio.Fs.dir_ty Eio.Path.t ->
7272- ('h -> string) ->
7373- (string -> ('h, [ `Msg of string ]) result) ->
7474- ('h -> 'h -> bool) ->
7575- 'h t
7272+ module Make (H : HASH) : S with type hash = H.t
76737777- val create_sha1 : sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Hash.sha1 t
7878-7979- val create_sha256 :
8080- sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Hash.sha256 t
8181-8282- val create_cid : sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Atp.Cid.t t
7474+ val sha1 : sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Hash.sha1 t
7575+ val sha256 : sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Hash.sha256 t
7676+ val cid : sw:Eio.Switch.t -> Eio.Fs.dir_ty Eio.Path.t -> Atp.Cid.t t
8377end
84788579(** {1 Statistics} *)