2
* MultiPMap - Polymorphic maps with multiple associations
3
* Copyright (C) 1996-2003 Xavier Leroy, Nicolas Cannasse, Markus Mottl
4
* Copyright (C) 2008 David Teller, LIFO, Universite d'Orleans
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version,
10
* with the special exception on linking described in file LICENSE.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
Polymorphic Multi-Map.
25
This is a polymorphic multi-map, i.e. an association from 1 to many.
28
@author Nicolas Cannasse
35
val empty : ('a, 'b) t
36
(** The empty map, using [compare] as key comparison function. *)
38
val is_empty : ('a, 'b) t -> bool
39
(** returns true if the map is empty. *)
41
val create : ('a -> 'a -> int) -> ('b -> 'b -> int) -> ('a, 'b) t
42
(** creates a new empty map, using the provided function for key comparison.*)
44
val add : 'a -> 'b -> ('a, 'b) t -> ('a, 'b) t
45
(** [add x y m] returns a map containing the same bindings as
46
[m], plus a binding of [x] to [y].*)
48
val find : 'a -> ('a, 'b) t -> 'b BatPSet.t
49
(** [find x m] returns the current binding of [x] in [m]*)
51
val remove_all : 'a -> ('a, 'b) t -> ('a, 'b) t
52
(** [remove_all x m] returns a map containing the same bindings as
53
[m], except for [x] which is unbound in the returned map. *)
55
val remove : 'a -> 'b -> ('a, 'b) t -> ('a, 'b) t
56
(** [remove k d m] returns a map containing the same bindings as
57
[m], except for [k] which is not bound to [d] anymore in the returned
58
map. If [k] was not bound to [d], nothing is changed. If the operation
59
removes the last binding of [k], then [k] is also removed from the set
62
val mem : 'a -> ('a, 'b) t -> bool
63
(** [mem x m] returns [true] if [m] contains at least a binding for [x],
64
and [false] otherwise. *)
66
val iter : ('a -> 'b BatPSet.t-> unit) -> ('a, 'b) t -> unit
67
(** [iter f m] applies [f] to all bindings in map [m].
68
[f] receives the key as first argument, and the associated value
69
as second argument. The order in which the bindings are passed to
70
[f] is unspecified. Only current bindings are presented to [f]:
71
bindings hidden by more recent bindings are not passed to [f]. *)
73
val map : ('b BatPSet.t -> 'c BatPSet.t) -> (('b -> 'b -> int) -> ('c -> 'c -> int)) -> ('a, 'b) t -> ('a, 'c) t
74
(** [map f m] returns a map with same domain as [m], where the
75
associated value [a] of all bindings of [m] has been
76
replaced by the result of the application of [f] to [a].
77
The order in which the associated values are passed to [f]
80
val mapi : ('a -> 'b BatPSet.t -> 'c BatPSet.t) -> (('b -> 'b -> int) -> ('c -> 'c -> int)) -> ('a, 'b) t -> ('a, 'c) t
81
(** Same as [map], but the function receives as arguments both the
82
key and the associated value for each binding of the map. *)
84
val fold : ('b BatPSet.t -> 'c -> 'c) -> ('a , 'b) t -> 'c -> 'c
85
(** [fold f m a] computes [(f kN dN ... (f k1 d1 a)...)],
86
where [k1 ... kN] are the keys of all bindings in [m],
87
and [d1 ... dN] are the associated data.
88
The order in which the bindings are presented to [f] is
91
val foldi : ('a -> 'b BatPSet.t -> 'c -> 'c) -> ('a , 'b) t -> 'c -> 'c
92
(** Same as [fold], but the function receives as arguments both the
93
key and the associated value for each binding of the map. *)
95
val enum : ('a, 'b) t -> ('a * 'b) BatEnum.t
96
(** creates an enumeration for this map. *)
98
val of_enum : ?keys:('a -> 'a -> int) -> ?data:('b -> 'b -> int) -> ('a * 'b) BatEnum.t -> ('a, 'b) t
99
(** creates a map from an enumeration, using the specified function
100
for key comparison or [compare] by default. *)
102
(** {6 Boilerplate code}*)
106
val print : ?first:string -> ?last:string -> ?sep:string -> ('a BatInnerIO.output -> 'b -> unit) ->
107
('a BatInnerIO.output -> 'c -> unit) ->
108
'a BatInnerIO.output -> ('b, 'c) t -> unit