Hashtbl.Make(3)
πΈ Hashtbl.Make(3) β the OCaml library glow-up π¦
okay so this little icon is from the OCaml library manual, page Hashtbl.Make(3) β and bestie, it's literally the functor that builds you a whole hashtable implementation. no cap, it's giving "build-a-bear but for data structures" π
β¨ NAME β¨
Hashtbl.Make β a functor that builds an implementation of the hashtable structure. that's it, that's the vibe π
π§ Module π§
Module Hashtbl.Make
π Documentation π
Module Make
: (H : HashedType) -> sig end
okay so here's the tea π₯ β Hashtbl.Make is a functor building an implementation of the hashtable structure.
The way that it works: the functor Hashtbl.Make returns a structure containing:
- a type
keyof keys π - a type
'a tof hash tables associating data of type'ato keys of typekey
The operations perform similarly to those of the generic interface, but β and this is the main character detail β they use the hashing and equality functions specified in the functor argument H instead of generic equality and hashing. iykyk π
ngl, one important thing: since the hash function is not seeded, the create operation of the result structure always returns non-randomized hash tables. no randomization, no surprises, just consistency β¨
Parameters:
"H"β which is aHashtbl.HashedTypeπ
π Types π
type keyβ the key type, slaying as always πtype !'a tβ the hash table type itself, with that!variance marker doing its thing (yes, we stan a constructor that's not covariant) π
β The functions β
val create : int -> 'a tβ makes you a fresh table, you give it anintand it gives you the'a tπval clear : 'a t -> unitβ empties the table out. bye bestie πval reset : 'a t -> unitβ resets it. Since 4.00 π¦val copy : 'a t -> 'a tβ a whole duplicate, no sharing of your original's drama πval add : 'a t -> key -> 'a -> unitβ put a key + value in there πval remove : 'a t -> key -> unitβ take a key out πΈval find_and_remove : 'a t -> key -> 'a optionβ finds it and removes it in one go, handing you back an'a option. Since 5.5 π₯val find : 'a t -> key -> 'aβ find the value for a key, straight up πval find_opt : 'a t -> key -> 'a optionβ same energy but safe, gives you an'a option. Since 4.05 β¨val find_all : 'a t -> key -> 'a listβ all the values for that key, in a list πval replace : 'a t -> key -> 'a -> unitβ swap out the value π§val find_and_replace : 'a t -> key -> 'a -> 'a optionβ swap it and give you the old value back as an'a option. Since 5.5 πval mem : 'a t -> key -> boolβ is this key even in here??boolsays yes/no πval iter : (key -> 'a -> unit) -> 'a t -> unitβ run your function over everything, nobody left out π«Άval filter_map_inplace : (key -> 'a -> 'a option) -> 'a t -> unitβ filters and maps in place,optiondeciding who stays. Since 4.03 πval fold : (key -> 'a -> 'acc -> 'acc) -> 'a t -> 'acc -> 'accβ fold it all down into one accumulated'accβval length : 'a t -> intβ how many things are in there, as anintπval stats : 'a t -> Hashtbl.statisticsβ the numbers on your table, all packaged asHashtbl.statistics. Since 4.00 πval to_seq : 'a t -> (key * 'a) Seq.tβ turn it into a sequence of(key * 'a)pairs. Since 4.07 π¦val to_seq_keys : 'a t -> key Seq.tβ just the keys, as akey Seq.t. Since 4.07 πval to_seq_values : 'a t -> 'a Seq.tβ just the values, as an'a Seq.t. Since 4.07 πval add_seq : 'a t -> (key * 'a) Seq.t -> unitβ pour a(key * 'a) Seq.tstraight into your table. Since 4.07 πval replace_seq : 'a t -> (key * 'a) Seq.t -> unitβ same but replacing as it goes. Since 4.07 πΈval of_seq : (key * 'a) Seq.t -> 'a tβ build a whole fresh table out of a sequence. Since 4.07 π
fr fr that's every single val, every signature, every Since note β nothing skipped, nothing merged, we keep the facts and only change the vibe π
okay bestie that's the whole page π«Ά this was rendered by OCamldoc, dated 2026-06-22, and it's the Hashtbl.Make(3) page from the OCaml library β periodt. go build your hashtable, you're gonna eat πβ¨π
π¦ 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