mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 19:25:28 -05:00
doc/CCHeap: move filter down
This commit is contained in:
parent
8349a4d244
commit
cc2dd6d829
2 changed files with 16 additions and 16 deletions
|
|
@ -49,11 +49,6 @@ module type S = sig
|
||||||
val add : t -> elt -> t
|
val add : t -> elt -> t
|
||||||
(** [add h x] is [insert x h]. *)
|
(** [add h x] is [insert x h]. *)
|
||||||
|
|
||||||
val filter : (elt -> bool) -> t -> t
|
|
||||||
(** [filter p h] filters values, only retaining the ones that satisfy the predicate [p].
|
|
||||||
Complexity: [O(n log n)].
|
|
||||||
*)
|
|
||||||
|
|
||||||
val find_min : t -> elt option
|
val find_min : t -> elt option
|
||||||
(** [find_min h] find the minimal element of the heap [h].
|
(** [find_min h] find the minimal element of the heap [h].
|
||||||
Complexity: [O(1)].
|
Complexity: [O(1)].
|
||||||
|
|
@ -91,6 +86,11 @@ module type S = sig
|
||||||
Complexity: [O(n log n)].
|
Complexity: [O(n log n)].
|
||||||
@since 2.0 *)
|
@since 2.0 *)
|
||||||
|
|
||||||
|
val filter : (elt -> bool) -> t -> t
|
||||||
|
(** [filter p h] filters values, only retaining the ones that satisfy the predicate [p].
|
||||||
|
Complexity: [O(n log n)].
|
||||||
|
*)
|
||||||
|
|
||||||
val iter : (elt -> unit) -> t -> unit
|
val iter : (elt -> unit) -> t -> unit
|
||||||
(** [iter f h] iterates over the heap [h] invoking [f] with the current element. *)
|
(** [iter f h] iterates over the heap [h] invoking [f] with the current element. *)
|
||||||
|
|
||||||
|
|
@ -251,12 +251,6 @@ module Make (E : PARTIAL_ORD) : S with type elt = E.t = struct
|
||||||
let insert x h = merge (N (1, x, E, E)) h
|
let insert x h = merge (N (1, x, E, E)) h
|
||||||
let add h x = insert x h
|
let add h x = insert x h
|
||||||
|
|
||||||
let rec filter p h =
|
|
||||||
match h with
|
|
||||||
| E -> E
|
|
||||||
| N (_, x, l, r) when p x -> _make_node x (filter p l) (filter p r)
|
|
||||||
| N (_, _, l, r) -> merge (filter p l) (filter p r)
|
|
||||||
|
|
||||||
let find_min_exn = function
|
let find_min_exn = function
|
||||||
| E -> raise Empty
|
| E -> raise Empty
|
||||||
| N (_, x, _, _) -> x
|
| N (_, x, _, _) -> x
|
||||||
|
|
@ -306,6 +300,12 @@ module Make (E : PARTIAL_ORD) : S with type elt = E.t = struct
|
||||||
else
|
else
|
||||||
h
|
h
|
||||||
|
|
||||||
|
let rec filter p h =
|
||||||
|
match h with
|
||||||
|
| E -> E
|
||||||
|
| N (_, x, l, r) when p x -> _make_node x (filter p l) (filter p r)
|
||||||
|
| N (_, _, l, r) -> merge (filter p l) (filter p r)
|
||||||
|
|
||||||
let rec iter f h =
|
let rec iter f h =
|
||||||
match h with
|
match h with
|
||||||
| E -> ()
|
| E -> ()
|
||||||
|
|
|
||||||
|
|
@ -54,11 +54,6 @@ module type S = sig
|
||||||
val add : t -> elt -> t
|
val add : t -> elt -> t
|
||||||
(** [add h x] is [insert x h]. *)
|
(** [add h x] is [insert x h]. *)
|
||||||
|
|
||||||
val filter : (elt -> bool) -> t -> t
|
|
||||||
(** [filter p h] filters values, only retaining the ones that satisfy the predicate [p].
|
|
||||||
Complexity: [O(n log n)].
|
|
||||||
*)
|
|
||||||
|
|
||||||
val find_min : t -> elt option
|
val find_min : t -> elt option
|
||||||
(** [find_min h] find the minimal element of the heap [h].
|
(** [find_min h] find the minimal element of the heap [h].
|
||||||
Complexity: [O(1)].
|
Complexity: [O(1)].
|
||||||
|
|
@ -95,6 +90,11 @@ module type S = sig
|
||||||
Complexity: [O(n log n)].
|
Complexity: [O(n log n)].
|
||||||
@since 2.0 *)
|
@since 2.0 *)
|
||||||
|
|
||||||
|
val filter : (elt -> bool) -> t -> t
|
||||||
|
(** [filter p h] filters values, only retaining the ones that satisfy the predicate [p].
|
||||||
|
Complexity: [O(n log n)].
|
||||||
|
*)
|
||||||
|
|
||||||
val iter : (elt -> unit) -> t -> unit
|
val iter : (elt -> unit) -> t -> unit
|
||||||
(** [iter f h] iterates over the heap [h] invoking [f] with the current element. *)
|
(** [iter f h] iterates over the heap [h] invoking [f] with the current element. *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue