1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283(* This file is free software, part of Zipperposition. See file "license" for more details. *)(** {1 Hashconsing} *)moduletypeHashedType=sigtypetvalequal:t->t->boolvalhash:t->intvaltag:int->t->unitendmoduletypeS=sigtypeelt(** Hashconsed objects *)valhashcons:elt->elt(** Hashcons the elements *)valmem:elt->bool(** Is the element present in this table? *)valfresh_unique_id:unit->int(** Unique ID that will never occur again in this table (modulo 2^63...) *)valstats:unit->int*int*int*int*int*intendmoduleMake(X:HashedType)=structmoduleH=Weak.Make(X)typeelt=X.tletcount_=ref0lettbl:H.t=H.create4_096lethashconsx=letx'=H.mergetblxinifx==x'then(X.tag!count_x;incrcount_;);x'let[@inline]memx=H.memtblxletfresh_unique_id()=letx=!count_inincrcount_;xletstats()=H.statstblend[@@inline]moduleMakeNonWeak(X:HashedType)=structmoduleH=Hashtbl.Make(X)typeelt=X.tletcount_=ref0lettbl:eltH.t=H.create1024lethashconsx=tryH.findtblxwithNot_found->X.tag!count_x;incrcount_;H.addtblxx;xletmemx=H.memtblxletfresh_unique_id()=letx=!count_inincrcount_;xletstats()=letstat=H.statstblinletopenHashtblinletsum_buck=Array.fold_left(+)0stat.bucket_histograminletmin_buck=Array.fold_leftminmax_intstat.bucket_histograminstat.num_buckets,stat.num_bindings,sum_buck,min_buck,0,stat.max_bucket_lengthend