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.
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?