module Weak_hashtbl: Weak_hashtbl
type ('a, 'b)
t
val create : ?growth_allowed:bool ->
?size:int -> 'a Core_kernel.Std.Hashtbl.Hashable.t -> ('a, 'b) t
val mem : ('a, 'b) t -> 'a -> bool
val find : ('a, 'b) t -> 'a -> 'b Core_kernel.Std.Heap_block.t option
val find_or_add : ('a, 'b) t ->
'a ->
default:(unit -> 'b Core_kernel.Std.Heap_block.t) ->
'b Core_kernel.Std.Heap_block.t
val remove : ('a, 'b) t -> 'a -> unit
val add_exn : ('a, 'b) t ->
key:'a -> data:'b Core_kernel.Std.Heap_block.t -> unit
val replace : ('a, 'b) t ->
key:'a -> data:'b Core_kernel.Std.Heap_block.t -> unit
val key_is_using_space : ('a, 'b) 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 : ('a, 'b) 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 key
s such that
key_is_using_space t key && not (mem t key)
will be reclaimed.
val set_run_when_unused_data : ('a, 'b) t -> thread_safe_f:(unit -> unit) -> unit
set_run_when_unused_data t ~thread_safe_f
calls thread_safe_f
in the finalizer
attached to each data
in t
, after ensuring the entry being finalized will be
handled in the next call to reclaim_space_for_keys_with_unused_data
. This can be
used to arrange to call reclaim_space_for_keys_with_unused_data
at a convenient time
in the future. thread_safe_f
must be thread safe -- it is *not* safe for it to call
any Weak_hashtbl
functions.
val sexp_of_t : ('a -> Sexplib.Sexp.t) ->
('b -> Sexplib.Sexp.t) -> ('a, 'b) t -> Sexplib.Sexp.t
growth_allowed
and size
are both optionally passed on to the underlying call to
Hashtbl.create
.
default is true
default is 128
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)
.
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 key
s such that
key_is_using_space t key && not (mem t key)
will be reclaimed.
set_run_when_unused_data t ~thread_safe_f
calls thread_safe_f
in the finalizer
attached to each data
in t
, after ensuring the entry being finalized will be
handled in the next call to reclaim_space_for_keys_with_unused_data
. This can be
used to arrange to call reclaim_space_for_keys_with_unused_data
at a convenient time
in the future. thread_safe_f
must be thread safe -- it is *not* safe for it to call
any Weak_hashtbl
functions.