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 is MoreLabels.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 'a data to your keys ✨

⭐ 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.5
  • val 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.05
  • val 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.5
  • val 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 runs f on each πŸ”₯
  • val filter_map_inplace : f:(key:key -> data:'a -> 'a option) -> 'a t -> unit β€” transforms each value in place via f; a None from f means that binding doesn't survive the vibe check πŸ’€. Since 4.03
  • val fold : f:(key:key -> data:'a -> 'acc -> 'acc) -> 'a t -> init:'acc -> 'acc β€” folds the whole table down into one accumulated 'acc, starting from init 🧚
  • 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.00
  • val to_seq : 'a t -> (key * 'a) Seq.t β€” turns her into a sequence of (key * 'a) pairs πŸ¦‹. Since 4.07
  • val to_seq_keys : 'a t -> key Seq.t β€” sequence of just the keys πŸ”‘. Since 4.07
  • val to_seq_values : 'a t -> 'a Seq.t β€” sequence of just the values πŸ“. Since 4.07
  • val add_seq : 'a t -> (key * 'a) Seq.t -> unit β€” pours a whole sequence of pairs into the table 🌸. Since 4.07
  • val replace_seq : 'a t -> (key * 'a) Seq.t -> unit β€” same, but with replace semantics for each pair πŸ’…. Since 4.07
  • val 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 was OCamldoc documentation, dated 2026-06-22. go forth and hash responsibly βœ¨πŸŽ€πŸ¦‹
πŸ“¦ where this page comes from