wip: Mixset

This commit is contained in:
Simon Cruanes 2015-04-28 13:05:28 +02:00
parent 5208579b9d
commit b66caf67bf
2 changed files with 15 additions and 1 deletions

View file

@ -75,3 +75,5 @@ let get_exn ~key set = match get ~key set with
let set ~key v set = let set ~key v set =
IMap.add key.id (fun () -> key.opt <- Some v) set IMap.add key.id (fun () -> key.opt <- Some v) set
let cardinal set = IMap.cardinal set

View file

@ -52,14 +52,26 @@ type 'a key
val newkey : unit -> 'a key val newkey : unit -> 'a key
(** [newkey ()] creates a new unique key that can be used to access (** [newkey ()] creates a new unique key that can be used to access
a ['a] value in a set *) a ['a] value in a set. Each key created with [newkey] is distinct
from any other key, even if they have the same type.
Not thread-safe. *)
val empty : t val empty : t
(** Empty set *)
val set : key:'a key -> 'a -> t -> t val set : key:'a key -> 'a -> t -> t
(** [set ~key v set] maps [key] to [v] in [set]. It means that
for every [set], [get ~key (set ~key v set) = Some v]. *)
val get : key:'a key -> t -> 'a option val get : key:'a key -> t -> 'a option
(** [get ~key set] obtains the value for [key] in [set], if any. *)
val get_exn : key:'a key -> t -> 'a val get_exn : key:'a key -> t -> 'a
(** Same as {!get}, but can fail (** Same as {!get}, but can fail
@raise Not_found if the key is not present *) @raise Not_found if the key is not present *)
val cardinal : t -> int
(** Number of mappings *)