Ephemeron.Kn.Make(3)

okay so bestie, this page is Ephemeron.Kn.Make(3) from the OCaml library manual β€” and it's giving weak hash table functor realness, no cap πŸ’…βœ¨

πŸ’– NAME πŸ’–

Ephemeron.Kn.Make β€” functor building an implementation of a weak hash table. periodt.

🧚 Module 🧚

Module Ephemeron.Kn.Make 🫢

✨ Documentation ✨

🌸 Module Make 🌸

here's the exact module shape:

Module Make
 : (H : Hashtbl.HashedType) -> sig end

Functor building an implementation of a weak hash table. iconic behavior, honestly.

Parameters:

  • H β€” Stdlib.Hashtbl.HashedType

The vibe here: it proposes the same interface as a usual hash table. But β€” and this is the big weak-table caveat β€” since the bindings are weak, even if mem h k is true, a subsequent find h k may raise Not_found because the garbage collector can run between the two. 🫠

🚨 bestie, do not forget that caveat. weak bindings + GC timing = find h k can absolutely raise Not_found after mem h k said true. that's the documented behavior, not a drill. πŸ’€

Here are the types and the full val lineup, exact signatures and all:

type key

type !'a t

val create : int -> 'a t
val clear : 'a t -> unit
val reset : 'a t -> unit
val copy : 'a t -> 'a t
val add : 'a t -> key -> 'a -> unit
val remove : 'a t -> key -> unit
val find : 'a t -> key -> 'a
val find_opt : 'a t -> key -> 'a option
val find_all : 'a t -> key -> 'a list
val replace : 'a t -> key -> 'a -> unit
val mem : 'a t -> key -> bool
val length : 'a t -> int
val stats : 'a t -> Hashtbl.statistics
val add_seq : 'a t -> (key * 'a) Seq.t -> unit
val replace_seq : 'a t -> (key * 'a) Seq.t -> unit
val of_seq : (key * 'a) Seq.t -> 'a t

and the last two, with their notes:

  • val clean : 'a t -> unit β€” remove all dead bindings. Done automatically during automatic resizing.
  • val stats_alive : 'a t -> Hashtbl.statistics β€” same as Hashtbl.SeededS.stats but only count the alive bindings.

that's the whole page, bestie 🫢 the footer energy is OCamldoc, dated 2026-06-22 β€” official manual sign-off, cute and done πŸ’–βœ¨

πŸ“¦ where this page comes from