Add sparsepp as a replacement for sparsehash

This commit is contained in:
Jacob Dufault 2017-04-18 22:45:37 -07:00
parent cd50eb9e35
commit eb83ba26e1
4 changed files with 20 additions and 11 deletions

3
.gitmodules vendored
View File

@ -7,3 +7,6 @@
[submodule "third_party/sparsehash"]
path = third_party/sparsehash
url = https://github.com/sparsehash/sparsehash
[submodule "third_party/sparsepp"]
path = third_party/sparsepp
url = https://github.com/greg7mdp/sparsepp

View File

@ -72,8 +72,9 @@ void AddMergeableRange(
// time at the cost of some additional memory.
// Build lookup table.
google::dense_hash_map<TId, size_t, std::hash<TId>> id_to_index;
id_to_index.set_empty_key(TId(-1));
//google::dense_hash_map<TId, size_t, std::hash<TId>> id_to_index;
//id_to_index.set_empty_key(TId(-1));
spp::sparse_hash_map<TId, size_t> id_to_index;
id_to_index.resize(dest->size());
for (size_t i = 0; i < dest->size(); ++i)
id_to_index[(*dest)[i].id] = i;
@ -356,17 +357,17 @@ IdMap::IdMap(QueryDatabase* query_db, const IdCache& local_ids)
: local_ids(local_ids) {
primary_file = GetQueryFileIdFromPath(query_db, local_ids.primary_file);
cached_type_ids_.set_empty_key(IndexTypeId(-1));
//cached_type_ids_.set_empty_key(IndexTypeId(-1));
cached_type_ids_.resize(local_ids.type_id_to_usr.size());
for (const auto& entry : local_ids.type_id_to_usr)
cached_type_ids_[entry.first] = GetQueryTypeIdFromUsr(query_db, entry.second);
cached_func_ids_.set_empty_key(IndexFuncId(-1));
//cached_func_ids_.set_empty_key(IndexFuncId(-1));
cached_func_ids_.resize(local_ids.func_id_to_usr.size());
for (const auto& entry : local_ids.func_id_to_usr)
cached_func_ids_[entry.first] = GetQueryFuncIdFromUsr(query_db, entry.second);
cached_var_ids_.set_empty_key(IndexVarId(-1));
//cached_var_ids_.set_empty_key(IndexVarId(-1));
cached_var_ids_.resize(local_ids.var_id_to_usr.size());
for (const auto& entry : local_ids.var_id_to_usr)
cached_var_ids_[entry.first] = GetQueryVarIdFromUsr(query_db, entry.second);

View File

@ -3,7 +3,7 @@
#include "indexer.h"
#include "serializer.h"
#include <sparsehash/dense_hash_map>
#include <sparsepp/spp.h>
#include <functional>
@ -257,10 +257,11 @@ struct QueryDatabase {
std::vector<QueryVar> vars;
// Lookup symbol based on a usr.
google::dense_hash_map<Usr, SymbolIdx> usr_to_symbol;
spp::sparse_hash_map<Usr, SymbolIdx> usr_to_symbol;
//google::dense_hash_map<Usr, SymbolIdx> usr_to_symbol;
QueryDatabase() {
usr_to_symbol.set_empty_key("");
//usr_to_symbol.set_empty_key("");
}
//std::unordered_map<Usr, SymbolIdx> usr_to_symbol;
@ -310,7 +311,10 @@ struct IdMap {
SymbolIdx ToSymbol(IndexFuncId id) const;
SymbolIdx ToSymbol(IndexVarId id) const;
private:
google::dense_hash_map<IndexTypeId, QueryTypeId, std::hash<IndexTypeId>> cached_type_ids_;
google::dense_hash_map<IndexFuncId, QueryFuncId, std::hash<IndexFuncId>> cached_func_ids_;
google::dense_hash_map<IndexVarId, QueryVarId, std::hash<IndexVarId>> cached_var_ids_;
spp::sparse_hash_map<IndexTypeId, QueryTypeId> cached_type_ids_;
spp::sparse_hash_map<IndexFuncId, QueryFuncId> cached_func_ids_;
spp::sparse_hash_map<IndexVarId, QueryVarId> cached_var_ids_;
//google::dense_hash_map<IndexTypeId, QueryTypeId, std::hash<IndexTypeId>> cached_type_ids_;
//google::dense_hash_map<IndexFuncId, QueryFuncId, std::hash<IndexFuncId>> cached_func_ids_;
//google::dense_hash_map<IndexVarId, QueryVarId, std::hash<IndexVarId>> cached_var_ids_;
};

1
third_party/sparsepp vendored Submodule

@ -0,0 +1 @@
Subproject commit b1d54fbe547cab3a13d181f16f1de758d6827f81