Module CCFQueue
Functional queues
type 'a sequence
= ('a -> unit) -> unit
type 'a klist
= unit -> [ `Nil | `Cons of 'a * 'a klist ]
type 'a equal
= 'a -> 'a -> bool
type 'a printer
= Stdlib.Format.formatter -> 'a -> unit
Basics
val empty : 'a t
val is_empty : 'a t -> bool
val singleton : 'a -> 'a t
val doubleton : 'a -> 'a -> 'a t
val take_front_exn : 'a t -> 'a * 'a t
Same as
take_front
, but fails on empty queues.- raises Empty
if the queue is empty.
val take_front_l : int -> 'a t -> 'a list * 'a t
take_front_l n q
takes at mostn
elements from the front ofq
, and returns them wrapped in a list.- raises Invalid_argument
if n<0.
val take_front_while : ('a -> bool) -> 'a t -> 'a list * 'a t
val take_back : 'a t -> ('a t * 'a) option
Take last element.
val take_back_exn : 'a t -> 'a t * 'a
Same as
take_back
, but fails on empty queues.- raises Empty
if the queue is empty.
val take_back_l : int -> 'a t -> 'a t * 'a list
take_back_l n q
removes and returns the lastn
elements ofq
. The elements are in the order of the queue, that is, the head of the returned list is the first element to appear viatake_front
.take_back_l 2 (of_list [1;2;3;4]) = of_list [1;2], [3;4]
.- raises Invalid_argument
if n<0.
Individual extraction
val first : 'a t -> 'a option
First element of the queue.
val last : 'a t -> 'a option
Last element of the queue.
Global Operations
val append : 'a t -> 'a t -> 'a t
Append two queues. Elements from the second one come after elements of the first one. Linear in the size of the second queue.
val size : 'a t -> int
Number of elements in the queue (constant time).
Conversions
val of_list : 'a list -> 'a t
val to_list : 'a t -> 'a list
val add_seq_front : 'a sequence -> 'a t -> 'a t
val add_seq_back : 'a t -> 'a sequence -> 'a t
val to_seq : 'a t -> 'a sequence
val of_seq : 'a sequence -> 'a t
val to_klist : 'a t -> 'a klist
val of_klist : 'a klist -> 'a t
val (--) : int -> int -> int t
a -- b
is the integer range froma
tob
, both included.- since
- 0.10
val (--^) : int -> int -> int t
a -- b
is the integer range froma
tob
, whereb
is excluded.- since
- 0.17