|
| 1 | +[near-runtime-ts](../README.md) > ["near"](../modules/_near_.md) > [collections](../modules/_near_.collections.md) > [Deque](../classes/_near_.collections.deque.md) |
| 2 | + |
| 3 | +# Class: Deque |
| 4 | + |
| 5 | +A deque class that implements a persistent bidirectional queue. |
| 6 | + |
| 7 | +## Type parameters |
| 8 | +#### T |
| 9 | +## Hierarchy |
| 10 | + |
| 11 | +**Deque** |
| 12 | + |
| 13 | +## Index |
| 14 | + |
| 15 | +### Constructors |
| 16 | + |
| 17 | +* [constructor](_near_.collections.deque.md#constructor) |
| 18 | + |
| 19 | +### Accessors |
| 20 | + |
| 21 | +* [back](_near_.collections.deque.md#back) |
| 22 | +* [first](_near_.collections.deque.md#first) |
| 23 | +* [front](_near_.collections.deque.md#front) |
| 24 | +* [isEmpty](_near_.collections.deque.md#isempty) |
| 25 | +* [last](_near_.collections.deque.md#last) |
| 26 | +* [length](_near_.collections.deque.md#length) |
| 27 | + |
| 28 | +### Methods |
| 29 | + |
| 30 | +* [containsIndex](_near_.collections.deque.md#containsindex) |
| 31 | +* [delete](_near_.collections.deque.md#delete) |
| 32 | +* [popBack](_near_.collections.deque.md#popback) |
| 33 | +* [popFront](_near_.collections.deque.md#popfront) |
| 34 | +* [pushBack](_near_.collections.deque.md#pushback) |
| 35 | +* [pushFront](_near_.collections.deque.md#pushfront) |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +## Constructors |
| 40 | + |
| 41 | +<a id="constructor"></a> |
| 42 | + |
| 43 | +### constructor |
| 44 | + |
| 45 | +⊕ **new Deque**(prefix: *`string`*): [Deque](_near_.collections.deque.md) |
| 46 | + |
| 47 | +*Defined in [near.ts:475](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L475)* |
| 48 | + |
| 49 | +Creates or restores a persistent deque with a given storage prefix. Always use a unique storage prefix for different collections. |
| 50 | + |
| 51 | +**Parameters:** |
| 52 | + |
| 53 | +| Name | Type | Description | |
| 54 | +| ------ | ------ | ------ | |
| 55 | +| prefix | `string` | A prefix to use for every key of this deque. | |
| 56 | + |
| 57 | +**Returns:** [Deque](_near_.collections.deque.md) |
| 58 | + |
| 59 | +___ |
| 60 | + |
| 61 | +## Accessors |
| 62 | + |
| 63 | +<a id="back"></a> |
| 64 | + |
| 65 | +### back |
| 66 | + |
| 67 | +getback(): `T` |
| 68 | + |
| 69 | +*Defined in [near.ts:677](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L677)* |
| 70 | + |
| 71 | +**Returns:** `T` |
| 72 | +The last/back element of the deque. |
| 73 | + |
| 74 | +___ |
| 75 | +<a id="first"></a> |
| 76 | + |
| 77 | +### first |
| 78 | + |
| 79 | +getfirst(): `T` |
| 80 | + |
| 81 | +*Defined in [near.ts:644](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L644)* |
| 82 | + |
| 83 | +**Returns:** `T` |
| 84 | +The first/front element of the deque. |
| 85 | + |
| 86 | +___ |
| 87 | +<a id="front"></a> |
| 88 | + |
| 89 | +### front |
| 90 | + |
| 91 | +getfront(): `T` |
| 92 | + |
| 93 | +*Defined in [near.ts:636](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L636)* |
| 94 | + |
| 95 | +**Returns:** `T` |
| 96 | +The first/front element of the deque. |
| 97 | + |
| 98 | +___ |
| 99 | +<a id="isempty"></a> |
| 100 | + |
| 101 | +### isEmpty |
| 102 | + |
| 103 | +getisEmpty(): `bool` |
| 104 | + |
| 105 | +*Defined in [near.ts:561](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L561)* |
| 106 | + |
| 107 | +**Returns:** `bool` |
| 108 | +True if the deque is empty. |
| 109 | + |
| 110 | +___ |
| 111 | +<a id="last"></a> |
| 112 | + |
| 113 | +### last |
| 114 | + |
| 115 | +getlast(): `T` |
| 116 | + |
| 117 | +*Defined in [near.ts:685](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L685)* |
| 118 | + |
| 119 | +**Returns:** `T` |
| 120 | +The last/back element of the deque. |
| 121 | + |
| 122 | +___ |
| 123 | +<a id="length"></a> |
| 124 | + |
| 125 | +### length |
| 126 | + |
| 127 | +getlength(): `i32` |
| 128 | + |
| 129 | +*Defined in [near.ts:554](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L554)* |
| 130 | + |
| 131 | +**Returns:** `i32` |
| 132 | +The length of the deque. |
| 133 | + |
| 134 | +___ |
| 135 | + |
| 136 | +## Methods |
| 137 | + |
| 138 | +<a id="containsindex"></a> |
| 139 | + |
| 140 | +### containsIndex |
| 141 | + |
| 142 | +▸ **containsIndex**(index: *`i32`*): `bool` |
| 143 | + |
| 144 | +*Defined in [near.ts:538](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L538)* |
| 145 | + |
| 146 | +**Parameters:** |
| 147 | + |
| 148 | +| Name | Type | Description | |
| 149 | +| ------ | ------ | ------ | |
| 150 | +| index | `i32` | The index to check. | |
| 151 | + |
| 152 | +**Returns:** `bool` |
| 153 | +True if the given index is within the range of the deque indices. |
| 154 | + |
| 155 | +___ |
| 156 | +<a id="delete"></a> |
| 157 | + |
| 158 | +### delete |
| 159 | + |
| 160 | +▸ **delete**(index: *`i32`*): `void` |
| 161 | + |
| 162 | +*Defined in [near.ts:546](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L546)* |
| 163 | + |
| 164 | +Removes the content of the element from storage without changing length of the deque. |
| 165 | + |
| 166 | +**Parameters:** |
| 167 | + |
| 168 | +| Name | Type | Description | |
| 169 | +| ------ | ------ | ------ | |
| 170 | +| index | `i32` | The index of the element to remove. | |
| 171 | + |
| 172 | +**Returns:** `void` |
| 173 | + |
| 174 | +___ |
| 175 | +<a id="popback"></a> |
| 176 | + |
| 177 | +### popBack |
| 178 | + |
| 179 | +▸ **popBack**(): `T` |
| 180 | + |
| 181 | +*Defined in [near.ts:665](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L665)* |
| 182 | + |
| 183 | +Removes the last/back element from the deque and returns it. Asserts that the deque is not empty. Decreases the length of the deque. |
| 184 | + |
| 185 | +**Returns:** `T` |
| 186 | +The removed first element of the queue. |
| 187 | + |
| 188 | +___ |
| 189 | +<a id="popfront"></a> |
| 190 | + |
| 191 | +### popFront |
| 192 | + |
| 193 | +▸ **popFront**(): `T` |
| 194 | + |
| 195 | +*Defined in [near.ts:625](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L625)* |
| 196 | + |
| 197 | +Removes the first/front element from the deque and returns it. Asserts that the deque is not empty. Decreases the length of the deque. |
| 198 | + |
| 199 | +**Returns:** `T` |
| 200 | +The removed first element of the queue. |
| 201 | + |
| 202 | +___ |
| 203 | +<a id="pushback"></a> |
| 204 | + |
| 205 | +### pushBack |
| 206 | + |
| 207 | +▸ **pushBack**(element: *`T`*): `i32` |
| 208 | + |
| 209 | +*Defined in [near.ts:653](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L653)* |
| 210 | + |
| 211 | +Adds a new element to the end of the deque. Increases the length of the deque. |
| 212 | + |
| 213 | +**Parameters:** |
| 214 | + |
| 215 | +| Name | Type | Description | |
| 216 | +| ------ | ------ | ------ | |
| 217 | +| element | `T` | A new element to add. | |
| 218 | + |
| 219 | +**Returns:** `i32` |
| 220 | +The index of a newly added element |
| 221 | + |
| 222 | +___ |
| 223 | +<a id="pushfront"></a> |
| 224 | + |
| 225 | +### pushFront |
| 226 | + |
| 227 | +▸ **pushFront**(element: *`T`*): `i32` |
| 228 | + |
| 229 | +*Defined in [near.ts:614](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L614)* |
| 230 | + |
| 231 | +Adds a new element in front of the deque. Increases the length of the deque. |
| 232 | + |
| 233 | +**Parameters:** |
| 234 | + |
| 235 | +| Name | Type | Description | |
| 236 | +| ------ | ------ | ------ | |
| 237 | +| element | `T` | A new element to add. | |
| 238 | + |
| 239 | +**Returns:** `i32` |
| 240 | +The index of a newly added element |
| 241 | + |
| 242 | +___ |
| 243 | + |
0 commit comments