mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
add a few function in CCWBTree
This commit is contained in:
parent
257c2ad71c
commit
dab3ea6052
2 changed files with 21 additions and 0 deletions
|
|
@ -27,6 +27,8 @@ module type S = sig
|
||||||
|
|
||||||
val is_empty : _ t -> bool
|
val is_empty : _ t -> bool
|
||||||
|
|
||||||
|
val singleton : key -> 'a -> 'a t
|
||||||
|
|
||||||
val mem : key -> _ t -> bool
|
val mem : key -> _ t -> bool
|
||||||
|
|
||||||
val get : key -> 'a t -> 'a option
|
val get : key -> 'a t -> 'a option
|
||||||
|
|
@ -45,6 +47,11 @@ module type S = sig
|
||||||
|
|
||||||
val remove : key -> 'a t -> 'a t
|
val remove : key -> 'a t -> 'a t
|
||||||
|
|
||||||
|
val update : key -> ('a option -> 'a option) -> 'a t -> 'a t
|
||||||
|
(** [update k f m] calls [f (Some v)] if [get k m = Some v], [f None]
|
||||||
|
otherwise. Then, if [f] returns [Some v'] it binds [k] to [v'],
|
||||||
|
if [f] returns [None] it removes [k] *)
|
||||||
|
|
||||||
val cardinal : _ t -> int
|
val cardinal : _ t -> int
|
||||||
|
|
||||||
val weight : _ t -> int
|
val weight : _ t -> int
|
||||||
|
|
@ -273,6 +280,13 @@ module MakeFull(K : KEY) : S with type key = K.t = struct
|
||||||
List.for_all (fun (k,_) -> let m' = M.remove k m in M.balanced m') l)
|
List.for_all (fun (k,_) -> let m' = M.remove k m in M.balanced m') l)
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
let update k f m =
|
||||||
|
let maybe_v = get k m in
|
||||||
|
match maybe_v, f maybe_v with
|
||||||
|
| None, None -> m
|
||||||
|
| Some _, None -> remove k m
|
||||||
|
| _, Some v -> add k v m
|
||||||
|
|
||||||
(* TODO union, intersection *)
|
(* TODO union, intersection *)
|
||||||
|
|
||||||
let rec nth_exn i m = match m with
|
let rec nth_exn i m = match m with
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ module type S = sig
|
||||||
|
|
||||||
val is_empty : _ t -> bool
|
val is_empty : _ t -> bool
|
||||||
|
|
||||||
|
val singleton : key -> 'a -> 'a t
|
||||||
|
|
||||||
val mem : key -> _ t -> bool
|
val mem : key -> _ t -> bool
|
||||||
|
|
||||||
val get : key -> 'a t -> 'a option
|
val get : key -> 'a t -> 'a option
|
||||||
|
|
@ -50,6 +52,11 @@ module type S = sig
|
||||||
|
|
||||||
val remove : key -> 'a t -> 'a t
|
val remove : key -> 'a t -> 'a t
|
||||||
|
|
||||||
|
val update : key -> ('a option -> 'a option) -> 'a t -> 'a t
|
||||||
|
(** [update k f m] calls [f (Some v)] if [get k m = Some v], [f None]
|
||||||
|
otherwise. Then, if [f] returns [Some v'] it binds [k] to [v'],
|
||||||
|
if [f] returns [None] it removes [k] *)
|
||||||
|
|
||||||
val cardinal : _ t -> int
|
val cardinal : _ t -> int
|
||||||
|
|
||||||
val weight : _ t -> int
|
val weight : _ t -> int
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue