lsm-tree-0.1.0.0: Log-structured merge-trees
Safe HaskellSafe-Inferred
LanguageGHC2021

Database.LSMTree.Internal.Vector.Growing

Description

Vectors with support for appending elements.

Synopsis

Documentation

data GrowingVector s a Source #

A vector with support for appending elements.

Internally, the elements of a growing vector are stored in a buffer. This buffer is automatically enlarged whenever this is needed for storing additional elements. On each such enlargement, the size of the buffer is multiplied by a power of 2, whose exponent is chosen just big enough to make the final buffer size at least as high as the new vector length.

Note that, while buffer sizes and vector lengths are represented as Int values internally, the above-described buffer enlargement scheme has the consequence that the largest possible buffer size and thus the largest possible vector length may not be the maximum Int value. That said, they are always greater than half the maximum Int value, which should be enough for all practical purposes.

Constructors

GrowingVector !(STRef s (MVector s a)) !(PrimVar s Int) 

new Source #

Arguments

:: Int

Initial buffer size

-> ST s (GrowingVector s a)

Construction of the vector

Creates a new, initially empty, vector.

append :: forall s a. GrowingVector s a -> Int -> a -> ST s () Source #

Appends a value a certain number of times to a vector. If a negative number is provided as the count, the vector is not changed.

freeze :: GrowingVector s a -> ST s (Vector a) Source #

Turns a growing vector into an ordinary vector.

readMaybeLast :: GrowingVector s a -> ST s (Maybe a) Source #

Reads the last element of a growing vector if it exists.