···147147let equal a b = String.equal (to_string a) (to_string b)
148148149149let hash = Hashtbl.hash
150150+151151+module Set = Set.Make (struct
152152+ type nonrec t = t
153153+154154+ let compare = compare
155155+end)
-95
mist/lib/block_map.ml
···11-module Cid_map = Map.Make (Cid)
22-33-module type S = sig
44- type t
55-66- type many = {blocks: t; missing: Cid.t list}
77-88- val add : Lex.value -> Cid.t
99-1010- val update : Cid.t -> bytes -> unit
1111-1212- val find : Cid.t -> bytes option
1313-1414- val remove : Cid.t -> unit
1515-1616- val find_many : Cid.t list -> many
1717-1818- val mem : Cid.t -> bool
1919-2020- val clear : unit -> unit
2121-2222- val iter : (Cid.t -> bytes -> unit) -> unit
2323-2424- val to_list : (Cid.t * bytes) list
2525-2626- val to_seq : (Cid.t * bytes) Seq.t
2727-2828- val cids : Cid.t list
2929-3030- val add_map : t -> t
3131-3232- val cardinal : unit -> int
3333-3434- val byte_size : unit -> int
3535-3636- val equal : t -> bool
3737-end
3838-3939-module Make : S = struct
4040- type t = bytes Cid_map.t
4141-4242- type many = {blocks: t; missing: Cid.t list}
4343-4444- let map : bytes Cid_map.t ref = ref Cid_map.empty
4545-4646- let add value =
4747- let cid, bytes = Lex.to_cbor_block value in
4848- map := Cid_map.add cid bytes !map ;
4949- cid
5050-5151- let update cid bytes = map := Cid_map.add cid bytes !map
5252-5353- let find cid = Cid_map.find_opt cid !map
5454-5555- let remove cid =
5656- map := Cid_map.remove cid !map ;
5757- ()
5858-5959- let find_many cids =
6060- let blocks = Cid_map.empty in
6161- let missing = ref [] in
6262- List.iter
6363- (fun cid ->
6464- match Cid_map.find_opt cid !map with
6565- | Some bytes ->
6666- ignore (Cid_map.add cid bytes blocks)
6767- | None ->
6868- missing := cid :: !missing )
6969- cids ;
7070- {blocks; missing= List.rev !missing}
7171-7272- let mem cid = Cid_map.mem cid !map
7373-7474- let clear () =
7575- Cid_map.iter (fun cid _ -> remove cid) !map ;
7676- ()
7777-7878- let iter f = Cid_map.iter (fun cid bytes -> f cid bytes) !map
7979-8080- let to_list = Cid_map.bindings !map
8181-8282- let to_seq = Cid_map.to_seq !map
8383-8484- let cids = Cid_map.fold (fun cid _ acc -> cid :: acc) !map []
8585-8686- let add_map t =
8787- Cid_map.fold (fun cid bytes acc -> Cid_map.add cid bytes acc) t !map
8888-8989- let cardinal () = Cid_map.cardinal !map
9090-9191- let byte_size () =
9292- Cid_map.fold (fun _ bytes acc -> acc + Bytes.length bytes) !map 0
9393-9494- let equal t = Cid_map.equal ( = ) !map t
9595-end
···11+module type S = sig
22+ type t
33+44+ val put_temp : t -> char Seq.t -> string Lwt.t
55+66+ val make_permanent : t -> string -> Cid.t -> unit Lwt.t
77+88+ val put_permanent : t -> Cid.t -> char Seq.t -> unit Lwt.t
99+1010+ val quarantine : t -> Cid.t -> unit Lwt.t
1111+1212+ val unquarantine : t -> Cid.t -> unit Lwt.t
1313+1414+ val get_bytes : t -> Cid.t -> bytes Lwt.t
1515+1616+ val get_seq : t -> Cid.t -> char Seq.t Lwt.t
1717+1818+ val has_temp : t -> string -> bool Lwt.t
1919+2020+ val has_stored : t -> Cid.t -> bool Lwt.t
2121+2222+ val delete : t -> Cid.t -> unit Lwt.t
2323+2424+ val delete_many : t -> Cid.t list -> unit Lwt.t
2525+end
+46
mist/lib/storage/block_map.ml
···11+module Cid_map = Map.Make (Cid)
22+33+type t = bytes Cid_map.t
44+55+type with_missing = {blocks: t; missing: Cid.t list}
66+77+let empty = Cid_map.empty
88+99+let add m value =
1010+ let cid, bytes = Lex.to_cbor_block value in
1111+ (Cid_map.add cid bytes m, cid)
1212+1313+let set m cid bytes = Cid_map.add cid bytes m
1414+1515+let get m cid = Cid_map.find_opt cid m
1616+1717+let remove m cid = Cid_map.remove cid m
1818+1919+let get_many m cids =
2020+ let blocks, missing =
2121+ List.fold_left
2222+ (fun (b, mis) cid ->
2323+ match get m cid with
2424+ | Some bytes ->
2525+ (Cid_map.add cid bytes b, mis)
2626+ | None ->
2727+ (b, mis @ [cid]) )
2828+ (Cid_map.empty, []) cids
2929+ in
3030+ {blocks; missing= List.rev missing}
3131+3232+let has = Cid_map.mem
3333+3434+let iter = Cid_map.iter
3535+3636+let entries = Cid_map.bindings
3737+3838+let merge m m' =
3939+ let m = Cid_map.fold (fun cid bytes m -> Cid_map.add cid bytes m) m m in
4040+ Cid_map.fold (fun cid bytes m -> Cid_map.add cid bytes m) m' m
4141+4242+let size = Cid_map.cardinal
4343+4444+let byte_size m = Cid_map.fold (fun _ bytes acc -> acc + Bytes.length bytes) m 0
4545+4646+let equal = Cid_map.equal Bytes.equal
+35
mist/lib/storage/storage.ml
···11+module Block_map = Block_map
22+33+type commit_data =
44+ { cid: Cid.t
55+ ; rev: string
66+ ; since: string option
77+ ; prev: Cid.t option
88+ ; relevant_blocks: Block_map.t
99+ ; removed_cids: Cid.Set.t }
1010+1111+module type S = sig
1212+ type t
1313+1414+ val get_root : t -> Cid.t option Lwt.t
1515+1616+ val put_block : t -> Cid.t -> bytes -> rev:string -> unit Lwt.t
1717+1818+ val put_many : t -> Block_map.t -> unit Lwt.t
1919+2020+ val update_root : t -> Cid.t -> rev:string -> unit Lwt.t
2121+2222+ val apply_commit : t -> commit_data -> unit Lwt.t
2323+2424+ val get_bytes : t -> Cid.t -> bytes option Lwt.t
2525+2626+ val has : t -> Cid.t -> bool Lwt.t
2727+2828+ val get_blocks : t -> Cid.t list -> Block_map.with_missing Lwt.t
2929+3030+ val read_obj_and_bytes : t -> Cid.t -> (Dag_cbor.value * bytes) option Lwt.t
3131+3232+ val read_obj : t -> Cid.t -> Dag_cbor.value option Lwt.t
3333+3434+ val read_record : t -> Cid.t -> Lex.repo_record
3535+end