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
Efficiently storing Up to 4 million bits in a TON smart contract

I'm working on a TON smart contract that may need to store up to 4 million bits. I understand from the TON documentation that this isn't typically recommended, but I'm exploring the possibility for extreme cases.

Given that a cell can hold up to 1023 bits, I'd need roughly 4 million / 1023 ≈ 4000 cells to store all the bits.

My initial idea is to employ a data structure that uses a dictionary. This dictionary would have up to 4,000 keys, with each key mapping to a cell containing 1023 bits.

Another approach I'm considering is leveraging the fact that a cell can reference up to four other cells. So, starting with four reference cells in my contract, I could keep expanding the depth of each cell hierarchy to store the full 4 million bits.

In most scenarios, my contract will likely use no more than 10,000 bits. But I want to be prepared for cases where it could expand to the full 4 million bits. Considering that, once stored, the data will mostly be accessed for reading (rather than frequent updates), what would be the most efficient way to structure the storage?

Posted 10 months ago
Votes Newest


Strictly speaking, finding the most efficient way to structure storage is NP-class task meaning that it will require too much resources given the amount of bits.
Dictionaries are binary trees (up to 2 branches in cell), though reading and updating them is actually cheaper than quadro-trees. So I'd recommend using dicts.

Posted 10 months ago