What is the way to create a map from 256 bit integers to values?
Is it std::map<>
? or will std::map<>
become slow as the data grows? If it is slow, what is faster?
EOS.IO Stack Exchange is a question and answer site for users and developers of distributed applications built on top of the blockchain operating system, EOS.IO. It only takes a minute to sign up.
Sign up to join this communityWhat is the way to create a map from 256 bit integers to values?
Is it std::map<>
? or will std::map<>
become slow as the data grows? If it is slow, what is faster?
My answer is too long to fit in comment, so leave here.
I came to know we are using different terms, but saying same things. eosio::multi_index is a table and you can add items (I called these 'rows'), but you said that you will make only one object. Then your code will be like this:
struct other {
...
};
struct [[eosio::table]] some {
uint64_t id;
std::map<checksum256,other> others; // checksum256 for 256-bit integer key
uint64_t primary_key() const { return id; }
};
typedef eosio::multi_index<"some"_n, some> some_index;
If I understand you correctly, you will save all data into map (others
above) in one row, not add multiple rows to multi_index. That is very inefficient when you save many data into one map. All data in that map need to be copied from internal db whenever you access this map.
struct [[eosio::table]] other {
uint64_t id;
checksum256 key;
...
uint64_t primary_key() const { return id; }
checksum256 secondary_key() const { return key; }
};
typedef eosio::multi_index<"other"_n,other,
indexed_by<"secondary"_n, const_mem_fun<other, checksum256, &other::secondary_key>
> other_index;
The second example I attached shows a better way to save data with 256-bit integer key in eosio.
eosio::multi_index
is more efficient than std::map
? I don't understand why you refer to one row vs multiple rows, when eosio::multi_index
is also one object (as you call it one row) just like std::map
. Why do you call std::map
one row but eosio::multi_index
multiple rows?
find()
to get specific object from it. Every field you declare works like column in DB table, every object you emplace()
into multi_index works like row. BTW, all variables declared during transaction execution are freed after execution ends (not saved in persistent area), but the only data stored though multi_index will be preserved.