Vector

near-runtime-ts > "near" > collections > Vector

Class: Vector

A vector class that implements a persistent array.

Type parameters

T

Hierarchy

Vector

Index

Constructors

  • constructor

Accessors

  • back

  • first

  • front

  • isEmpty

  • last

  • length

Methods

  • containsIndex

  • pop

  • popBack

  • push

  • pushBack

  • remove

Constructors

constructor

new Vector(prefix: string): Vector

Defined in near.ts:237

Creates or restores a persistent vector with a given storage prefix. Always use a unique storage prefix for different collections.

Parameters:

Name

Type

Description

prefix

string

A prefix to use for every key of this vector.

Returns: Vector

Accessors

back

getback(): T

Defined in near.ts:393

Returns: T The last element of the vector. Asserts that the vector is not empty.

first

getfirst(): T

Defined in near.ts:416

Returns: T The first element of the vector. Asserts that the vector is not empty.

front

getfront(): T

Defined in near.ts:408

Returns: T The first element of the vector. Asserts that the vector is not empty.

isEmpty

getisEmpty(): bool

Defined in near.ts:278

Returns: bool True if the vector is empty.

last

getlast(): T

Defined in near.ts:401

Returns: T The last element of the vector. Asserts that the vector is not empty.

length

getlength(): i32

Defined in near.ts:285

Returns: i32 The length of the vector.

Methods

containsIndex

containsIndex(index: i32): bool

Defined in near.ts:271

Parameters:

Name

Type

Description

index

i32

The index to check.

Returns: bool True if the given index is within the range of the vector indices.

pop

pop(): T

Defined in near.ts:371

Removes the last element from the vector and returns it. Asserts that the vector is not empty. Decreases the length of the vector.

Returns: T The removed last element of the vector.

popBack

popBack(): T

Defined in near.ts:386

Removes the last element from the vector and returns it. Asserts that the vector is not empty. Decreases the length of the vector.

Returns: T The removed last element of the vector.

push

push(element: T): i32

Defined in near.ts:349

Adds a new element to the end of the vector. Increases the length of the vector.

Parameters:

Name

Type

Description

element

T

A new element to add.

Returns: i32 The index of a newly added element

pushBack

pushBack(element: T): i32

Defined in near.ts:362

Adds a new element to the end of the vector. Increases the length of the vector.

Parameters:

Name

Type

Description

element

T

A new element to add.

Returns: i32 The index of a newly added element

remove

remove(index: i32): void

Defined in near.ts:262

Removes the content of the element from storage without changing length of the vector.

Parameters:

Name

Type

Description

index

i32

The index of the element to remove.

Returns: void