MoreLabels.Hashtbl.Make(3)
π MoreLabels.Hashtbl.Make(3) π
okay so bestie, welcome to the OCaml library corner of the manual where we're about to talk about everyone's favorite β¨vibesβ¨: hash tables. this is MoreLabels.Hashtbl.Make, and honestly? she's giving custom-hashing main character energy. let's get into it π«Ά
πΈ NAME πΈ
MoreLabels.Hashtbl.Make β a functor that builds you an implementation of the hashtable structure. periodt.
π Module π
the module is literally MoreLabels.Hashtbl.Make. iconic, no notes.
π Documentation π
β¨ Module Make β¨
Module Make
: (H : HashedType) -> sig end
so what is she, exactly? Make is a functor that builds an implementation of the hashtable structure π₯. the functor Hashtbl.Make hands you back a structure containing a type key (that's your keys, bestie) and a type 'a t (those are your hash tables, which associate data of type 'a to keys of type key).
the operations work similarly to the ones in the generic interface β but π they use the hashing and equality functions you specified in the functor argument H instead of the generic equality and hashing. custom behavior, your rules, iykyk π
.
π¨ important caveat, do NOT skip: since the hash function is not seeded, the create operation of the result structure always returns non-randomized hash tables. like, literally always. no randomness, no surprise, just predictability π.
π¦ Parameters π¦
"H"β which isMoreLabels.Hashtbl.HashedType, the whole vibe check of how your keys get hashed and compared π
π The Types π
type keyβ your key type, exactly as it sounds πtype !'a tβ the hash table type itself, mapping'adata to yourkeys β¨
β The Values β
val create : int -> 'a tβ makes you a fresh table πΈval clear : 'a t -> unitβ empties her out πval reset : 'a t -> unitβ resets her. Since 4.00 πval copy : 'a t -> 'a tβ a whole duplicate, twin energy π―val add : 'a t -> key:key -> data:'a -> unitβ adds a key β data pair in there πval remove : 'a t -> key -> unitβ yeets the key out πval find_and_remove : 'a t -> key -> 'a optionβ finds it and removes it in one go, multitasking queen π. Since 5.5val find : 'a t -> key -> 'aβ finds the value for the key πval find_opt : 'a t -> key -> 'a optionβ same but wrapped in an option, so much safer vibes π«Ά. Since 4.05val find_all : 'a t -> key -> 'a listβ gives you all the values for that key, a whole list of them πval replace : 'a t -> key:key -> data:'a -> unitβ swaps in new data for the key, out with the old β¨val find_and_replace : 'a t -> key:key -> data:'a -> 'a optionβ replaces and hands you back the old value (as an option) like a little souvenir π. Since 5.5val mem : 'a t -> key -> boolβ is the key in there or not,true/false, simple as πval iter : f:(key:key -> data:'a -> unit) -> 'a t -> unitβ walks every key/data pair and runsfon each π₯val filter_map_inplace : f:(key:key -> data:'a -> 'a option) -> 'a t -> unitβ transforms each value in place viaf; aNonefromfmeans that binding doesn't survive the vibe check π. Since 4.03val fold : f:(key:key -> data:'a -> 'acc -> 'acc) -> 'a t -> init:'acc -> 'accβ folds the whole table down into one accumulated'acc, starting frominitπ§val length : 'a t -> intβ how many bindings she's holding, a number πval stats : 'a t -> MoreLabels.Hashtbl.statisticsβ the receipts: statistics about the table π. Since 4.00val to_seq : 'a t -> (key * 'a) Seq.tβ turns her into a sequence of(key * 'a)pairs π¦. Since 4.07val to_seq_keys : 'a t -> key Seq.tβ sequence of just the keys π. Since 4.07val to_seq_values : 'a t -> 'a Seq.tβ sequence of just the values π. Since 4.07val add_seq : 'a t -> (key * 'a) Seq.t -> unitβ pours a whole sequence of pairs into the table πΈ. Since 4.07val replace_seq : 'a t -> (key * 'a) Seq.t -> unitβ same, but with replace semantics for each pair π . Since 4.07val of_seq : (key * 'a) Seq.t -> 'a tβ builds you a brand new table straight out of a sequence of pairs, chef's kiss π. Since 4.07
that's the whole page bestie, every single function accounted for, no cap π«Άπ
π and that's the tea, fr fr β this wasOCamldocdocumentation, dated2026-06-22. go forth and hash responsibly β¨ππ¦
π¦ 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