Module Sek
This library offers efficient implementations of ephemeral sequences and persistent sequences, together with efficient conversions between these two data structures.
Type Abbreviations
type index= intAn index into a sequence is an integer. It is comprised between 0 (included) and the length of the sequence (excluded or included, depending on the circumstances).
type 'a segment= 'a array * index * lengthAn array segment is described by a triple of an array
a, a start indexi, and a lengthk.
type 'a segments= ('a segment -> unit) -> unitA sequence of array segments is represented by a higher-order iterator.
Library API
module type ITER = sig ... endThe signature
ITERis the core iterator API. It is common to ephemeral and persistent sequences. Please follow the link for details.
module type ITER_EPHEMERAL = sig ... endThe signature
ITER_EPHEMERALextends the iterator API with concepts and operations that exist only in the case of iterators over ephemeral sequences. Please follow the link for details.
Ephemeral and Persistent Sequences
val front : sideval back : sideA side appears as a parameter to several operations, such as
pushandpop, which can operate at either end of a sequence.
val forward : directionval backward : directionA direction appears as a parameter to several operations, such as
iter, which can traverse the sequence either forward (from front to back) or backward (from back to front).
val sign : direction -> intsign forwardis+1.sign backwardis-1.
exceptionEmptyThe exception
Emptyis raised bypopandpeekoperations when applied to an empty sequence.
exceptionEndThe exception
Endis raised by the iterator operationsget,get_segment,get_and_move, andget_segment_and_jumpwhen the iterator has moved past the end of the sequence.
module Ephemeral : sig ... endThe submodule
Ephemeral, also available under the nameE, offers an implementation of ephemeral (mutable) sequences. Please follow the link for details.
module Persistent : sig ... endThe submodule
Persistent, also available under the nameP, offers an implementation of persistent (immutable) sequences. Please follow the link for details.
module P = PersistentPis a short name for the submodulePersistent.
Conversion Functions
val snapshot : 'a Ephemeral.t -> 'a Persistent.tsnapshot sconstructs and returns a persistent sequence whose elements are the elements ofs. It is less efficient thansnapshot_and_clear, whose use should be preferred, when possible.Time complexity: O(K). Note that this operation introduces sharing: therefore, it may increase the cost of subsequent operations.
val snapshot_and_clear : 'a Ephemeral.t -> 'a Persistent.tsnapshot_and_clear sconstructs and returns a persistent sequence whose elements are the elements of an ephemeral sequences. As a side effect, it clearss.Time complexity: O(min(K,n)). In other words, the cost is always O(K) and, in the specific case of short sequences, it is only O(n).
In the particular case where the ephemeral sequence
shas been constructed by applying a series ofpushoperations, the cost ofsnapshot_and_clearmay be charged to thesepushoperations, allowing one to consider thatsnapshot_and_clearcosts O(1).
val edit : 'a Persistent.t -> 'a Ephemeral.tedit sconstructs and returns a new ephemeral sequence whose elements are the elements ofs.Time complexity: O(K).
Emulation Layers
Miscellaneous
val released : unit -> unitThe function call
released()does nothing if the library was compiled in release mode, and fails (with an assertion failure) if the library was compiled with assertions enabled.
module Segment : sig ... endThe module
Segmentoffers facilities for working with array segments. An array segment is a triple of an array, a start index, and a length.
Settings
Chunk Capacity
module type CAPACITY = sig ... endOverwriting Empty Slots
module type OVERWRITE_EMPTY_SLOTS = sig ... endCompact Persistent Sequence Threshold
module type THRESHOLD = sig ... endDynamic Checking of Iterator Validity
module type CHECK_ITERATOR_VALIDITY = sig ... endThe Functor Make
module Make : functor (Settings : sig ... end) -> SEKThe functor
Makeconstructs an implementation of the signatureSEK, and allows the user to choose the value of the settings described above. Be warned, however, that the number and the nature of the settings expected by this functor may change in the future. A relatively forward-compatible way of using this functor is to always pass it a structure that is built by including the structureDefaultSettingsand overriding the definition of one or more settings.
module DefaultSettings : sig ... endThe module
DefaultSettingsprovides a set of recommended settings for the functorMake.
The Functor SupplyDefault
module SupplyDefault = SupplyDefault.SupplyDefault