Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 20ba61d

Browse files
Merge pull request #11 from nearprotocol/add-top-n
Add TopN collection. Fix Map bug. Add Map values. Adding missing documentation and comments.
2 parents 30d6281 + b4f1a32 commit 20ba61d

15 files changed

+2613
-550
lines changed
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
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+
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
[near-runtime-ts](../README.md) > ["near"](../modules/_near_.md) > [collections](../modules/_near_.collections.md) > [Map](../classes/_near_.collections.map.md)
2+
3+
# Class: Map
4+
5+
A map class that implements a persistent unordered map. NOTE: The Map doesn't store keys, so if you need to retrive them, include keys in the values.
6+
7+
## Type parameters
8+
#### K
9+
#### V
10+
## Hierarchy
11+
12+
**Map**
13+
14+
## Index
15+
16+
### Constructors
17+
18+
* [constructor](_near_.collections.map.md#constructor)
19+
20+
### Methods
21+
22+
* [contains](_near_.collections.map.md#contains)
23+
* [delete](_near_.collections.map.md#delete)
24+
* [get](_near_.collections.map.md#get)
25+
* [set](_near_.collections.map.md#set)
26+
* [values](_near_.collections.map.md#values)
27+
28+
---
29+
30+
## Constructors
31+
32+
<a id="constructor"></a>
33+
34+
### constructor
35+
36+
**new Map**(prefix: *`string`*): [Map](_near_.collections.map.md)
37+
38+
*Defined in [near.ts:696](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L696)*
39+
40+
Creates or restores a persistent map with a given storage prefix. Always use a unique storage prefix for different collections.
41+
42+
**Parameters:**
43+
44+
| Name | Type | Description |
45+
| ------ | ------ | ------ |
46+
| prefix | `string` | A prefix to use for every key of this map. |
47+
48+
**Returns:** [Map](_near_.collections.map.md)
49+
50+
___
51+
52+
## Methods
53+
54+
<a id="contains"></a>
55+
56+
### contains
57+
58+
**contains**(key: *`K`*): `bool`
59+
60+
*Defined in [near.ts:736](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L736)*
61+
62+
**Parameters:**
63+
64+
| Name | Type | Description |
65+
| ------ | ------ | ------ |
66+
| key | `K` | Key to check. |
67+
68+
**Returns:** `bool`
69+
True if the given key present in the map.
70+
71+
___
72+
<a id="delete"></a>
73+
74+
### delete
75+
76+
**delete**(key: *`K`*): `void`
77+
78+
*Defined in [near.ts:744](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L744)*
79+
80+
Removes value and the key from the map.
81+
82+
**Parameters:**
83+
84+
| Name | Type | Description |
85+
| ------ | ------ | ------ |
86+
| key | `K` | Key to remove. |
87+
88+
**Returns:** `void`
89+
90+
___
91+
<a id="get"></a>
92+
93+
### get
94+
95+
**get**(key: *`K`*, defaultValue?: *`V`*): `V`
96+
97+
*Defined in [near.ts:753](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L753)*
98+
99+
**Parameters:**
100+
101+
| Name | Type | Default value | Description |
102+
| ------ | ------ | ------ | ------ |
103+
| key | `K` | - | Key of the element. |
104+
| `Default value` defaultValue | `V` | null | The default value if the key is not present. |
105+
106+
**Returns:** `V`
107+
Value for the given key or the default value.
108+
109+
___
110+
<a id="set"></a>
111+
112+
### set
113+
114+
**set**(key: *`K`*, value: *`V`*): `void`
115+
116+
*Defined in [near.ts:762](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L762)*
117+
118+
Sets the new value for the given key.
119+
120+
**Parameters:**
121+
122+
| Name | Type | Description |
123+
| ------ | ------ | ------ |
124+
| key | `K` | Key of the element. |
125+
| value | `V` | The new value of the element. |
126+
127+
**Returns:** `void`
128+
129+
___
130+
<a id="values"></a>
131+
132+
### values
133+
134+
**values**(start?: *`K`*, end?: *`K`*, limit?: *`i32`*, startInclusive?: *`bool`*): `V`[]
135+
136+
*Defined in [near.ts:722](https://github.com/nearprotocol/near-runtime-ts/blob/a04d184/near.ts#L722)*
137+
138+
Returns values of the map between the given start key and the end key.
139+
140+
**Parameters:**
141+
142+
| Name | Type | Default value | Description |
143+
| ------ | ------ | ------ | ------ |
144+
| `Default value` start | `K` | null | Starting from which key to include values. Default is \`null\`, means from the beginning. |
145+
| `Default value` end | `K` | null | Up to which key include values (inclusive). Default is \`null\`, means to the end. |
146+
| `Default value` limit | `i32` | -1 | The maximum number of values to return. Default is \`-1\`, means no limit. |
147+
| `Default value` startInclusive | `bool` | true | Whether the start key is inclusive. Default is \`true\`, means include start key. It's useful to set it to false for pagination. |
148+
149+
**Returns:** `V`[]
150+
151+
___
152+

0 commit comments

Comments
 (0)