Indexable.Of_content_addressable
An indexable store is a read-write store in which values can be added and later found via their keys.
Keys are not necessarily portable between different stores, so each store provides an index
mechanism to find keys by the hashes of the values they reference.
module Key : Type.S
module S : Content_addressable.S with type key = Key.t
Read-only stores are store where it is only possible to read existing values.
type 'a t = 'a S.t
The type for stores. The 'a
phantom type carries information about the store mutability.
type value = S.value
The type for raw values.
val mem : [> Perms.read ] t -> key -> bool Lwt.t
mem t k
is true iff k
is present in t
.
val find : [> Perms.read ] t -> key -> value option Lwt.t
find t k
is Some v
if k
is associated to v
in t
and None
is k
is not present in t
.
val close : 'a t -> unit Lwt.t
close t
frees up all the resources associated with t
. Any operations run on a closed handle will raise Closed
.
val add : [> Perms.write ] t -> value -> key Lwt.t
Write the contents of a value to the store, and obtain its key.
val unsafe_add : [> Perms.write ] t -> hash -> value -> key Lwt.t
Same as add
but allows specifying the value's hash directly. The backend might choose to discard that hash and/or can be corrupt if the hash is not consistent.
val index : [> Perms.read ] t -> hash -> key option Lwt.t
Indexing maps the hash of a value to a corresponding key of that value in the store. For stores that are addressed by hashes directly, this is typically fun _t h -> Lwt.return (Key.of_hash h)
; for stores with more complex addressing schemes, index
may attempt a lookup operation in the store.
In general, indexing is best-effort and reveals no information about the membership of the value in the store. In particular:
index t hash = Some key
doesn't guarantee mem t key
: the value with hash hash
may still be absent from the store;index t hash = None
doesn't guarantee that there is no key
such that mem t key
and Key.to_hash key = hash
: the value may still be present in the store under a key that is not indexed.val batch :
Perms.read t ->
([ Perms.read | Perms.write ] t -> 'a Lwt.t) ->
'a Lwt.t
batch t f
applies the writes in f
in a separate batch. The exact guarantees depend on the implementation.