1

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?

6
  • Can you elaborate use case of this? If you try storing a large map to a row of multi_index table, it wouldn't be a good idea.
    – conr2d
    Apr 20 '20 at 6:20
  • @conr2d Why do you assume that I try storing a large map to a row of multi_index table? I just want a large map from 256 bit integers to values. Anyway, I stopped this project.
    – porton
    Apr 20 '20 at 22:59
  • Because storing data in a row is cheaper than adding new rows to multi_index. Every multi_index row costs additional RAM for indexing.
    – conr2d
    Apr 21 '20 at 4:02
  • What is "storing data in a row"? Which row?
    – porton
    Apr 27 '20 at 3:15
  • A row of eosio::multi_index. Won't you store instantiated map into persistent state? If you won't, forget about my answer.
    – conr2d
    Apr 27 '20 at 5:21
1

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.

2
  • So, you mean 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?
    – porton
    Apr 29 '20 at 16:03
  • Hmm, it seems you don't have much experience in EOS. eosio::multi_index is a handler of table. If it is just one object, why do you call 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.
    – conr2d
    Apr 30 '20 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.