1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374(*
* Copyright (C) Citrix Systems Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; version 2.1 only. with the special
* exception on linking described in file LICENSE.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*)typet=inttype'arecord={data:'a;mutablegarbage:bool}letint_string_tbl:(int,stringrecord)Hashtbl.t=Hashtbl.create1024letstring_int_tbl:(string,int)Hashtbl.t=Hashtbl.create1024letcreated_counter=ref0letused_counter=ref0letcount=ref0letrecfresh()=ifHashtbl.memint_string_tbl!countthenbeginincrcount;fresh()endelse!countletnew_recordv={data=v;garbage=false}letof_stringname=ifHashtbl.memstring_int_tblnamethenbeginincrused_counter;Hashtbl.findstring_int_tblnameendelsebeginleti=fresh()inincrcreated_counter;Hashtbl.addstring_int_tblnamei;Hashtbl.addint_string_tbli(new_recordname);iendletto_stringi=(Hashtbl.findint_string_tbli).dataletmark_all_as_unused()=Hashtbl.iter(fun_v->v.garbage<-true)int_string_tblletmark_as_usedsymb=letrecord1=Hashtbl.findint_string_tblsymbinrecord1.garbage<-falseletgarbage()=letrecords=Hashtbl.fold(funsymbrecordaccu->ifrecord.garbagethen(symb,record.data)::accuelseaccu)int_string_tbl[]inletremove(int,string)=Hashtbl.removeint_string_tblint;Hashtbl.removestring_int_tblstringincreated_counter:=0;used_counter:=0;List.iterremoverecordsletstats()=Hashtbl.lengthstring_int_tblletcreated()=!created_counterletused()=!used_counter