mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-05 19:00:31 -05:00
in CCVector, use invalid_arg, and document it
This commit is contained in:
parent
7288045828
commit
541d716d5c
2 changed files with 7 additions and 4 deletions
|
|
@ -129,7 +129,7 @@ let grow_with_ v ~filler:x =
|
|||
) else (
|
||||
let n = Array.length v.vec in
|
||||
let size = min (2 * n + 3) Sys.max_array_length in
|
||||
if size = n then failwith "vec: can't grow any further";
|
||||
if size = n then invalid_arg "vec: can't grow any further";
|
||||
resize_ v size v.vec.(0)
|
||||
)
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ let grow_with_ v ~filler:x =
|
|||
behave well *)
|
||||
let ensure_assuming_not_empty_ v ~size =
|
||||
if size > Sys.max_array_length
|
||||
then failwith "vec.ensure: size too big"
|
||||
then invalid_arg "vec.ensure: size too big"
|
||||
else (
|
||||
let n = ref (max 8 (Array.length v.vec)) in
|
||||
while !n < size do n := min Sys.max_array_length (2* !n) done;
|
||||
|
|
|
|||
|
|
@ -66,12 +66,15 @@ val ensure_with : init:'a -> ('a, rw) t -> int -> unit
|
|||
This does not affect [length v].
|
||||
@param init if [capacity v = 0], used to enforce the type of the vector
|
||||
(see {!create_with}).
|
||||
@raise Invalid_arg if the size is not suitable (negative, or too big for OCaml arrays)
|
||||
@since 0.14 *)
|
||||
|
||||
val ensure : ('a, rw) t -> int -> unit
|
||||
(** Hint to the vector that it should have at least the given capacity.
|
||||
Just a hint, will not be enforced if the vector is empty and [init]
|
||||
is not provided. *)
|
||||
is not provided.
|
||||
@raise Invalid_arg if the size is not suitable (negative, or too big for OCaml arrays)
|
||||
*)
|
||||
|
||||
val is_empty : ('a, _) t -> bool
|
||||
(** Is the vector empty? *)
|
||||
|
|
@ -114,7 +117,7 @@ val pop : ('a, rw) t -> 'a option
|
|||
(** Remove last element, or [None]. *)
|
||||
|
||||
val pop_exn : ('a, rw) t -> 'a
|
||||
(** Remove last element, or raise a Failure if empty.
|
||||
(** Remove last element, or raise an exception if empty.
|
||||
@raise Empty on an empty vector. *)
|
||||
|
||||
val top : ('a, _) t -> 'a option
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue