specify behavior of CCFQueue.take_{front,back}_l in some corner cases

This commit is contained in:
Simon Cruanes 2017-09-10 19:56:01 +02:00
parent d7b90d3ba3
commit 56928a1a15
2 changed files with 10 additions and 2 deletions

View file

@ -132,6 +132,9 @@ let take_front q =
with Empty -> None
let take_front_l n q =
if n<0 then (
invalid_arg "take_back_l: cannot take negative number of arguments"
);
let rec aux acc q n =
if n=0 || is_empty q then List.rev acc, q
else
@ -183,6 +186,9 @@ let take_back q =
with Empty -> None
let take_back_l n q =
if n<0 then (
invalid_arg "take_back_l: cannot take negative number of arguments"
);
let rec aux acc q n =
if n=0 || is_empty q then q, acc
else

View file

@ -38,7 +38,8 @@ val take_front_exn : 'a t -> ('a * 'a t)
val take_front_l : int -> 'a t -> 'a list * 'a t
(** [take_front_l n q] takes at most [n] elements from the front
of [q], and returns them wrapped in a list *)
of [q], and returns them wrapped in a list
@raise Invalid_argument if n<0 *)
val take_front_while : ('a -> bool) -> 'a t -> 'a list * 'a t
@ -51,7 +52,8 @@ val take_back_l : int -> 'a t -> 'a t * 'a list
(** [take_back_l n q] removes and returns the last [n] elements of [q]. The
elements are in the order of the queue, that is, the head of the returned
list is the first element to appear via {!take_front}.
[take_back_l 2 (of_list [1;2;3;4]) = of_list [1;2], [3;4]] *)
[take_back_l 2 (of_list [1;2;3;4]) = of_list [1;2], [3;4]]
@raise Invalid_argument if n<0 *)
val take_back_while : ('a -> bool) -> 'a t -> 'a t * 'a list