Module EphemeralChunk.Make
Parameters
Signature
type 'a t
A chunk is a mutable object, which represents a sequence of elements of type
'a
. A chunk has a fixed capacity, which it cannot exceed.
val check : 'a t -> unit
check c
verifies that the chunkc
is valid, i.e., that its internal invariant is satisfied.
val create : 'a -> Sek__.PublicTypeAbbreviations.capacity -> 'a t
create d n
creates a fresh chunk whose capacity isn
. The default elementd
is used to initialize empty slots. Ifoverwrite_empty_slots
istrue
, then it is also used to overwrite a slot that becomes empty, e.g., inpop
andcarve_back
.
val make : 'a -> Sek__.PublicTypeAbbreviations.capacity -> Sek__.PublicTypeAbbreviations.length -> 'a -> 'a t
make d n k v
creates a fresh chunk whose default element isd
, whose capacity isn
, and which contains a sequence ofk
copies of the valuev
. The integerk
must be no greater thann
.
val init : 'a -> Sek__.PublicTypeAbbreviations.capacity -> Sek__.PublicTypeAbbreviations.length -> Sek__.PublicTypeAbbreviations.index -> (Sek__.PublicTypeAbbreviations.index -> 'a) -> 'a t
init d n k i f
creates a fresh chunk whose default element isd
, whose capacity isn
, and which contains the sequence of values produced by the callsf i
,f (i+1)
, ...f (i+k-1)
, in this order. The integerk
must be no greater thann
.
val dummy : 'a -> 'a t
dummy d
creates a dummy (invalid!) chunk, which can be used as a default element when creating a chunk of chunks. This dummy chunk is invalid and must not be used. As an exception to this rule, it is permitted to applyis_empty
andis_full
to a dummy chunk; in that case, they both returntrue
.
val is_dummy : 'a t -> bool
is_dummy c
tells whetherc
is a dummy chunk, that is, whether it has been built bydummy
.
val of_array_segment : 'a -> Sek__.PublicTypeAbbreviations.capacity -> 'a array -> Sek__.PublicTypeAbbreviations.index -> Sek__.PublicTypeAbbreviations.length -> 'a t
of_array_segment d n a head size
creates a chunk by copying data from the array segment defined by the arraya
, the start indexhead
, and the sizesize
. The chunk has capacityn
and default valued
.size
must be less than or equal ton
.
val default : 'a t -> 'a
default c
returns the default element that was provided when the chunkc
was created.
val length : 'a t -> Sek__.PublicTypeAbbreviations.length
length c
is the length of the sequencec
.
val capacity : 'a t -> Sek__.PublicTypeAbbreviations.capacity
capacity c
is the capacity of the chunkc
, that is, the maximum number of elements that this chunk can hold.
val data : 'a t -> 'a array
data c
is the raw array that underlies the chunkc
. This function is dangerous; it should be used only to implement efficient iterators.
val is_empty : 'a t -> bool
is_empty c
is equivalent tolength c = 0
.
val is_full : 'a t -> bool
is_full c
is equivalent tolength c = capacity c
.
val is_empty_or_dummy : 'a t -> bool
is_empty_or_dummy c
is equivalent tois_empty c || is_dummy c
.
val is_full_or_dummy : 'a t -> bool
is_full_or_dummy c
is equivalent tois_full c || is_dummy c
.
val get : 'a t -> Sek__.PublicTypeAbbreviations.index -> 'a
get c i
returns the element found at indexi
in the sequencec
.i
must be comprised between 0 included andlength c
excluded.
val set : 'a t -> Sek__.PublicTypeAbbreviations.index -> 'a -> unit
set c i x
replaces the element found at indexi
in the sequencec
with the valuex
.i
must be comprised between 0 included andlength c
excluded.
val peek : Sek__.PrivateSignatures.pov -> 'a t -> 'a
peek pov c
returns the first or last element of the chunkc
, depending on the point-of-viewpov
. The chunkc
must be nonempty.
val push : Sek__.PrivateSignatures.pov -> 'a t -> 'a -> unit
push pov c x
inserts the elementx
at the front or back of the chunkc
, depending on the point-of-viewpov
. The chunkc
must not be full.
val pop : Sek__.PrivateSignatures.pov -> 'a t -> 'a
pop pov c
extracts and returns the first or last element of the chunkc
, depending on the point-of-viewpov
. The chunkc
must be nonempty.
val copy : 'a t -> 'a t
copy c
creates and returns a copy of the chunkc
. The copy is identical to the original chunk, but is disjoint fromc
, so an update to the copy does not affectc
.
val clear : 'a t -> unit
clear c
updates the chunkc
so that it represents the empty sequence.
val carve_back : 'a t -> Sek__.PublicTypeAbbreviations.index -> 'a t
carve_back c i
splits the sequencec
at indexi
. The indexi
must be comprised between 0 included andlength c
included. After this operation, the chunkc
is truncated and represents the first part of the sequence, up to indexi
excluded. A new chunk, which represents the second part of the sequence, beginning at indexi
, is returned.
val take : 'a t -> Sek__.PublicTypeAbbreviations.index -> unit
take c i
truncates the sequencec
at indexi
. The indexi
must be comprised between 0 included andlength c
included. After this operation, the chunkc
is truncated and represents the first part of the sequence, up to indexi
excluded.
val drop : 'a t -> Sek__.PublicTypeAbbreviations.index -> unit
drop c i
truncates the sequencec
at indexi
. The indexi
must be comprised between 0 included andlength c
included. After this operation, the chunkc
is truncated and represents the second part of the sequence, beginning at indexi
.
val print : ('a -> PPrint.document) -> 'a t -> PPrint.document
print
is a chunk printer, parameterized with an element printer. It is intended to be used only while debugging.
module View : sig ... end
val view : 'a t -> View.view
view c
is a view that covers all of the elements currently found in the chunkc
.
val iter_segments : Sek__.PrivateSignatures.pov -> 'a t -> 'a Sek__.PublicTypeAbbreviations.segments
iter_segments pov c
returns a sequence of up to two array segments that cover the chunkc
. It is analogous toView.iter_segments
above, but applies to the entire chunk (not to a view). It is permitted to applyiter_segments
to a dummy chunk.