1
1
// A part of standard library for Tolk
2
- tolk 1.0
2
+ tolk 1.1
3
3
4
4
/**
5
- Dictionaries are represented as `cell` data type (cells can store anything, dicts in particular).
6
- Currently, they have very low-level API very close to TVM internals.
5
+ Low-level API working with TVM dictionaries.
6
+ Not recommended to use, since it's very complicated and error-prone.
7
+ Use `map<K, V>` instead, it's even more efficient then low-level dict API.
8
+
9
+ Dictionaries are represented as `cell` data type.
7
10
Most of functions are duplicated for three common cases:
8
11
- iDict* - dicts with signed integer keys
9
12
- uDict* - dicts with unsigned integer keys
@@ -14,10 +17,12 @@ tolk 1.0
14
17
*/
15
18
16
19
/// In @stdlib/common.tolk, there is a type alias:
17
- /// `type dict = cell?`
20
+ /// ```
21
+ /// type dict = cell?
22
+ /// ```
18
23
/// For clarity, we use "dict" instead of a "cell?" where a cell-dictionary is assumed.
19
24
20
- /// Creates an empty dictionary, which is actually a null value. Equivalent to PUSHNULL
25
+ /// Creates an empty dictionary, which is actually a null value. Equivalent to ` PUSHNULL`
21
26
@pure
22
27
fun createEmptyDict(): dict
23
28
asm "NEWDICT"
@@ -86,28 +91,28 @@ fun dict.uDictSetIfExists(mutate self, keyLen: int, key: int, value: slice): boo
86
91
87
92
88
93
@pure
89
- fun dict.iDictGetRef(self, keyLen: int, key: int): (dict , bool)
94
+ fun dict.iDictGetRef(self, keyLen: int, key: int): (cell? , bool)
90
95
asm(key self keyLen) "DICTIGETREF" "NULLSWAPIFNOT"
91
96
92
97
@pure
93
- fun dict.uDictGetRef(self, keyLen: int, key: int): (dict , bool)
98
+ fun dict.uDictGetRef(self, keyLen: int, key: int): (cell? , bool)
94
99
asm(key self keyLen) "DICTUGETREF" "NULLSWAPIFNOT"
95
100
96
101
@pure
97
- fun dict.sDictGetRef(self, keyLen: int, key: slice): (dict , bool)
102
+ fun dict.sDictGetRef(self, keyLen: int, key: slice): (cell? , bool)
98
103
asm(key self keyLen) "DICTGETREF" "NULLSWAPIFNOT"
99
104
100
105
101
106
@pure
102
- fun dict.iDictGetRefOrNull(self, keyLen: int, key: int): dict
107
+ fun dict.iDictGetRefOrNull(self, keyLen: int, key: int): cell?
103
108
asm(key self keyLen) "DICTIGETOPTREF"
104
109
105
110
@pure
106
- fun dict.uDictGetRefOrNull(self, keyLen: int, key: int): dict
111
+ fun dict.uDictGetRefOrNull(self, keyLen: int, key: int): cell?
107
112
asm(key self keyLen) "DICTUGETOPTREF"
108
113
109
114
@pure
110
- fun dict.sDictGetRefOrNull(self, keyLen: int, key: slice): dict
115
+ fun dict.sDictGetRefOrNull(self, keyLen: int, key: slice): cell?
111
116
asm(key self keyLen) "DICTGETOPTREF"
112
117
113
118
@@ -138,11 +143,11 @@ fun dict.sDictSetAndGet(mutate self, keyLen: int, key: slice, value: slice): (sl
138
143
139
144
140
145
@pure
141
- fun dict.iDictSetAndGetRefOrNull(mutate self, keyLen: int, key: int, value: cell): dict
146
+ fun dict.iDictSetAndGetRefOrNull(mutate self, keyLen: int, key: int, value: cell): cell?
142
147
asm(value key self keyLen) "DICTISETGETOPTREF"
143
148
144
149
@pure
145
- fun dict.uDictSetAndGetRefOrNull(mutate self, keyLen: int, key: int, value: cell): dict
150
+ fun dict.uDictSetAndGetRefOrNull(mutate self, keyLen: int, key: int, value: cell): cell?
146
151
asm(value key self keyLen) "DICTUSETGETOPTREF"
147
152
148
153
@@ -228,15 +233,15 @@ fun dict.sDictGetFirst(self, keyLen: int): (slice?, slice?, bool)
228
233
asm (-> 1 0 2) "DICTMIN" "NULLSWAPIFNOT2"
229
234
230
235
@pure
231
- fun dict.iDictGetFirstAsRef(self, keyLen: int): (int?, dict , bool)
236
+ fun dict.iDictGetFirstAsRef(self, keyLen: int): (int?, cell? , bool)
232
237
asm (-> 1 0 2) "DICTIMINREF" "NULLSWAPIFNOT2"
233
238
234
239
@pure
235
- fun dict.uDictGetFirstAsRef(self, keyLen: int): (int?, dict , bool)
240
+ fun dict.uDictGetFirstAsRef(self, keyLen: int): (int?, cell? , bool)
236
241
asm (-> 1 0 2) "DICTUMINREF" "NULLSWAPIFNOT2"
237
242
238
243
@pure
239
- fun dict.sDictGetFirstAsRef(self, keyLen: int): (slice?, dict , bool)
244
+ fun dict.sDictGetFirstAsRef(self, keyLen: int): (slice?, cell? , bool)
240
245
asm (-> 1 0 2) "DICTMINREF" "NULLSWAPIFNOT2"
241
246
242
247
@@ -253,15 +258,15 @@ fun dict.sDictGetLast(self, keyLen: int): (slice?, slice?, bool)
253
258
asm (-> 1 0 2) "DICTMAX" "NULLSWAPIFNOT2"
254
259
255
260
@pure
256
- fun dict.iDictGetLastAsRef(self, keyLen: int): (int?, dict , bool)
261
+ fun dict.iDictGetLastAsRef(self, keyLen: int): (int?, cell? , bool)
257
262
asm (-> 1 0 2) "DICTIMAXREF" "NULLSWAPIFNOT2"
258
263
259
264
@pure
260
- fun dict.uDictGetLastAsRef(self, keyLen: int): (int?, dict , bool)
265
+ fun dict.uDictGetLastAsRef(self, keyLen: int): (int?, cell? , bool)
261
266
asm (-> 1 0 2) "DICTUMAXREF" "NULLSWAPIFNOT2"
262
267
263
268
@pure
264
- fun dict.sDictGetLastAsRef(self, keyLen: int): (slice?, dict , bool)
269
+ fun dict.sDictGetLastAsRef(self, keyLen: int): (slice?, cell? , bool)
265
270
asm (-> 1 0 2) "DICTMAXREF" "NULLSWAPIFNOT2"
266
271
267
272
@@ -273,6 +278,10 @@ fun dict.iDictGetNext(self, keyLen: int, pivot: int): (int?, slice?, bool)
273
278
fun dict.uDictGetNext(self, keyLen: int, pivot: int): (int?, slice?, bool)
274
279
asm(pivot self keyLen -> 1 0 2) "DICTUGETNEXT" "NULLSWAPIFNOT2"
275
280
281
+ @pure
282
+ fun dict.sDictGetNext(self, keyLen: int, pivot: slice): (slice?, slice?, bool)
283
+ asm(pivot self keyLen -> 1 0 2) "DICTGETNEXT" "NULLSWAPIFNOT2"
284
+
276
285
@pure
277
286
fun dict.iDictGetNextOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool)
278
287
asm(pivot self keyLen -> 1 0 2) "DICTIGETNEXTEQ" "NULLSWAPIFNOT2"
@@ -281,6 +290,10 @@ fun dict.iDictGetNextOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool
281
290
fun dict.uDictGetNextOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool)
282
291
asm(pivot self keyLen -> 1 0 2) "DICTUGETNEXTEQ" "NULLSWAPIFNOT2"
283
292
293
+ @pure
294
+ fun dict.sDictGetNextOrEqual(self, keyLen: int, pivot: slice): (slice?, slice?, bool)
295
+ asm(pivot self keyLen -> 1 0 2) "DICTGETNEXTEQ" "NULLSWAPIFNOT2"
296
+
284
297
285
298
@pure
286
299
fun dict.iDictGetPrev(self, keyLen: int, pivot: int): (int?, slice?, bool)
@@ -290,6 +303,10 @@ fun dict.iDictGetPrev(self, keyLen: int, pivot: int): (int?, slice?, bool)
290
303
fun dict.uDictGetPrev(self, keyLen: int, pivot: int): (int?, slice?, bool)
291
304
asm(pivot self keyLen -> 1 0 2) "DICTUGETPREV" "NULLSWAPIFNOT2"
292
305
306
+ @pure
307
+ fun dict.sDictGetPrev(self, keyLen: int, pivot: slice): (slice?, slice?, bool)
308
+ asm(pivot self keyLen -> 1 0 2) "DICTGETPREV" "NULLSWAPIFNOT2"
309
+
293
310
@pure
294
311
fun dict.iDictGetPrevOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool)
295
312
asm(pivot self keyLen -> 1 0 2) "DICTIGETPREVEQ" "NULLSWAPIFNOT2"
@@ -298,9 +315,13 @@ fun dict.iDictGetPrevOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool
298
315
fun dict.uDictGetPrevOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool)
299
316
asm(pivot self keyLen -> 1 0 2) "DICTUGETPREVEQ" "NULLSWAPIFNOT2"
300
317
318
+ @pure
319
+ fun dict.sDictGetPrevOrEqual(self, keyLen: int, pivot: slice): (slice?, slice?, bool)
320
+ asm(pivot self keyLen -> 1 0 2) "DICTGETPREVEQ" "NULLSWAPIFNOT2"
321
+
301
322
302
323
/**
303
- Prefix dictionary primitives.
324
+ Prefix dictionary primitives.
304
325
*/
305
326
306
327
@pure
0 commit comments