doc/CCHeap: move filter down

This commit is contained in:
Glen Mével 2024-07-27 01:47:09 +02:00
parent 8349a4d244
commit cc2dd6d829
2 changed files with 16 additions and 16 deletions

View file

@ -49,11 +49,6 @@ module type S = sig
val add : t -> elt -> t
(** [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
(** [find_min h] find the minimal element of the heap [h].
Complexity: [O(1)].
@ -91,6 +86,11 @@ module type S = sig
Complexity: [O(n log n)].
@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
(** [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 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
| E -> raise Empty
| N (_, x, _, _) -> x
@ -306,6 +300,12 @@ module Make (E : PARTIAL_ORD) : S with type elt = E.t = struct
else
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 =
match h with
| E -> ()

View file

@ -54,11 +54,6 @@ module type S = sig
val add : t -> elt -> t
(** [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
(** [find_min h] find the minimal element of the heap [h].
Complexity: [O(1)].
@ -95,6 +90,11 @@ module type S = sig
Complexity: [O(n log n)].
@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
(** [iter f h] iterates over the heap [h] invoking [f] with the current element. *)