Skip to content

Commit

Permalink
Using robin_hood unordered_map and unordered_set
Browse files Browse the repository at this point in the history
  • Loading branch information
programLyrique committed Dec 20, 2021
1 parent be50f98 commit e5d3848
Show file tree
Hide file tree
Showing 7 changed files with 2,563 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/default_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ std::pair<const sexp_hash*, bool> DefaultStore::add_value(SEXP val) {
debug_counters_t d_counters;
d_counters.n_maybe_shared = maybe_shared(val);
d_counters.n_sexp_address_opt = sexp_address_optim;
debug_counters.insert(std::make_pair(*key, d_counters));
debug_counters.insert({*key, d_counters});
}
#endif

Expand All @@ -196,7 +196,7 @@ std::pair<const sexp_hash*, bool> DefaultStore::add_value(SEXP val) {
store_file.write(reinterpret_cast<const char*>(buf->data()), buf->size());

// add it to the index (only if writing the value did not fail)
auto res = index.insert(std::make_pair(*key, write_pos));
auto res = index.insert({*key, write_pos});
assert(res.second); //insertion should have take place; otherwise, it means there is a collision with XXH128

// new value in that session
Expand Down
9 changes: 5 additions & 4 deletions src/default_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "serialization.h"
#include "hasher.h"
#include "source_ref.h"
#include "robin_hood.h"

#include <fstream>
#include <unordered_map>
Expand All @@ -28,9 +29,9 @@ class DefaultStore : public Store {

// it means that the order in the hash map won't necessary be the order of offsets
// it that bad because of data locality?
std::unordered_map<sexp_hash, uint64_t, xxh128_hasher> index;
robin_hood::unordered_map<sexp_hash, uint64_t, xxh128_hasher> index;
// new during that session or not
std::unordered_map<sexp_hash, bool, xxh128_hasher> newly_seen;
robin_hood::unordered_map<sexp_hash, bool, xxh128_hasher> newly_seen;

size_t bytes_read;

Expand All @@ -41,7 +42,7 @@ class DefaultStore : public Store {
// Optimization
// we store the hash of the addresses of the sexp during a session
// also involves setting the tracing bit
mutable std::unordered_map<SEXP, sexp_hash> sexp_adresses;
mutable robin_hood::unordered_map<SEXP, sexp_hash> sexp_adresses;

pid_t pid;

Expand All @@ -67,7 +68,7 @@ class DefaultStore : public Store {
uint64_t n_maybe_shared = 0;// how many times MAYBE_SHARED(val) has been true on a SEXP that was being added
uint64_t n_sexp_address_opt = 0;// how many times we have been able to use the SEXP address optimization
};
std::unordered_map<sexp_hash, debug_counters_t, xxh128_hasher> debug_counters;
robin_hood::unordered_map<sexp_hash, debug_counters_t, xxh128_hasher> debug_counters;
#endif

public:
Expand Down
2 changes: 1 addition & 1 deletion src/generic_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GenericStore : public DefaultStore {
std::chrono::nanoseconds next_seen_dur;
#endif
};
std::unordered_map<sexp_hash, metadata_t, xxh128_hasher> metadata;
robin_hood::unordered_map<sexp_hash, metadata_t, xxh128_hasher> metadata;
std::shared_ptr<SourceRefs> src_locs;

protected:
Expand Down
3 changes: 2 additions & 1 deletion src/global_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "default_store.h"
#include "generic_store.h"
#include "source_ref.h"
#include "robin_hood.h"

#include <vector>
#include <memory>
Expand All @@ -20,7 +21,7 @@ class GlobalStore : Store {

// to preserve the order
std::vector<std::unique_ptr<GenericStore>> stores;
std::unordered_map<std::string, uint64_t> types;
robin_hood::unordered_map<std::string, uint64_t> types;


size_t bytes_read;
Expand Down
Loading

0 comments on commit e5d3848

Please sign in to comment.