Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file tmap.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129(*********************************************************************************)(* Stog *)(* *)(* Copyright (C) 2012-2024 INRIA All rights reserved. *)(* Author: Maxence Guesdon, INRIA Saclay *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU General Public License as *)(* published by the Free Software Foundation, version 3 of the 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 General Public License for more details. *)(* *)(* You should have received a copy of the GNU General Public *)(* License along with this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* As a special exception, you have permission to link this program *)(* with the OCaml compiler and distribute executables, as long as you *)(* follow the requirements of the GNU GPL in regard to all of the *)(* software in the executable aside from the OCaml compiler. *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(*********************************************************************************)(*c==m=[TMap]=0.1=t==*)(** *)moduletypeS=sigtype'akeytype('key,'a)tvalcreate:'a->('key,'a)tvalcompare_key:'akey->'akey->intvalget:('key,'a)t->'keykey->'avaladd:('key,'a)t->'a->'keykey*('key,'a)tvalfold:('keykey->'a->'b->'b)->('key,'a)t->'b->'bvalfind:('key,'a)t->('a->bool)->'keykeyvalint:'keykey->intvaliter:('keykey->'a->unit)->('key,'a)t->unitvalremove:('key,'a)t->'keykey->('key,'a)tvalmodify:('key,'a)t->'keykey->'a->('key,'a)tvalcard:('key,'a)t->intendmoduletypeMap_par=sigtype(+'a)ttypekey=intvalempty:'atvalis_empty:'at->boolvaladd:int->'a->'at->'atvalfind:int->'at->'avalremove:int->'at->'atvalmem:int->'at->boolvaliter:(int->'a->unit)->'at->unitvalmap:('a->'b)->'at->'btvalmapi:(int->'a->'b)->'at->'btvalfold:(int->'a->'b->'b)->'at->'b->'bvalcompare:('a->'a->int)->'at->'at->intvalequal:('a->'a->bool)->'at->'at->boolendmoduleFunctional=functor(Map:Map_parwithtypekey=int)->structexceptionFoundofint;;type'akey=Map.keytype('key,'a)t={counter:intref;(** Having a reference instead of a function will allow us
to dump structures using marshalling. Using a ref instead
of an int will make unique ids. This will result in an id
being usable only in a graph or its "descendents". In case
we use a new id on an "old" graph of a graph being not
a descendent of the graph the id was created for, there will
be a Not_found error instead of a confusion in the elements
manipulated. This will be easier to debug. *)map:'aMap.t;}letcompare_key(x:int)y=Stdlib.comparexy;;letcreate_={counter=ref0;map=Map.empty;};;letgettk=Map.findkt.map;;letaddtv=incrt.counter;letid=!(t.counter)inassert(id<>0);(* fail if we used too many ids *)lett={twithmap=Map.addidvt.map}in(id,t)letfoldft=Map.foldft.map;;letfindtpred=tryMap.iter(funkeye->ifpredethenraise(Foundkey))t.map;raiseNot_foundwithFoundkey->keyletintk=k;;letiterft=Map.iterft.map;;letremovetk={twithmap=Map.removekt.map};;letmodifytkv=lett=removetkin{twithmap=Map.addkvt.map}letcardt=Map.fold(fun__n->n+1)t.map0;;end;;moduleMap=Functional(Map.Make(structtypet=intletcompare(x:int)y=Stdlib.comparexyend));;includeMap(*/c==m=[TMap]=0.1=t==*)