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 typedata. Big warning bestie: weak hash sets cannot be marshaled usingoutput_valueor the functions of theMarshalmodule. Not me finding that out the hard way π.
val create : int -> tβcreate ncreates a new empty weak hash set, of initial sizen. 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 xreturns an instance ofxfound intif any, or else addsxtotand returnx. (The manual says βreturnβ; we're keeping the lore exact.)val add : t -> data -> unitβadd t xaddsxtot. If there is already an instance ofxint, it is unspecified which one will be returned by subsequent calls tofindandmerge. So don't come for the ordering, it's giving unspecified π.val remove : t -> data -> unitβremove t xremoves fromtone instance ofx. Does nothing if there is no instance ofxint. Lowkey polite.val find : t -> data -> dataβfind t xreturns an instance ofxfound int. RaisesNot_foundif there is no such element. The audacity of a missing element, honestly π.val find_opt : t -> data -> data optionβfind_opt t xreturns an instance ofxfound intorNoneif 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 xreturns a list of all the instances ofxfound int. Collector energy.val mem : t -> data -> boolβmem t xreturnstrueif there is at least one instance ofxint,falseotherwise. Bool check, very demure.val iter : (data -> unit) -> t -> unitβiter f tcallsfon each element oft, in some unspecified order. It is not specified what happens ifftries to changetitself. 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 initcomputes(f d1 (... (f dN init)))whered1 ... dNare the elements oftin some unspecified order. It is not specified what happens ifftries to changetitself. Same warning, same unspecified vibe check.val count : t -> intβ counts the number of elements in the table.count tgives the same result asfold (fun _ n -> n+1) t 0but 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
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms