Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
In FunC, is there an equivalent to Solidity's mapping?

I have a smart contract that accepts messages from users. I would like to keep a history of requests. How can I save a list of pairs (address, text of the message)? Do I understand correctly that I cannot use tuple for such a case because it has a limit of 256 entries? Are there any best practices for storing such a dynamic list? Similar to a mapping in Solidity.


This question was imported from Telegram Chat: https://t.me/tondev_eng/9905

Votes Newest

Answers


Dicts

Dicts can be used to store a map of keys to values. However, in TON, it's recommended to avoid storing unbounded dicts. That is dicts that grow dynamically as time passes. The use case that you described is a dynamic one. The reason to avoid it is that your storage grows, and as it grows you have to pay more and more to keep it on the blockchain.

To store a dynamic list, you have to break it into smaller parts. This is called sharding, and you can find more info about how to do it in this great article:

https://blog.ton.org/how-to-shard-your-ton-smart-contract-and-why-studying-the-anatomy-of-tons-jettons

Tuples

Tuples are limited to 256 entries, but you can use them as an unlimited ML-style list. That means to store the first element as the first tuple element, and the rest of the list in another tuple as the second element, and again use this same structure for the rest of the list until the end which is usually a null value:

(1, (2, (3, null())))

But in FunC (and TON in general), this is only useful for working with data in memory, since when you want to store it, you have to serialize it to a Cell.

1
1
Posted one year ago