Skip to content

TypedVector

Defined in: packages/data/src/storage/typed-vector.ts:47

A growable vector over a fixed-size typed array.

RingVector boxes every element into a generic T slot; this holds raw numbers in an Int32Array, Float64Array or similar, so a million elements cost a million machine words rather than a million pointers plus a million heap-allocated numbers.

Build it for the memory, not for the speed. What this wins is footprint and cache locality on large numeric collections, which matters at a scale where the per-element constant does not.

Growth doubles the backing and copies, so pushBack is O(1) amortised. The copy uses TypedArray.prototype.set, a single bulk move rather than a JS loop.

Only back-end operations are declared: a front-end insert on a flat array is O(n), so IPushFront is deliberately absent. Use RingVector when both ends are needed.

C extends TypedArrayConstructor

The typed-array constructor, e.g. Float64Array.

new TypedVector<C>(arrayType, iterable?, options?): TypedVector<C>

Defined in: packages/data/src/storage/typed-vector.ts:53

C

Iterable<number, any, any>

TypedVectorOptions

TypedVector<C>

get physicalLength(): number

Defined in: packages/data/src/storage/typed-vector.ts:82

Slots allocated, not elements held.

number

[iterator](): Iterator<number>

Defined in: packages/data/src/storage/typed-vector.ts:86

Iterator<number>

IStorage.[iterator]


back(): number | undefined

Defined in: packages/data/src/storage/typed-vector.ts:156

O(1).

number | undefined


clear(): void

Defined in: packages/data/src/storage/typed-vector.ts:96

void

IStorage.clear


count(): number

Defined in: packages/data/src/storage/typed-vector.ts:92

number

IStorage.count


get(index): number | undefined

Defined in: packages/data/src/storage/typed-vector.ts:101

O(1). Out of range returns undefined rather than throwing.

number

number | undefined


popBack(): number | undefined

Defined in: packages/data/src/storage/typed-vector.ts:143

O(1).

number | undefined


pushBack(item): void

Defined in: packages/data/src/storage/typed-vector.ts:123

O(1) amortised.

number

void


pushBackAll(items): void

Defined in: packages/data/src/storage/typed-vector.ts:131

O(n) in the number of items, with one bulk copy and at most one growth.

readonly number[]

void


set(index, item): void

Defined in: packages/data/src/storage/typed-vector.ts:114

O(1).

number

number

void

If index is outside 0 .. count() - 1.


toTypedArray(): InstanceType<C>

Defined in: packages/data/src/storage/typed-vector.ts:166

A copy of the elements held, as a typed array of the vector’s own type.

A copy rather than a view, so later growth cannot leave the caller holding a window onto a detached buffer.

InstanceType<C>