Vector

collections/vectorDocs


near-sdk-js v2.0.0 / collections/vector / Vector

Class: Vector<DataType>

An iterable implementation of vector that stores its content on the trie. Uses the following map: index -> element

Extends

Type Parameters

DataType

Constructors

new Vector()

new Vector<DataType>(prefix, length): Vector<DataType>

Parameters

prefix: string

The byte prefix to use when storing elements inside this collection.

length: number = 0

The initial length of the collection. By default 0.

Returns

Vector<DataType>

Overrides

SubType.constructor

Defined in

packages/near-sdk-js/src/collections/vector.ts:31

Properties

length

length: number = 0

The initial length of the collection. By default 0.

Defined in

packages/near-sdk-js/src/collections/vector.ts:31


prefix

readonly prefix: string

The byte prefix to use when storing elements inside this collection.

Defined in

packages/near-sdk-js/src/collections/vector.ts:31

Methods

[iterator]()

[iterator](): VectorIterator<DataType>

Returns

VectorIterator<DataType>

Defined in

packages/near-sdk-js/src/collections/vector.ts:174


clear()

clear(): void

Remove all of the elements stored within the collection.

Returns

void

Defined in

packages/near-sdk-js/src/collections/vector.ts:211


extend()

extend(elements): void

Extends the current collection with the passed in array of elements.

Parameters

elements: DataType[]

The elements to extend the collection with.

Returns

void

Defined in

packages/near-sdk-js/src/collections/vector.ts:168


get()

get(index, options?): DataType

Get the data stored at the provided index.

Parameters

index: number

The index at which to look for the data.

options?: Omit<GetOptions<DataType>, "serializer">

Options for retrieving the data.

Returns

DataType

Defined in

packages/near-sdk-js/src/collections/vector.ts:48


isEmpty()

isEmpty(): boolean

Checks whether the collection is empty.

Returns

boolean

Defined in

packages/near-sdk-js/src/collections/vector.ts:38


pop()

pop(options?): DataType

Removes and retrieves the element with the highest index.

Parameters

options?: Omit<GetOptions<DataType>, "serializer">

Options for retrieving the data.

Returns

DataType

Defined in

packages/near-sdk-js/src/collections/vector.ts:118


push()

push(element, options?): void

Adds data to the collection.

Parameters

element: DataType

The data to store.

options?: Pick<GetOptions<DataType>, "serializer">

Options for storing the data.

Returns

void

Defined in

packages/near-sdk-js/src/collections/vector.ts:100


replace()

replace(index, element, options?): DataType

Replaces the data stored at the provided index with the provided data and returns the previously stored data.

Parameters

index: number

The index at which to replace the data.

element: DataType

The data to replace with.

options?: GetOptions<DataType>

Options for retrieving and storing the data.

Returns

DataType

Defined in

packages/near-sdk-js/src/collections/vector.ts:141


serialize()

serialize(options?): Uint8Array

Serialize the collection.

Parameters

options?: Pick<GetOptions<DataType>, "serializer">

Options for storing the data.

Returns

Uint8Array

Defined in

packages/near-sdk-js/src/collections/vector.ts:225


set_reconstructor()

set_reconstructor(options?): Omit<GetOptions<DataType>, "serializer">

Parameters

options?: Omit<GetOptions<DataType>, "serializer">

Returns

Omit<GetOptions<DataType>, "serializer">

Inherited from

SubType.set_reconstructor

Defined in

packages/near-sdk-js/src/collections/subtype.ts:8


subtype()

subtype(): any

Returns

any

Inherited from

SubType.subtype

Defined in

packages/near-sdk-js/src/collections/subtype.ts:6


swapRemove()

swapRemove(index, options?): DataType

Removes an element from the vector and returns it in serialized form. The removed element is replaced by the last element of the vector. Does not preserve ordering, but is O(1).

Parameters

index: number

The index at which to remove the element.

options?: GetOptions<DataType>

Options for retrieving and storing the data.

Returns

DataType

Defined in

packages/near-sdk-js/src/collections/vector.ts:70


toArray()

toArray(options?): DataType[]

Return a JavaScript array of the data stored within the collection.

Parameters

options?: GetOptions<DataType>

Options for retrieving and storing the data.

Returns

DataType[]

Defined in

packages/near-sdk-js/src/collections/vector.ts:196


reconstruct()

static reconstruct<DataType>(data): Vector<DataType>

Converts the deserialized data from storage to a JavaScript instance of the collection.

Type Parameters

DataType

Parameters

data: Vector<DataType>

The deserialized data to create an instance from.

Returns

Vector<DataType>

Defined in

packages/near-sdk-js/src/collections/vector.ts:234

Last updated