Module CCDeque
Imperative deque
This structure provides fast access to its front and back elements, with O(1) operations.
val create : unit -> 'a t
New deque.
val clear : _ t -> unit
Remove all elements.
- since
- 0.13
val is_empty : 'a t -> bool
Is the deque empty?
val equal : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> bool
equal a b
checks whethera
andb
contain the same sequence of elements.- parameter eq
comparison function for elements.
- since
- 0.13
val compare : cmp:('a -> 'a -> int) -> 'a t -> 'a t -> int
compare a b
compares lexicographicallya
andb
.- parameter cmp
comparison function for elements.
- since
- 0.13
val length : 'a t -> int
Number of elements. Used to be linear time, now constant time.
val push_front : 'a t -> 'a -> unit
Push value at the front.
val push_back : 'a t -> 'a -> unit
Push value at the back.
val peek_front : 'a t -> 'a
First value.
- raises Empty
if empty.
val peek_back : 'a t -> 'a
Last value.
- raises Empty
if empty.
val take_back : 'a t -> 'a
Take last value.
- raises Empty
if empty.
val take_front : 'a t -> 'a
Take first value.
- raises Empty
if empty.
val append_front : into:'a t -> 'a t -> unit
append_front ~into q
adds all elements ofq
at the front ofinto
.O(length q)
in time.- since
- 0.13
val append_back : into:'a t -> 'a t -> unit
append_back ~into q
adds all elements ofq
at the back ofinto
.O(length q)
in time.- since
- 0.13
val iter : ('a -> unit) -> 'a t -> unit
Iterate on elements.
val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
Fold on elements.
- since
- 0.13
Conversions
val of_seq : 'a sequence -> 'a t
Create a deque from the sequence. Optional argument
deque
disappears, useadd_seq_back
instead.- since
- 0.13
val add_seq_front : 'a t -> 'a sequence -> unit
add_seq_front q seq
adds elements ofseq
into the front ofq
, in reverse order.O(n)
in time, wheren
is the number of elements to add.- since
- 0.13
val add_seq_back : 'a t -> 'a sequence -> unit
add_seq_back q seq
adds elements ofseq
into the back ofq
, in order.O(n)
in time, wheren
is the number of elements to add.- since
- 0.13
val of_list : 'a list -> 'a t
Conversion from list, in order.
- since
- 0.13
val to_list : 'a t -> 'a list
List of elements, in order. Less efficient than
to_rev_list
.- since
- 0.13
val to_rev_list : 'a t -> 'a list
Efficient conversion to list, in reverse order.
- since
- 0.13