package octez-libs

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
include Aches.Vache.MAP with type key = t
type key = t

The type of keys on which values in the cache are indexed.

type 'a t

The type of caches holding bindings from key to 'a

val create : int -> 'a t

create n creates a cache with a size-bound of n. Remember that the size-bound is not upheld strictly by all caches.

val replace : 'a t -> key -> 'a -> unit

replace c k v binds the key k to the value v in the cache c. This may or may not cause another binding to be removed from the cache, depending on the number of bindings already present in the cache c, the size-bound of the cache c, and the policy of the cache c towards its size-bound.

If k is already bound to a value in c, the previous binding disappears and is replaced by the new binding to v.

Note that in caches with a Sloppy accounting policy, the old (removed) binding may still count towards the size bound for some time.

val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b

fold f c init folds the function f and value init over the bindings of c from newest to oldest.

Note that for caches with a Weak overflow policy, this function may fold over a subset of the bindings of c. See Vache (or Functors) for more details.

val fold_oldest_first : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b

fold_oldest_first is like fold but in reversed order: oldest elements of c first. This function has the same limitation as fold.

val find_opt : 'a t -> key -> 'a option

find_opt c k is Some v if k is bound to v in c. It is None otherwise.

Note that the in caches with a non-FIFO replacement policy, this may have a side effect on the k-to-v binding. Specifically, in those caches, it might make it less likely to be removed when supernumerary bindings are inserted.

val remove : 'a t -> key -> unit

remove c k removes the binding from k in c. If k is not bound in c, it does nothing.

Note that in caches with a Sloppy accounting policy, removed bindings can still count towards the size bound for some time.

val length : 'a t -> int

length c is the number of bindings held by c.

val capacity : 'a t -> int

capacity c is the number of bindings c can hold: capacity (create n) = n

val clear : 'a t -> unit

clear c removes all bindings from c.

module H : Stdlib.Hashtbl.HashedType with type t = key
val encoding : 'a Data_encoding.t -> 'a t Data_encoding.t
OCaml

Innovation. Community. Security.