Commit d85f5836 authored by POTTIER Francois's avatar POTTIER Francois

Added [filter] in the [Map] interface.

parent 53843f7e
......@@ -116,6 +116,11 @@ module type S = sig
val fold_rev: (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
(* [filter f m] returns a copy of the map [m] where only the bindings
that satisfy [f] have been retained. *)
val filter: (key -> 'a -> bool) -> 'a t -> 'a t
(* It is valid to evaluate [iter2 f m1 m2] if and only if [m1] and
[m2] have equal domains. Doing so invokes [f k x1 x2], in turn,
for each key [k] bound to [x1] in [m1] and to [x2] in
......
......@@ -505,6 +505,17 @@ module Make (X : Endianness.S) = struct
else
Branch (p, m, tree0', tree1')
(* [filter f m] returns a copy of the map [m] where only the bindings
that satisfy [f] have been retained. *)
let filter f m =
fold (fun key data accu ->
if f key data then
add key data accu
else
accu
) m empty
(* [iterator m] returns a stateful iterator over the map [m]. *)
(* TEMPORARY performance could be improved, see JCF's paper *)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment