Module CCDeque
Imperative deque
This structure provides fast access to its front and back elements, with O(1) operations.
val create : unit -> 'a tNew deque.
val clear : _ t -> unitRemove all elements.
- since
- 0.13
val is_empty : 'a t -> boolIs the deque empty?
val equal : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> boolequal a bchecks whetheraandbcontain the same sequence of elements.- parameter eq
comparison function for elements.
- since
- 0.13
val compare : cmp:('a -> 'a -> int) -> 'a t -> 'a t -> intcompare a bcompares lexicographicallyaandb.- parameter cmp
comparison function for elements.
- since
- 0.13
val length : 'a t -> intNumber of elements. Used to be linear time, now constant time.
val push_front : 'a t -> 'a -> unitPush value at the front.
val push_back : 'a t -> 'a -> unitPush value at the back.
val peek_front : 'a t -> 'aFirst value.
- raises Empty
if empty.
val peek_front_opt : 'a t -> 'a optionFirst value.
- since
- 2.7
val peek_back : 'a t -> 'aLast value.
- raises Empty
if empty.
val peek_back_opt : 'a t -> 'a optionLast value.
- since
- 2.7
val remove_back : 'a t -> unitRemove last value. If the deque is empty do nothing
- since
- 2.7
val remove_front : 'a t -> unitRemove first value. If the deque is empty do nothing
- since
- 2.7
val take_back : 'a t -> 'aTake last value.
- raises Empty
if empty.
val take_back_opt : 'a t -> 'a optionTake last value.
- since
- 2.7
val take_front : 'a t -> 'aTake first value.
- raises Empty
if empty.
val take_front_opt : 'a t -> 'a optionTake first value.
- since
- 2.7
val update_back : 'a t -> ('a -> 'a option) -> unitUpdate last value. If the deque is empty do nothing. If the function returns
None, remove last element; if it returnsSome x, replace last element withx.- since
- 2.7
val update_front : 'a t -> ('a -> 'a option) -> unitUpdate first value. If the deque is empty do nothing. Similar to
update_backbut for the first value.- since
- 2.7
val append_front : into:'a t -> 'a t -> unitappend_front ~into qadds all elements ofqat the front ofinto.O(length q)in time.- since
- 0.13
val append_back : into:'a t -> 'a t -> unitappend_back ~into qadds all elements ofqat the back ofinto.O(length q)in time.- since
- 0.13
val iter : ('a -> unit) -> 'a t -> unitIterate on elements.
val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'bFold on elements.
- since
- 0.13
Conversions
val of_seq : 'a sequence -> 'a tCreate a deque from the sequence. Optional argument
dequedisappears, useadd_seq_backinstead.- since
- 0.13
val add_seq_front : 'a t -> 'a sequence -> unitadd_seq_front q seqadds elements ofseqinto the front ofq, in reverse order.O(n)in time, wherenis the number of elements to add.- since
- 0.13
val add_seq_back : 'a t -> 'a sequence -> unitadd_seq_back q seqadds elements ofseqinto the back ofq, in order.O(n)in time, wherenis the number of elements to add.- since
- 0.13
val of_list : 'a list -> 'a tConversion from list, in order.
- since
- 0.13
val to_list : 'a t -> 'a listList of elements, in order. Less efficient than
to_rev_list.- since
- 0.13
val to_rev_list : 'a t -> 'a listEfficient conversion to list, in reverse order.
- since
- 0.13
val filter_in_place : 'a t -> ('a -> bool) -> unitKeep only elements that satisfy the predicate.
- since
- 2.7