mercredi 1 mars 2017

Merge hashtables with unique keys into one C++

How to merge different std::unordered_map into one? Given that all the keys are unique?

For ex:

    std::unordered_map<uint64_t, uint64_t> h1, h2, h3, h4;
    h1.insert({5, 1});
    h1.insert({120, 2});
    h2.insert({7, 4});
    h4.insert({199,1})

std::unordered_map<uint64_t, uint64_t> h5;

Is there a to push all the KeyValue pairs from h1, h2, h3, h4 into the unordered_map h5 in O(1) operation Or Without resorting to hashing all the keys again.

It need not be std::unordered_map only. Any incarnation of hashtable in C++14 would be fine. That provides O(1) insert and query.

Aucun commentaire:

Enregistrer un commentaire