The generic type parameter T
can be any valid AssemblyScript type.
Creates or restores a persistent deque with a given storage prefix. Always use a unique storage prefix for different collections.
Example
let dq = new PersistentDeque<string>("q") // note the prefix must be unique (per NEAR account)
A prefix to use for every key of this deque.
Returns the last element in the deque without changing the queue
let dq = new PersistentDeque<string>("q")
dq.pushFront("world")
dq.pushFront("hello")
assert(dq.back == "world")
assert(dq.length == 2)
The last/back element of the deque.
Returns the first element in the deque without changing the queue
dq.first // alias of front
The first/front element of the deque.
Returns the first element in the deque without changing the queue
let dq = new PersistentDeque<string>("q")
dq.pushFront("world")
dq.pushFront("hello")
assert(dq.front == "hello")
assert(dq.length == 2)
The first/front element of the deque.
Returns a boolean indicating whether the deque is empty
let dq = new PersistentDeque<string>("q")
dq.isEmpty // true
dq.pushFront("hello world")
dq.isEmpty // false
True if the deque is empty.
Returns the last element in the deque without changing the queue
dq.last // alias of method back
The last/back element of the deque.
Returns the length of the deque
let dq = new PersistentDeque<string>("q")
dq.length // 0
dq.pushFront("hello world")
dq.length // 1
The length of the deque.
Checks whether the index is within the range of the deque indices
let dq = new PersistentDeque<string>("q")
dq.containsIndex(0) // false
dq.pushFront("hello world")
dq.containsIndex(0) // true
The index to check.
True if the given index is within the range of the deque indices.
Removes the last/back element from the deque and returns it. Asserts that the deque is not empty. Decreases the length of the deque.
let dq = new PersistentDeque<string>("q")
dq.pushFront("world")
dq.pushFront("hello")
let element = dq.popBack()
assert(element == "world")
assert(dq.length == 1)
The removed first element of the queue.
Removes the first/front element from the deque and returns it. Asserts that the deque is not empty. Decreases the length of the deque.
let dq = new PersistentDeque<string>("q")
dq.pushFront("world")
dq.pushFront("hello")
let element = dq.popFront()
assert(element == "hello")
assert(dq.length == 1)
The removed first element of the queue.
Adds a new element to the end of the deque. Increases the length of the deque.
let dq = new PersistentDeque<string>("q")
dq.pushBack("hello")
dq.pushBack("world")
dq[0] // hello
A new element to add.
The index of a newly added element
Adds a new element in front of the deque. Increases the length of the deque.
let dq = new PersistentDeque<string>("q")
dq.pushFront("world")
dq.pushFront("hello")
dq[0] // "hello"
A new element to add.
The index of a newly added element
Generated using TypeDoc
This class is one of several convenience collections built on top of the
Storage
class exposed by the NEAR platform. It implements queue -- a persistent bidirectional queue (aka double-ended queue or deque)To create a deque
let dq = new PersistentDeque<string>("q") // choose a unique prefix per account
To use the deque
IMPORTANT NOTE: Since all data stored on the blockchain is kept in a single key-value store under the contract account, you must always use a unique storage prefix for different collections to avoid data collision.