DrUg55.5.0+dev0-2025-04-28/'Hashtbl!tA;!a@!b@@B@A@OO@BB@@@8../../stdlib/hashtbl.mli~  ~  @@@@'Hashtbl@@A@&create&random&optionL$bool@@@@@@@#int@@@'Hashtbl!t!a@B@!b@B@@@@@@@@@:A @ @;B  @@9A@@%clear@'Hashtbl!t!a@B@!b@B@@@@$unit@@@@@@aibi@@`B@@%reset@'Hashtbl!t!a@B@!b@B@@@@'@@@@@@m}}m}@@C@@$copy@'Hashtbl!t!a@B@ˠ!b@B@@@@'Hashtbl!t@@@@@@rr+@@D@@#add@'Hashtbl!t!a@B@ؠ!b@B@@@@@@ |@@@@@@@@@@uZZuZ@@E@@$find@'Hashtbl!t!a@B@!b@B@@@@@ @@@@@6@@F@@(find_opt@'Hashtbl!t!a@B@!b@B@@@@@ @@@@@@@@'(@@&G@@(find_all@'Hashtbl!t!a@B@!b@ B@@@@@$list@@@@@@@@QiiRi@@PH@@#mem@'Hashtbl!t!a@B@ !b@B@ @@@@_@@@@@@@@ykkzk@@xI@@&remove@'Hashtbl!t!a@B@!b@!B@@@@@A@@@@@@@@@@J@@'replace@'Hashtbl!t!a@,B@"!b@.B@#@@@&@@ k@@@'@@(@@)@@*@@@K@@$iter@@!a@;B@/@!b@=B@0@@@1@@2@@3@'Hashtbl!t@@@6@@@7@@8@@9@*@@L@@2filter_map_inplace@@!a@KB@>@!b@MB@? @@@A@@B@@C@'Hashtbl!t@@@F@@@G@@H@@I@-{{.@@,M@@$fold @@!a@[B@N@!b@_B@O@#acc@]B@P@@Q@@R@@S@'Hashtbl!t @@@V@@@W@@X@@Y@^!,!,_!7!q@@]N@@&length!@'Hashtbl!t!a@hB@`!b@jB@a@@@da@@@e@@f@$$$$@@O@@)randomize"@4@@@k9@@@l@@m@%%%%@@P@@-is_randomized#@I@@@n@@@o@@p@)E)E)E)e@@Q@@'rebuild$&random@@@q@@@{@'Hashtbl!t!a@~B@r!b@B@s@@@v'Hashtbl!t@@@y@@z@@|@))*)*E@@R@@*statistics%B;@@,num_bindings&@@@@@,,,- @@T@+num_buckets'@@ @@@ -o-q -o-@@U@1max_bucket_length(@@ @@@ -- --@@V@0bucket_histogram)@@%array  @@@@@@' --( -.@@&W@@@A@@@@@+,,,..@@@@*S@A@%stats*@'Hashtbl !t!a@C@!b@C@@@@'Hashtbl*statistics@@@@@@T..U..@@SX@@&to_seqj@'Hashtbl!t!a@ C@!b@ C@@@@&Stdlib#Seq!t@@@@ @@@ @@ @////@@Y@@+to_seq_keysk@'Hashtbl!t!a@ C@ ڠ@@ @@@ &Stdlib#Seq!t@@@ @@ @&1t1t&1t1@@Z@@-to_seq_valuesl@'Hashtbl!t@@ !b@ C@ @@@ &Stdlib#Seq!t@@@ @@ @*11*11@@[@@'add_seqm@'Hashtbl!t!a@ C@ !b@ C@ @@@ @&Stdlib#Seq!t@@@@ @@@ @@@ @@ @@ @.2626.262h@@\@@+replace_seqn@'Hashtbl!t!a@ C@ !b@ C@ @@@ @&Stdlib#Seq!t@@@@ @@@ @@@ @@ @@ @H222I222@@G]@@&of_seqo@&Stdlib#Seq!t@!a@ C@ @!b@ C@ @@ @@@ 'Hashtbl!t@@@ @@ @z63838{6383b@@y^@@*HashedTypesD!tpC;@@A@@@@@^88^88@@@@_@A@%equalq@'Hashtbl*HashedType!t@@@ @'Hashtbl*HashedType!t@@@ @@@ @@ @@ @a88a88@@`@@$hashr@'Hashtbl *HashedType!t@@@ !@@@ @@ @d99d99/@@a@@@@\8j8jq;;@b@@!SG#keytE;@@A@@@@@v<"<&v<"<.@@@@c@A@!tuF;!a@ "@AA@O@B@@@w@@ ?@x|<<y|<<@@wh@@#addz@'Hashtbl*!S!t!a@ KG@ B@@@ D@'Hashtbl+!S#key@@@ E@G,@@@ F@@ G@@ H@@ I@}<<}<<@@i@@&remove{@'Hashtbl-!S!t!a@ TG@ L@@@ N@'Hashtbl.!S#key@@@ Ot/@@@ P@@ Q@@ R@~<<~<=@@j@@$find|@'Hashtbl0!S!t!a@ \G@ U@@@ W@'Hashtbl1!S#key@@@ X@@ Y@@ Z@====2@@k@@(find_opt}@'Hashtbl2!S!t!a@ fG@ ]@@@ _@'Hashtbl3!S#key@@@ `@@@ b@@ c@@ d@)=3=7*=3=^@@(l@@(find_all~@'Hashtbl4!S!t!a@ pG@ g@@@ i@'Hashtbl5!S#key@@@ j6@@@ l@@ m@@ n@W=w={X=w=@@Vm@@'replace@'Hashtbl7!S!t!a@ zG@ q@@@ s@'Hashtbl8!S#key@@@ t@&9@@@ u@@ v@@ w@@ x@====@@n@@#mem@'Hashtbl:!S!t!a@ G@ {@@@ }@'Hashtbl;!S#key@@@ ~<@@@ @@ @@ @====@@o@@$iter@@'Hashtbl=!S#key@@@ @!a@ G@ w>@@@ @@ @@ @'Hashtbl?!S!t@@@ @@@@ @@ @@ @===>!@@p@@2filter_map_inplace@@'HashtblA!S#key@@@ @!a@ G@  @@@ @@ @@ @'HashtblB!S!t@@@ C@@@ @@ @@ @>">& >b>l@@q@@$fold@@'HashtblD!S#key@@@ @!a@ G@ @#acc@ G@ @@ @@ @@ @'HashtblE!S!t@@@ @@@ @@ @@ @U>>V>>@@Tr@@&length@'HashtblF!S!t!a@ G@ @@@ SG@@@ @@ @v>>w>>@@us@@%stats@'HashtblH!S!t!a@ G@ @@@ 'HashtblI*statistics@@@ @@ @>>>? @@t@@&to_seq@'HashtblJ!S!t!a@ G@ @@@ &StdlibL#Seq!t@'HashtblK!S#key@@@ @!@@ @@@ @@ @?!?%?!?J@@u@@+to_seq_keys@'HashtblM!S!t@@ @@@ &StdlibO#Seq!t'HashtblN!S#key@@@ @@@ @@ @?c?g?c?@@v@@-to_seq_values@'HashtblP!S!t!a@ G@ @@@ &StdlibQ#Seq!t@@@ @@ @%??&??@@$w@@'add_seq@'HashtblR!S!t!a@ G@ @@@ @&StdlibT#Seq!t@'HashtblS!S#key@@@ ֠@#@@ @@@ U@@@ @@ @@ @c??d?@@@bx@@+replace_seq@'HashtblV!S!t!a@ G@ @@@ @&StdlibX#Seq!t@'HashtblW!S#key@@@ ⠠@#@@ @@@ AY@@@ @@ @@ @@.@2@.@d@@y@@&of_seq@&Stdlib[#Seq!t@'HashtblZ!S#key@@@ 렠@!a@ G@ @@ @@@ 'Hashtbl\!S!t@@@ @@ @@}@@}@@@z@@@@t< < @@@{@@ӱ$MakeH@!HIlJ;@@@A!t@@@ @@@@@A@A-@@@@}@A@J;@A@A@@@@@@A@@A@@@  @@@ @@ @@@@ @@@ F@@@ @@ @@@@@@@ @@@ @@ @@@@(@@@ ,@@@ @@ @@@@6@@@ @^@@@ @3@@@ @@ @@ @@ @@@@L@@@ @@@@ F@@@ @@ @@ @@@@_@@@ @)@@@ @@ @@ @z@w@v@nn@@@ @8@@@ aw@@@ @@ @@ @`@]@\@T@@@ @K@@@ NK_@@@ @@ @@ @G@D@C@;@@@ @`@@@ @C@@@ @@ @@ @@ @-@*@)@!@@@ @u@@@  E@@@ @@ @@ @@@@@@@@ @@@@ @@ @@ @̠@@@ @@@ @@ @@ @@@@@@@@ @@@@ @@ @@ @@@@ @@@ @@ @@ @@@@@@@@ @@@@ @@ @@ @@@@ @@@ @@ @@ @@@@ @@@ @@@ @@ @@@@@@@ C@@@ @@ @@@@(@@@ &Stdlib#Seq!t@@@@ @@@ @@@ @@ @}@z@y@Fq@@@ #Seq!t@@@ @@@ @@ @e@b@a@[Y@@@ 3#Seq!ta@@@ @@ @P@M@L@mD@@@ ~@G#Seq!t@B@@@ }@W@@ |@@@ {u@@@ z@@ y@@ x@3@0@/@'@@@ w@h#Seq!t@c@@@ v@:@@ u@@@ t@@@ s@@ r@@ q@@@@#Seq!t@~@@@ p@@@ o@@@ n @@@ m@@ l@@@@@ @@@ ~@@@0SeededHashedTypeL!tK;@@ A@@@@@ CC CC@@@@ @A@%equal@'Hashtbl^0SeededHashedType!t@@@ @'Hashtbl_0SeededHashedType!t@@@  `@@@ @@ @@ @ CC CC@@ @@@+seeded_hash@ a@@@ @'Hashtblb0SeededHashedType!t@@@  c@@@ @@ @@ @ (D1D5 )D1DU@@ 'A@@@@ ,C~C~ -EE@ +B@@'SeededSO#keyM;@@ AA@@@@@ <FF  =FF@@@@ ;C@A@!tN;!a@ @A OA@O@B@@@ LFF MFF#@@@@ KD@A@&create&random J Gd@@@ @@@ @ Fe@@@ 'Hashtblf'SeededS!t!a@ O@ @@@ @@ @@ @ zF$F( {FjF@@ yE@@%clear@'Hashtblg'SeededS!t!a@ O@ @@@  ;h@@@ @@ @ FF FF@@ F@@%reset@'Hashtbli'SeededS!t!a@ O@ @@@  \j@@@ @@ @ FF FF@@ G@@$copy@'Hashtblk'SeededS!t!a@ O@ @@@ 'Hashtbll'SeededS!t@@@ @@ @ FF FF@@ H@@#add@'Hashtblm'SeededS!t!a@ O@ @@@ @'Hashtbln'SeededS#key@@@ @ o@@@ @@ @@ @@ @ FF FG@@ I@@&remove@'Hashtblp'SeededS!t!a@ O@ @@@ @'Hashtblq'SeededS#key@@@  r@@@ @@ @@ @ ?GG  @GG)@@ >J@@$find@'Hashtbls'SeededS!t!a@ "O@ @@@ @'Hashtblt'SeededS#key@@@ @@ @@ @ gG*G. hG*GJ@@ fK@@(find_opt@'Hashtblu'SeededS!t!a@ ,O@ #@@@ %@'Hashtblv'SeededS#key@@@ & @@@ (@@ )@@ *@ GKGO GKGv@@ L@@(find_all@'Hashtblw'SeededS!t!a@ 6O@ -@@@ /@'Hashtblx'SeededS#key@@@ 0 ry@@@ 2@@ 3@@ 4@ GG GG@@ M@@'replace@'Hashtblz'SeededS!t!a@ @O@ 7@@@ 9@'Hashtbl{'SeededS#key@@@ :@ |@@@ ;@@ <@@ =@@ >@ GG GG@@ N@@#mem@'Hashtbl}'SeededS!t!a@ IO@ A@@@ C@'Hashtbl~'SeededS#key@@@ D @@@ E@@ F@@ G@ GG GH@@ O@@$iter@@'Hashtbl'SeededS#key@@@ J@!a@ UO@ K @@@ L@@ M@@ N@'Hashtbl'SeededS!t@@@ P @@@ Q@@ R@@ S@ THH UHH5@@ SP@@2filter_map_inplace@@'Hashtbl'SeededS#key@@@ V@!a@ bO@ W d @@@ Y@@ Z@@ [@'Hashtbl'SeededS!t@@@ ] *@@@ ^@@ _@@ `@ H6H: HvH@@ Q@@$fold@@'Hashtbl'SeededS#key@@@ c@!a@ oO@ d@#acc@ qO@ e@@ f@@ g@@ h@'Hashtbl'SeededS!t@@@ j@@@ k@@ l@@ m@ HH HH@@ R@@&length@'Hashtbl'SeededS!t!a@ xO@ r@@@ t @@@ u@@ v@ HH HH@@ S@@%stats@'Hashtbl'SeededS!t!a@ O@ y@@@ {'Hashtbl*statistics@@@ |@@ }@HIHI @@T@@&to_seq@'Hashtbl'SeededS!t!a@ O@ @@@ &Stdlib#Seq!t@'Hashtbl'SeededS#key@@@ @!@@ @@@ @@ @<I"I&=I"IK@@;U@@+to_seq_keys@'Hashtbl'SeededS!t@@ @@@ &Stdlib#Seq!t'Hashtbl'SeededS#key@@@ @@@ @@ @iIdIhjIdI@@hV@@-to_seq_values@'Hashtbl'SeededS!t!a@ O@ @@@ &Stdlib#Seq!t@@@ @@ @IIII@@W@@'add_seq@'Hashtbl'SeededS!t!a@ O@ @@@ @&Stdlib#Seq!t@'Hashtbl'SeededS#key@@@ @#@@ @@@ n@@@ @@ @@ @IIIJ@@X@@+replace_seq@'Hashtbl'SeededS!t!a@ O@ @@@ @&Stdlib#Seq!t@'Hashtbl'SeededS#key@@@ @#@@ @@@ @@@ @@ @@ @ J/J3 J/Je@@ Y@@&of_seq@&Stdlib#Seq!t@'Hashtbl'SeededS#key@@@ @!a@ O@ @@ @@@ 'Hashtbl'SeededS!t@@@ @@ @CJ~JDJ~J@@BZ@@@@GEEHJJ@F[@@ӱ*MakeSeededP@!HQ!R;@@@A!t@@@ @@@@dKKHeKKV@@@@c]@A@(R;'@A@A@$#@@"@@@A@e@@@ @@@ @u@@@ @@@ @@ @@ @ @ @ @ @@@ t@@@ @@ @@@@@@@ @@@ @@ @@@@'@@@ +@@@ @@ @@@@5@@@ @f@@@ @@@@ @@ @@ @@ @@@@K@@@ @@@@ @@@ @@ @@ @@@@^@@@ @)@@@ @@ @@ @@@~@mv@@@ @8@@@ i@@@ @@ @@ @h@e@d@\@@@ @K@@@ sf@@@ @@ @@ @N@K@J@B@@@ ~@_@@@ }@J@@@ |@@ {@@ z@@ y@4@1@0@(@@@ x@t@@@ wr@@@ v@@ u@@ t@@@@@@@@ s@(@@@ r@@ q@@ p@ɠ@@@ o2@@@ n@@ m@@ l@@@@@@@@ k@@@@ j@@ i@@ h@@@@ gM@@@ f@@ e@@ d@@@@@@@@ c@@@@ b@@ a@@ `@@@@ _@@@ ^@@ ]@@ \@@@@ @@@ [@@@ Z@@ Y@@@@@@@ X @@@ W@@ V@@@@%@@@ Uq#Seq!t@@@@ T@@@ S@@@ R@@ Q@@}@|@@t@@@ P#Seq!t@@@ O@@@ N@@ M@h@e@d@U\@@@ L#Seq!td@@@ K@@ J@S@P@O@gG@@@ I@#Seq!t@=@@@ H@Z@@ G@@@ F@@@ E@@ D@@ C@6@3@2@*@@@ B@#Seq!t@^@@@ A@=@@ @@@@ ?@@@ >@@ =@@ <@@@@#Seq!t@y@@@ ;@ @@ :@@@ 9@@@ 8@@ 7@@@@@@KK@>^@@@$hash@!a@ S@ 2@@@ @@ @UNKNKVNKN_@@T_@@+seeded_hash@B@@@ @!a@ S@ O@@@ @@ @@ @r ORORs OROt@@q`@@*hash_param@_@@@ @f@@@ @!a@ S@ s@@@ @@ @@ @@ @OOOO@@a@@1seeded_hash_param@@@@ @@@@ @@@@ @!a@ S@ @@@ @@ @@ @@ @@ @"T,T,"T,Tb@@b@@@3?Hash tables and hash functions.@ Hash tables are hashed association tables, with in-place modification. Because most operations on a hash table modify their input, they're more commonly used in imperative code. The lookup of the value associated with a key (see ,Hashtbl.findD@", 0Hashtbl.find_optD@ G) is normally very fast, often faster than the equivalent lookup in #Map@@!.@1 The functors ,Hashtbl.Make@@% and 2Hashtbl.MakeSeeded@@ can be used when performance or flexibility are key. The user provides custom equality and hash functions for the key type, and obtains a custom hash table type for this particular type of key.@$ 'Warning@ a hash table is only as good as the hash function. A bad hash function will turn the table into a degenerate association list, with linear time lookup instead of constant time lookup.@4 The polymorphic )Hashtbl.tE@ b hash table is useful in simpler cases or in interactive environments. It uses the polymorphic ,Hashtbl.hashD@ y function defined in the OCaml runtime (at the time of writing, it's SipHash), as well as the polymorphic equality #(=)!.@( See 0Hashtbl.examples(Examples@5 the examples section@!.@@@@@@@@@@@5unsynchronized_access ?Unsynchronized accesses to hash tables are a programming error.@A8../../stdlib/hashtbl.mli7Unsynchronized accesses@@ Unsynchronized accesses to a hash table may lead to an invalid hash table state. Thus, concurrent accesses to a hash tables must be synchronized (for instance with a 'Mutex.t@@").@A@1Generic interface@@#H3 "The type of hash tables from type "'a) to type "'b!.@@@@@@@@@@@@qOnO@@A@@ge@@.Hashtbl.create30Hashtbl.create n ^ creates a new, empty hash table, with initial size greater or equal to the suggested size !n8. For best results, !n x should be on the order of the expected number of elements that will be in the table. The table grows as needed, so !n " is just an initial guess. If !n V is very small or negative then it is disregarded and a small default size is used.@1 The optional '~random } parameter (a boolean) controls whether the internal organization of the hash table is randomized at each execution of .Hashtbl.create & or deterministic over all executions.@ & A hash table that is created with '~random( set to %false uses a fixed hash function (D@ ) to distribute keys among buckets. As a consequence, collisions between keys happen deterministically. In Web-facing applications or other security-sensitive applications, the deterministic collision patterns can be exploited by a malicious user to create a denial-of-service attack: the attacker sends input crafted to create many collisions in the table, slowing the application down.@ & A hash table that is created with '~random( set to $true " uses the seeded hash function 3Hashtbl.seeded_hashD@ with a seed that is randomly chosen at hash table creation time. In effect, the hash function used is randomly selected among &2^{30} different hash functions. All these hash functions have different collision patterns, rendering ineffective the denial-of-service attack described above. However, because of randomization, enumerating all elements of the hash table using ,Hashtbl.foldD@' or ,Hashtbl.iterD@ m is no longer deterministic: elements are enumerated in different orders at different runs of the program.@* If no '~random parameter is given, hash tables are created in non-random mode by default. This default can be changed either programmatically by calling 1Hashtbl.randomizeD@6 or by setting the !R- flag in the -OCAMLRUNPARAM6 environment variable.@@@@@$4.00$the '~random V parameter was not present and all hash tables were created in non-randomized mode.@@@@@@@@@@ @@@@֠-Hashtbl.clear38Empty a hash table. Use %reset, instead of %clear @ to shrink the size of the bucket table to its initial size.@@@@@@@@@@@@@@@@@ʠ-Hashtbl.reset3 SEmpty a hash table and shrink the size of the bucket table to its initial size.@@@@$4.00@@@@@@@@-@@@@,Hashtbl.copy3 %Return a copy of the given hashtable.@@@@@@@@@@@@@<@@@@+Hashtbl.add38Hashtbl.add tbl key data3 adds a binding of #key$ to $data- in table #tbl!.@$ 'Warning@8: Previous bindings for #key B are not removed, but simply hidden. That is, after performing .Hashtbl.removeD@( tbl key>, the previous binding for #key D, if any, is restored. (Same behavior as with association lists.)@ E If you desire the classic behavior of replacing elements, see /Hashtbl.replaceD@!.@@@@@@@@@@@@@@@@@@@ƠԐ32Hashtbl.find tbl x returns the current binding of !x$ in #tbl/, or raises )Not_found; if no such binding exists.@@@@@@@@@@@@@@@@@@ɠ36Hashtbl.find_opt tbl x returns the current binding of !x$ in #tbl), or $None; if no such binding exists.@@@@$4.05@@@@@@@@@@@@@ɠ0Hashtbl.find_all36Hashtbl.find_all tbl x 1 returns the list of all data associated with !x$ in #tbl y. The current binding is returned first, then the previous bindings, in reverse order of introduction in the table.@@@@@@@@@@@@@@@@@@+Hashtbl.mem31Hashtbl.mem tbl x+ checks if !x- is bound in #tbl!.@@@@@@@@@@@@@ @#@@@@34Hashtbl.remove tbl x removes the current binding of !x$ in #tbl H, restoring the previous binding if it exists. It does nothing if !x1 is not bound in #tbl!.@@@@@@@@@@@@@L@O@@@@ϐ3 to all bindings in table #tbl 8 and update each binding depending on the result of !f&. If !f) returns $None /, the binding is discarded. If it returns ,Some new_val 4, the binding is update to associate the key to 'new_val!.@8 Other comments for kD@/ apply as well.@@@@$4.03@@@@@@@E@@F@C2@@@@%37Hashtbl.fold f tbl init- computes ?(f kN dN ... (f k1 d1 init)...)+, where )k1 ... kN ! are the keys of all bindings in #tbl), and )d1 ... dN I are the associated values. Each binding is presented exactly once to !f!.@ 2 The order in which the bindings are passed to !f l is unspecified. However, if the table contains several bindings for the same key, they are passed to !f W in reverse order of introduction, that is, the most recent binding is passed first.@  If the hash table was created in non-randomized mode, the order in which the bindings are enumerated is reproducible between successive runs of the program, and even between minor versions of OCaml. For randomized hash tables, the order of enumeration is entirely random.@ F The behavior is not specified if the hash table is modified by !f6 during the iteration.@@@@@@@@@@@@d@e@N@Y@@@@G.Hashtbl.length32Hashtbl.length tbl # returns the number of bindings in #tbl M. It takes constant time. Multiple bindings are counted once each, so .Hashtbl.length; gives the number of times ,Hashtbl.iter= calls its first argument.@@@@@@@@@@@@]@^@@@@E30After a call to 3Hashtbl.randomize() =, hash tables are created in randomized mode by default: oD@ 0 returns randomized hash tables, unless the -~random:false Q optional parameter is given. The same effect can be achieved by setting the !R6 parameter in the -OCAMLRUNPARAM6 environment variable.@ It is recommended that applications or Web frameworks that need to protect themselves against the denial-of-service attack described in D@& call 3Hashtbl.randomize() ; at initialization time before any domains are created.@4 Note that once 3Hashtbl.randomize() U was called, there is no way to revert to the non-randomized default behavior of D@ V. This is intentional. Non-randomized hash tables can still be created using j@AU@@@@A3Hashtbl.replace_seq3 +Add the given bindings to the table, using ʐD@@@@@$4.07@@@@@@@G@UH@X3@@@@.Hashtbl.of_seq3 wBuild a table from the given bindings. The bindings are added in the same order they appear in the sequence, using  D@ h, which means that if two pairs have the same key, only the latest one will appear in the table.@@@@$4.07@@@@@@@(@o)@@@@A@4Functorial interface@@ The functorial interface allows the use of specific comparison and hash functions, either for performance/security concerns, or because keys are not hashable/comparable with the polymorphic builtins.@ N For instance, one might want to specialize a table for integer keys:  module IntHash = struct type t = int let equal i j = i=j let hash i = i land max_int end module IntHashtbl = Hashtbl.Make(IntHash) let h = IntHashtbl.create 17 in IntHashtbl.add h 12 "hello" @? This creates a new module *IntHashtbl2, with a new type 3'a IntHashtbl.t0 of tables from #int$ to "'a3. In this example, !h. contains &string7 values so its type is 3string IntHashtbl.t!.@< Note that the new type /'a IntHashtbl.t % is not compatible with the type 1('a,'b) Hashtbl.t , of the generic interface. For example, 0Hashtbl.length h ( would not type-check, you must use 1IntHashtbl.length!.@2Hashtbl.HashedType3 #The input signature of the functor @@!.@@@@@@@@@@@@hA#4Hashtbl.HashedType.t3?The type of the hashtable keys.@@@@@@@@@@@@@@A@@po@@8Hashtbl.HashedType.equal3 ,The equality predicate used to compare keys.@@@@@@@@@@@@r@s@j@@@@]7Hashtbl.HashedType.hash3 ^A hashing function on keys. It must be such that if two keys are equal according to %equal @, then they have identical hash values as computed by $hash . Examples: suitable (%equal", $hash 1) pairs for arbitrary key types include) (#(=)", -D@ [) for comparing objects by structure (provided objects do not contain floats)@) (<(fun x y -> compare x y = 0)", =D@ N) for comparing objects by structure and handling *Stdlib.nan@@* correctly@) ($(==)", SD@ `) for comparing objects by physical equality (e.g. for mutable or cyclic objects).@@@@@@@@@@@@@@@]@@@@@@@)Hashtbl.S3 $The output signature of the functor @@!.@@@@@@@@@@@@AO#-Hashtbl.S.key@@@A@@@@#+Hashtbl.S.t@O@@A@@@@0Hashtbl.S.create@@@@@@/Hashtbl.S.clear@@@@@@t/Hashtbl.S.reset3@@@@$4.00@@@@@@@s@t@@@@`.Hashtbl.S.copy@[@\@@@@B-Hashtbl.S.add@=@>@.@:@@@@"0Hashtbl.S.remove@@@@@@@.Hashtbl.S.find@@@@@@@堕2Hashtbl.S.find_opt3@@@@$4.05@@@@@@@@@@@@@Ƞ2Hashtbl.S.find_all@@@@@@@1Hashtbl.S.replace@@@@@@@@-Hashtbl.S.mem@@@ r@@@@e.Hashtbl.S.iter@`@a@I@@@@;Hashtbl.SeededHashedType.equal3 ,The equality predicate used to compare keys.@@@@@@@@@@@@9@:@1@@@@$ $Hashtbl.SeededHashedType.seeded_hash3 kA seeded hashing function on keys. The first argument is the seed. It must be the case that if )equal x y9 is true, then 'seeded_hash seed x = seeded_hash seed y< for any value of $seed9. A suitable choice for +seeded_hash; is the function D@' below.@@@@@@@@@@@@C@ID@L@@@@@3@@10@/Hashtbl.SeededS3 $The output signature of the functor z@@!.@@@@$4.00@@@@@@@;A@#3Hashtbl.SeededS.key@@@A@@=<@@#1Hashtbl.SeededS.t@:O@@A@@65@@6Hashtbl.SeededS.create@2@21@)@@@@5Hashtbl.SeededS.clear@@@@@@5Hashtbl.SeededS.reset@@@@@@堕4Hashtbl.SeededS.copy@@@@@@Ǡ3Hashtbl.SeededS.add@@@@@@@@6Hashtbl.SeededS.remove@@@@@@@4Hashtbl.SeededS.find@@@r@@@@j8Hashtbl.SeededS.find_opt3@@@@$4.05@@@@@@@i@j@Z@@@@M8Hashtbl.SeededS.find_all@H@I@9@@@@+7Hashtbl.SeededS.replace@&@'@@#@@@@ 3Hashtbl.SeededS.mem@@@ @@@@ ꠕ4Hashtbl.SeededS.iter@ @ @ @@@@ "Hashtbl.SeededS.filter_map_inplace3@@@@$4.03@@@@@@@ @ @ @@@@ 4Hashtbl.SeededS.fold@ @ @! {@$ @@@@ s6Hashtbl.SeededS.length@ n@- o@@@@ [5Hashtbl.SeededS.stats@ V@6 W@@@@ @6Hashtbl.SeededS.to_seq3@@@@$4.07@@@@@@@ ?@C @@@@@ ;Hashtbl.SeededS.to_seq_keys3@@@@$4.07@@@@@@@ @P @@@@ =Hashtbl.SeededS.to_seq_values3@@@@$4.07@@@@@@@ @] @@@@ ܠ7Hashtbl.SeededS.add_seq3@@@@$4.07@@@@@@@ @j @m @@@@ ;Hashtbl.SeededS.replace_seq3@@@@$4.07@@@@@@@ @z @} @@@@ 6Hashtbl.SeededS.of_seq3@@@@$4.07@@@@@@@ @ @@@@ V@@ T S@/  O3 OFunctor building an implementation of the hashtable structure. The functor 2Hashtbl.MakeSeeded + returns a structure containing a type #key4 of keys and a type $'a t - of hash tables associating data of type "'a1 to keys of type #key . The operations perform similarly to those of the generic interface, but use the seeded hashing and equality functions specified in the functor argument !H 3 instead of generic equality and hashing. The &create 4 operation of the result structure supports the '~random > optional parameter and returns randomized hash tables if ,~random:true 7 is passed or if randomization is globally on (see D@").@@@@$4.00@@@@@@@A  'Hashtbl0SeededHashedType0SeededHashedType@4 with type key = H.t@  @@@@@A@>The polymorphic hash functions@@ 3.Hashtbl.hash x [ associates a nonnegative integer to any value of any type. It is guaranteed that if %x = y$ or 6Stdlib.compare x y = 0', then /hash x = hash y/. Moreover, $hash . always terminates, even on cyclic structures.@@@@@@@@@@@@ @  @@@@ Ҡ e3-A variant of  $D@ 5 that is further parameterized by an integer seed.@@@@$4.00@@@@@@@ @ . @ 1 @@@@ Π2Hashtbl.hash_param3 %Hashtbl.hash_param meaningful total x; computes a hash value for !x %, with the same properties as for $hash &. The two extra integer parameters *meaningful% and %total z give more precise control over hashing. Hashing performs a breadth-first, left-to-right traversal of the structure !x1, stopping after *meaningful * meaningful nodes were encountered, or %total 4 nodes (meaningful or not) were encountered. If %total as specified by the user exceeds a certain value, currently 256, then it is capped to that value. Meaningful nodes are: integers; floating-point numbers; strings; characters; booleans; and constant constructors. Larger values of *meaningful% and %total means that more nodes are taken into account to compute the final hash value, and therefore collisions are less likely to happen. However, hashing takes longer. The parameters *meaningful% and %total L govern the tradeoff between accuracy and speed. As default choices,  D@% and  ؐD@) take /meaningful = 10% and +total = 100!.@@@@@@@@@@@@ 2@  3@  /@  +@@@@ "9Hashtbl.seeded_hash_param3-A variant of D@ A that is further parameterized by an integer seed. Usage: 1Hashtbl.seeded_hash_param meaningful total seed x!.@@@@$4.00@@@@@@@ 1@  2@  .@  *@  &@@@@ A(examples @@# B@-Basic Example@@# R (* 0...99 *) let seq = Seq.ints 0 |> Seq.take 100 (* build from Seq.t *) # let tbl = seq |> Seq.map (fun x -> x, string_of_int x) |> Hashtbl.of_seq val tbl : (int, string) Hashtbl.t = # Hashtbl.length tbl - : int = 100 # Hashtbl.find_opt tbl 32 - : string option = Some "32" # Hashtbl.find_opt tbl 166 - : string option = None # Hashtbl.replace tbl 166 "one six six" - : unit = () # Hashtbl.find_opt tbl 166 - : string option = Some "one six six" # Hashtbl.length tbl - : int = 101 @# B@1Counting Elements@@ ) Given a sequence of elements (here, a %Seq.t@@ ), we want to count how many times each distinct element occurs in the sequence. A simple way to do this, assuming the elements are comparable and hashable, is to use a hash table that maps elements to their number of occurrences.@ T Here we illustrate that principle using a sequence of (ascii) characters (type $char5). We use a custom (Char_tbl1 specialized for $char!.@#  # module Char_tbl = Hashtbl.Make(struct type t = char let equal = Char.equal let hash = Hashtbl.hash end) (* count distinct occurrences of chars in [seq] *) # let count_chars (seq : char Seq.t) : _ list = let counts = Char_tbl.create 16 in Seq.iter (fun c -> let count_c = Char_tbl.find_opt counts c |> Option.value ~default:0 in Char_tbl.replace counts c (count_c + 1)) seq; (* turn into a list *) Char_tbl.fold (fun c n l -> (c,n) :: l) counts [] |> List.sort (fun (c1,_)(c2,_) -> Char.compare c1 c2) val count_chars : Char_tbl.key Seq.t -> (Char.t * int) list = (* basic seq from a string *) # let seq = String.to_seq "hello world, and all the camels in it!" val seq : char Seq.t = # count_chars seq - : (Char.t * int) list = [(' ', 7); ('!', 1); (',', 1); ('a', 3); ('c', 1); ('d', 2); ('e', 3); ('h', 2); ('i', 2); ('l', 6); ('m', 1); ('n', 2); ('o', 2); ('r', 1); ('s', 1); ('t', 2); ('w', 1)] (* "abcabcabc..." *) # let seq2 = Seq.cycle (String.to_seq "abc") |> Seq.take 31 val seq2 : char Seq.t = # String.of_seq seq2 - : String.t = "abcabcabcabcabcabcabcabcabcabca" # count_chars seq2 - : (Char.t * int) list = [('a', 11); ('b', 10); ('c', 10)] @@@ @@A @@@@@