Weak.S(3)

πŸ’… NAME πŸ’…

Okay bestie, quick vibe check: this is Weak.S, the output signature of the functor Weak.Make, and we're in the OCaml library / Weak.S(3) corner of the universe. That's the manual-name drop, folded in cute and not copy-pasted.

πŸ¦‹ Module type πŸ¦‹

Module type Weak.S

Module type S = sig end

Literally an empty signature sig end β€” iconic minimalism, no cap.

πŸ’– Documentation πŸ’–

The output signature of the functor Weak.Make.

  • type data β€” the type of the elements stored in the table. This is the thing your weak hash set is full of. πŸ“
  • type t β€” the type of tables that contain elements of type data. Big warning bestie: weak hash sets cannot be marshaled using output_value or the functions of the Marshal module. Not me finding that out the hard way 😭.

  • val create : int -> t β€” create n creates a new empty weak hash set, of initial size n. The table will grow as needed. Slay, it scales. ✨
  • val clear : t -> unit β€” remove all elements from the table. Poof, empty, periodt.
  • 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 return x. (The manual says β€œreturn”; we're keeping the lore exact.)
  • 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 come for the ordering, it's giving unspecified πŸ’€.
  • 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. Lowkey polite.
  • 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. The audacity of a missing element, honestly πŸ™ˆ.
  • 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. This one said β€œno thanks to exceptions” and we respect it. 🫢
  • val find_all : t -> data -> data list β€” find_all t x returns a list of all the instances of x found in t. Collector energy.
  • val mem : t -> data -> bool β€” mem t x returns true if there is at least one instance of x in t, false otherwise. Bool check, very demure.
  • 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. So don't mutate the table mid-iter, bestie; that's chaos main character energy and the manual is not promising you anything.
  • 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. Same warning, same unspecified vibe check.
  • val count : t -> int β€” counts 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. It's not just folding with extra steps; it has a deallocation glow-up. 🧚
  • val stats : t -> int * int * int * int * int * int β€” returns 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. Six ints, one tuple, fully blessed data. πŸ”₯

Catch you later, bestie β€” this page came from OCamldoc, dated 2026-06-22, for Weak.S(3) in the OCaml library. Stay weak-hash-set-pilled πŸ’…βœ¨

πŸ“¦ where this page comes from