mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-01-21 16:56:39 -05:00
some changes in CCDeque (doc and tests)
This commit is contained in:
parent
e248b555da
commit
7d117da5bd
2 changed files with 20 additions and 4 deletions
|
|
@ -121,6 +121,14 @@ let append_front ~into q = iter (push_front into) q
|
|||
|
||||
let append_back ~into q = iter (push_back into) q
|
||||
|
||||
(*$R
|
||||
let q = of_list [3;4] in
|
||||
append_front ~into:q (of_list [2;1]);
|
||||
assert_equal [1;2;3;4] (to_list q);
|
||||
append_back ~into:q (of_list [5;6]);
|
||||
assert_equal [1;2;3;4;5;6] (to_list q);
|
||||
*)
|
||||
|
||||
let fold f acc d =
|
||||
match !d with
|
||||
| None -> acc
|
||||
|
|
@ -171,6 +179,14 @@ let of_list l =
|
|||
List.iter (push_back q) l;
|
||||
q
|
||||
|
||||
(*$R
|
||||
let q = of_list [1;2;3] in
|
||||
assert_equal 1 (take_front q);
|
||||
assert_equal 3 (take_back q);
|
||||
assert_equal 2 (take_front q);
|
||||
assert_equal true (is_empty q)
|
||||
*)
|
||||
|
||||
let to_rev_list q = fold (fun l x -> x::l) [] q
|
||||
|
||||
let to_list q = List.rev (to_rev_list q)
|
||||
|
|
|
|||
|
|
@ -57,16 +57,16 @@ val push_back : 'a t -> 'a -> unit
|
|||
(** Push value at the back *)
|
||||
|
||||
val peek_front : 'a t -> 'a
|
||||
(** First value, or Empty *)
|
||||
(** First value, or @raise Empty if empty *)
|
||||
|
||||
val peek_back : 'a t -> 'a
|
||||
(** Last value, or Empty *)
|
||||
(** Last value, or @raise Empty if empty *)
|
||||
|
||||
val take_back : 'a t -> 'a
|
||||
(** Take last value, or raise Empty *)
|
||||
(** Take last value, or @raise Empty if empty *)
|
||||
|
||||
val take_front : 'a t -> 'a
|
||||
(** Take first value, or raise Empty *)
|
||||
(** Take first value, or @raise Empty if empty *)
|
||||
|
||||
val append_front : into:'a t -> 'a t -> unit
|
||||
(** [append_front ~into q] adds all elements of [q] at the front
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue