11// A part of standard library for Tolk
2- tolk 1.0
2+ tolk 1.1
33
44/**
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.
710 Most of functions are duplicated for three common cases:
811 - iDict* - dicts with signed integer keys
912 - uDict* - dicts with unsigned integer keys
@@ -14,10 +17,12 @@ tolk 1.0
1417 */
1518
1619/// In @stdlib/common.tolk, there is a type alias:
17- /// `type dict = cell?`
20+ /// ```
21+ /// type dict = cell?
22+ /// ```
1823/// For clarity, we use "dict" instead of a "cell?" where a cell-dictionary is assumed.
1924
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`
2126@pure
2227fun createEmptyDict(): dict
2328 asm "NEWDICT"
@@ -86,28 +91,28 @@ fun dict.uDictSetIfExists(mutate self, keyLen: int, key: int, value: slice): boo
8691
8792
8893@pure
89- fun dict.iDictGetRef(self, keyLen: int, key: int): (dict , bool)
94+ fun dict.iDictGetRef(self, keyLen: int, key: int): (cell? , bool)
9095 asm(key self keyLen) "DICTIGETREF" "NULLSWAPIFNOT"
9196
9297@pure
93- fun dict.uDictGetRef(self, keyLen: int, key: int): (dict , bool)
98+ fun dict.uDictGetRef(self, keyLen: int, key: int): (cell? , bool)
9499 asm(key self keyLen) "DICTUGETREF" "NULLSWAPIFNOT"
95100
96101@pure
97- fun dict.sDictGetRef(self, keyLen: int, key: slice): (dict , bool)
102+ fun dict.sDictGetRef(self, keyLen: int, key: slice): (cell? , bool)
98103 asm(key self keyLen) "DICTGETREF" "NULLSWAPIFNOT"
99104
100105
101106@pure
102- fun dict.iDictGetRefOrNull(self, keyLen: int, key: int): dict
107+ fun dict.iDictGetRefOrNull(self, keyLen: int, key: int): cell?
103108 asm(key self keyLen) "DICTIGETOPTREF"
104109
105110@pure
106- fun dict.uDictGetRefOrNull(self, keyLen: int, key: int): dict
111+ fun dict.uDictGetRefOrNull(self, keyLen: int, key: int): cell?
107112 asm(key self keyLen) "DICTUGETOPTREF"
108113
109114@pure
110- fun dict.sDictGetRefOrNull(self, keyLen: int, key: slice): dict
115+ fun dict.sDictGetRefOrNull(self, keyLen: int, key: slice): cell?
111116 asm(key self keyLen) "DICTGETOPTREF"
112117
113118
@@ -138,11 +143,11 @@ fun dict.sDictSetAndGet(mutate self, keyLen: int, key: slice, value: slice): (sl
138143
139144
140145@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?
142147 asm(value key self keyLen) "DICTISETGETOPTREF"
143148
144149@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?
146151 asm(value key self keyLen) "DICTUSETGETOPTREF"
147152
148153
@@ -228,15 +233,15 @@ fun dict.sDictGetFirst(self, keyLen: int): (slice?, slice?, bool)
228233 asm (-> 1 0 2) "DICTMIN" "NULLSWAPIFNOT2"
229234
230235@pure
231- fun dict.iDictGetFirstAsRef(self, keyLen: int): (int?, dict , bool)
236+ fun dict.iDictGetFirstAsRef(self, keyLen: int): (int?, cell? , bool)
232237 asm (-> 1 0 2) "DICTIMINREF" "NULLSWAPIFNOT2"
233238
234239@pure
235- fun dict.uDictGetFirstAsRef(self, keyLen: int): (int?, dict , bool)
240+ fun dict.uDictGetFirstAsRef(self, keyLen: int): (int?, cell? , bool)
236241 asm (-> 1 0 2) "DICTUMINREF" "NULLSWAPIFNOT2"
237242
238243@pure
239- fun dict.sDictGetFirstAsRef(self, keyLen: int): (slice?, dict , bool)
244+ fun dict.sDictGetFirstAsRef(self, keyLen: int): (slice?, cell? , bool)
240245 asm (-> 1 0 2) "DICTMINREF" "NULLSWAPIFNOT2"
241246
242247
@@ -253,15 +258,15 @@ fun dict.sDictGetLast(self, keyLen: int): (slice?, slice?, bool)
253258 asm (-> 1 0 2) "DICTMAX" "NULLSWAPIFNOT2"
254259
255260@pure
256- fun dict.iDictGetLastAsRef(self, keyLen: int): (int?, dict , bool)
261+ fun dict.iDictGetLastAsRef(self, keyLen: int): (int?, cell? , bool)
257262 asm (-> 1 0 2) "DICTIMAXREF" "NULLSWAPIFNOT2"
258263
259264@pure
260- fun dict.uDictGetLastAsRef(self, keyLen: int): (int?, dict , bool)
265+ fun dict.uDictGetLastAsRef(self, keyLen: int): (int?, cell? , bool)
261266 asm (-> 1 0 2) "DICTUMAXREF" "NULLSWAPIFNOT2"
262267
263268@pure
264- fun dict.sDictGetLastAsRef(self, keyLen: int): (slice?, dict , bool)
269+ fun dict.sDictGetLastAsRef(self, keyLen: int): (slice?, cell? , bool)
265270 asm (-> 1 0 2) "DICTMAXREF" "NULLSWAPIFNOT2"
266271
267272
@@ -273,6 +278,10 @@ fun dict.iDictGetNext(self, keyLen: int, pivot: int): (int?, slice?, bool)
273278fun dict.uDictGetNext(self, keyLen: int, pivot: int): (int?, slice?, bool)
274279 asm(pivot self keyLen -> 1 0 2) "DICTUGETNEXT" "NULLSWAPIFNOT2"
275280
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+
276285@pure
277286fun dict.iDictGetNextOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool)
278287 asm(pivot self keyLen -> 1 0 2) "DICTIGETNEXTEQ" "NULLSWAPIFNOT2"
@@ -281,6 +290,10 @@ fun dict.iDictGetNextOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool
281290fun dict.uDictGetNextOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool)
282291 asm(pivot self keyLen -> 1 0 2) "DICTUGETNEXTEQ" "NULLSWAPIFNOT2"
283292
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+
284297
285298@pure
286299fun 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)
290303fun dict.uDictGetPrev(self, keyLen: int, pivot: int): (int?, slice?, bool)
291304 asm(pivot self keyLen -> 1 0 2) "DICTUGETPREV" "NULLSWAPIFNOT2"
292305
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+
293310@pure
294311fun dict.iDictGetPrevOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool)
295312 asm(pivot self keyLen -> 1 0 2) "DICTIGETPREVEQ" "NULLSWAPIFNOT2"
@@ -298,9 +315,13 @@ fun dict.iDictGetPrevOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool
298315fun dict.uDictGetPrevOrEqual(self, keyLen: int, pivot: int): (int?, slice?, bool)
299316 asm(pivot self keyLen -> 1 0 2) "DICTUGETPREVEQ" "NULLSWAPIFNOT2"
300317
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+
301322
302323/**
303- Prefix dictionary primitives.
324+ Prefix dictionary primitives.
304325 */
305326
306327@pure
0 commit comments