Weak.Make(3)

πŸŽ€ NAME πŸŽ€

Weak.Make(3) β€” from the OCaml library, bestie! This is the functor that builds an implementation of the weak hash set structure. Literally iconic. πŸ’–

🧩 Module 🧩

Module Weak.Make β€” yep, that's the module, and it's giving main character energy. ✨

πŸ’… Documentation πŸ’…

🌸 Module Make 🌸

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

Okay so this functor builds an implementation of the weak hash set structure. Real talk: H.equal can't be the physical equality, since only shallow copies of the elements in the set are given to it. No cap. πŸ™ˆ

🫢 Parameters 🫢

  • "H" β€” Stdlib.Hashtbl.HashedType. That's the parameter, bestie.
  • type data β€” the type of the elements stored in the table. πŸ“
  • type t β€” the type of tables that contain elements of type data. Note that weak hash sets cannot be marshaled using output_value or the functions of the Marshal module. That's a hard no. 😭
  • val create : int -> t β€” create n creates a new empty weak hash set, of initial size n. The table will grow as needed. ✨
  • val clear : t -> unit β€” remove all elements from the table. Clean slate vibes. 🧼
  • val merge : t -> data -> data β€” merge t x returns an instance of x found in t if any, or else adds x to t and returns x. 🫢
  • val add : t -> data -> unit β€” add t x adds x to t. If there is already an instance of x in t, it is unspecified which one will be returned by subsequent calls to find and merge. So don't @ me about which twin you get. πŸ’€
  • val remove : t -> data -> unit β€” remove t x removes from t one instance of x. Does nothing if there is no instance of x in t. 🫑
  • val find : t -> data -> data β€” find t x returns an instance of x found in t. Raises Not_found if there is no such element. 🚨
  • val find_opt : t -> data -> data option β€” find_opt t x returns an instance of x found in t or None if there is no such element. Since 4.05. πŸ—“οΈ
  • val find_all : t -> data -> data list β€” find_all t x returns a list of all the instances of x found in t. All of them. Obsessed. πŸ’…
  • val mem : t -> data -> bool β€” mem t x returns true if there is at least one instance of x in t, false otherwise. βœ…
  • val iter : (data -> unit) -> t -> unit β€” iter f t calls f on each element of t, in some unspecified order. It is not specified what happens if f tries to change t itself. ⚠️
  • val fold : (data -> 'acc -> 'acc) -> t -> 'acc -> 'acc β€” fold f t init computes (f d1 (... (f dN init))) where d1 ... dN are the elements of t in some unspecified order. It is not specified what happens if f tries to change t itself. ⚠️
  • val count : t -> int β€” count the number of elements in the table. count t gives the same result as fold (fun _ n -> n+1) t 0 but does not delay the deallocation of the dead elements. πŸ”₯
  • val stats : t -> int * int * int * int * int * int β€” return statistics on the table. The numbers are, in order: table length, number of entries, sum of bucket lengths, smallest bucket length, median bucket length, biggest bucket length. πŸ“Š

Okay that's the whole manual, bestie! Footer check: source is OCamldoc, date is 2026-06-22, and this page is for Weak.Make(3). Slay and goodbye. πŸ’–βœ¨πŸ‘‘

πŸ“¦ where this page comes from