123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156(*
POMAP - Library for manipulating partially ordered maps
Copyright (C) 2001-2002 Markus Mottl (OEFAI)
email: markus.mottl@gmail.com
WWW: http://www.ocaml.info
This library 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; either
version 2.1 of the License, or (at your option) any later version.
This library 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.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*)(** Specification of indices used to index elements in stores *)moduletypeINDEX=sigtypet=int(** Type of indices *)typegen(** Type of index generators *)moduleSet:moduletypeofPtset(** Efficient sets of indices *)moduleMap:Map.Swithtypekey=t(** Efficient maps of indices *)valstart:gen(** The start state of the index generator *)valnext_ix:gen->t(** [next_ix gen] @return the next index that generator [gen] will produce. *)valnext:gen->t*gen(** [next gen] @return the tuple of [(new_ix, new_gen)], where
[new_ix] is the next index and [new_gen] the next state of the
index generator. *)valremove_ix:gen->t->gen(** [remove_ix gen ix] @return an updated index generator which is
guaranteed to never return index [ix] or any other previously
returned index. *)valint_of_ix:t->int(** [int_of_ix ix] converts index [ix] to an integer.
@raise Failure if index out of range for machine integers. *)end(** Interface to stores *)moduletypeSTORE=sigmoduleIx:INDEX(** Index module used to index elements in the store *)type(+'a)t(** Type of stores *)valempty:'at(** The empty store *)valis_empty:'at->bool(** [is_empty s] @return [true] if [s] is empty, [false] otherwise. *)valcardinal:'at->int(** [cardinal s] @return the number of elements in [s]. *)valnext_ix:'at->Ix.t(** [next_ix s] @return the next index the store [s] will use to index
a new element. *)valsingleton:'a->Ix.t*'at(** [singleton el] @return the tuple [(ix, store)], where [ix]
is the index under which the only element [el] was stored, and
[store] is the store containing [el]. *)valadd:'a->'at->Ix.t*'at(** [add el s] @return the tuple [(new_ix, new_store)], where [new_ix]
is the index under which the new element [el] was stored, and
[new_store] is the new store containing [el]. *)valfind:Ix.t->'at->'a(** [find ix s] @return the element stored under index [ix].
@raise Not_found if index [ix] not bound. *)valupdate:Ix.t->'a->'at->'at(** [update ix el s] rebinds index [ix] in store [s] to point to
[el], and returns the resulting store. The previous binding
disappears. New indices resulting from further adds are guaranteed
to have higher indices.
@raise Not_found if index [ix] not bound. *)valremove:Ix.t->'at->'at(** [remove ix s] removes the binding of index [ix] of store [s],
and returns the resulting store. *)valiter:('a->unit)->'at->unit(** [iter f s] applies [f] to all stored elements in store [s]. The
order in which elements are passed to [f] is unspecified. *)valiteri:(Ix.t->'a->unit)->'at->unit(** [iter f s] applies [f] to all indexes and their related elements
in store [s]. The order in which elements are passed to [f] is
unspecified. *)valmap:('a->'b)->'at->'bt(** [map f s] @return a store with all elements in [s] mapped from
their original value to the codomain of [f]. Only the elements
are passed to [f]. The order in which elements are passed to [f]
is unspecified. *)valmapi:(Ix.t->'a->'b)->'at->'bt(** [mapi f s] same as [map], but function [f] also receives the index
associated with the elements. *)valfold:('a->'b->'b)->'at->'b->'b(** [fold f s a] computes [(f eN ... (f e1 a) ...)], where [e1 ... eN]
are the elements of all bindings in store [s]. The order in which
the bindings are presented to [f] is unspecified. *)valfoldi:(Ix.t->'a->'b->'b)->'at->'b->'b(** [foldi f s a] same as [fold], but function [f] also receives
the index associated with the elements. *)valto_list:'at->(Ix.t*'a)list(** [to_list s] converts [s] to an association list of indices and
elements. *)valchoose:'at->Ix.t*'a(** [choose s] @return a tuple [(ix, x)], where [ix] is the index
of some unspecified value [x] in store [s].
@raise Not_found if [s] is empty. *)valfilter:(Ix.t->'a->bool)->'at->'at(** [filter p s] @return the store of all elements in [s] that
satisfy [p]. *)valpartition:(Ix.t->'a->bool)->'at->'at*'at(** [partition p s] @return a pair of stores [(s1, s2)], where
[s1] is the store of all the elements of [s] that satisfy the
predicate [p], and [s2] is the store of all the elements of [s]
that do not satisfy [p]. *)valeq_classes:('a->'a->bool)->'at->('a*'at)list(** [eq_classes eq s] @return a list of tuples [(el, ec)], where
[el] is the only kind of element as identified by the equivalence
relation [eq] stored in the equivalence class (store) [ec] under
each index. Every such equivalence class is unique and maximal
with respect to [s], and the original indices of the elements are
preserved in each class. *)valget_ix_map:'at->'aIx.Map.t(** [get_ix_map s] @return a map of all indices mapped to their
respective elements in store [s]. *)end