package async_extra

  1. Overview
  2. Docs

Like Core.Weak_hashtbl, but automatically collects keys with unused data, rather than requiring user code to call remove_keys_with_unused_data.

include module type of Core.Weak_hashtbl
type ('a, 'b) t = ('a, 'b) Core.Weak_hashtbl.t
include sig ... end
val sexp_of_t : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> ('b -> Ppx_sexp_conv_lib.Sexp.t) -> ('a, 'b) t -> Ppx_sexp_conv_lib.Sexp.t
val create : ?growth_allowed:bool -> ?size:int -> (module Core_kernel.Hashtbl.Key_plain with type t = 'a) -> ('a, 'b) t

growth_allowed and size are both optionally passed on to the underlying call to Hashtbl.create.

module Using_hashable = Core.Weak_hashtbl.Using_hashable
val mem : ('a, _) t -> 'a -> bool
val find : ('a, 'b) t -> 'a -> 'b Core__.Import.Heap_block.t option
val find_or_add : ('a, 'b) t -> 'a -> default:(unit -> 'b Core__.Import.Heap_block.t) -> 'b Core__.Import.Heap_block.t
val remove : ('a, 'b) t -> 'a -> unit
val add_exn : ('a, 'b) t -> key:'a -> data:'b Core__.Import.Heap_block.t -> unit
val replace : ('a, 'b) t -> key:'a -> data:'b Core__.Import.Heap_block.t -> unit
val key_is_using_space : ('a, _) t -> 'a -> bool

key_is_using_space t key returns true if key is using some space in t. mem t key implies key_is_using_space t key, but it is also possible that that key_is_using_space t key && not (mem t key).

val reclaim_space_for_keys_with_unused_data : (_, _) t -> unit

reclaim_space_for_keys_with_unused_data t reclaims space for all keys in t whose data has been detected (by a finalizer) to be unused. Only keys such that key_is_using_space t key && not (mem t key) will be reclaimed.

val remove_keys_with_unused_data : [ `Do_not_use ] -> unit
val set_run_when_unused_data : [ `Do_not_use ] -> unit
OCaml

Innovation. Community. Security.