package spvec
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=7a49527ee7101c5091c9611c6c4b1625
sha512=2834ebaaf9ed0d4cb04aea7759fda74a1b376772937d8cd35b2ec55cfa9eba9775fa987838857cbc441a84793ed1afdb91b20e1a9e24589140bc807ce485534c
doc/index.html
spvec
This library offers semi-persistent vectors.
A semi-persistent vector represents a sequence of elements. It supports reading at an arbitrary index (get) and appending a new element at the end of the vector (push).
A semi-persistent vector apparently offers the API of a persistent data structure, where each push operation produces a new vector. At the same time, it enjoys the efficiency of a mutable data structure, where each push operation modifies the data structure in place.
This is possible because the API is restricted. At every point in time, only the most recent vector and its ancestors are considered valid. get and push must be applied to a valid vector. The call push v x is equivalent to truncate v; push v x: that is, it makes v the most recent valid vector, thereby invalidating all strict descendants of v, then creates and returns a new vector, which is a descendant of v, and is valid.
Documentation
The library offers two modules, Spvec.Safe and Spvec.Unsafe.
Spvec.Safe is safe in the sense that an attempt to use an invalid semi-persistent array is detected at runtime and results in an exception.
Spvec.Unsafe is unsafe in the sense that an attempt to use an invalid semi-persistent array is not detected at runtime and can cause undefined behavior, by which we mean incorrect results or unexpected exceptions.
Spvec.Unsafe is faster and has lower memory usage than Spvec.Safe.
We recommended using Spvec.Safe by default. Switch to Spvec.Unsafe only if superior performance is needed and only after your code has been fully debugged.
Installation and Usage
Type opam install spvec.
In your dune file, add (libraries spvec) to the description of your library or executable.