This repository has been archived by the owner on Dec 26, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
overflow fix: rehash with different hash instead (#121)
This uses a pretty nice idea to rehash with a different hash whenever the info byte would cause an overflow, and also improves hash quality when a bad hash is used. * The murmur finalizer is split up into 2 parts, the final part (one multiplication and one xor&shift) is *always* done, regardless of the hash used. That way the robin_hood hash is murmur's fmix, and all other hashes have an addition mixer to improve its quality. * The additional mixer uses a member variable for the multiplication constant. When an overflow is encountered, that constant is changed, thus the rehash will spread the elements completely differently. * Rehashing is tried multiple times (up to 256 times), so we won't get an endless loop if this rehashing still does not work.
- Loading branch information
Showing
5 changed files
with
122 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <app/doctest.h> | ||
#include <robin_hood.h> | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <map> | ||
|
||
// Loads the file "test-data-new.txt" and processes it | ||
TEST_CASE("playback" * doctest::skip()) { | ||
auto sets = std::map<size_t, robin_hood::unordered_flat_set<int32_t>>(); | ||
|
||
auto fin = std::fstream("../test-data-3.txt"); | ||
auto line = std::string(); | ||
|
||
auto prefix = std::string(); | ||
auto id = size_t(); | ||
auto command = std::string(); | ||
auto lineNr = 0; | ||
try { | ||
while (fin >> prefix >> id >> command) { | ||
++lineNr; | ||
|
||
// std::cout << prefix << " " << id << " " << command << " "; | ||
if (command == "insert") { | ||
auto number = int32_t(); | ||
fin >> number; | ||
// std::cout << number << std::endl; | ||
sets[id].insert(number); | ||
} else if (command == "construct") { | ||
// std::cout << std::endl; | ||
sets[id]; | ||
} else if (command == "move_construct") { | ||
auto idMoved = size_t(); | ||
fin >> idMoved; | ||
// std::cout << idMoved << std::endl; | ||
sets[id] = std::move(sets[idMoved]); | ||
} else if (command == "destroy") { | ||
// std::cout << std::endl; | ||
sets.erase(id); | ||
} else if (command == "clear") { | ||
// std::cout << std::endl; | ||
sets[id].clear(); | ||
} else { | ||
throw std::runtime_error(command); | ||
} | ||
} | ||
} catch (...) { | ||
std::cout << "line " << lineNr << std::endl; | ||
throw; | ||
} | ||
} |