From eb83ba26e166fe3df71691f3aa9fa40b693df579 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Tue, 18 Apr 2017 22:45:37 -0700 Subject: [PATCH] Add sparsepp as a replacement for sparsehash --- .gitmodules | 3 +++ src/query.cc | 11 ++++++----- src/query.h | 16 ++++++++++------ third_party/sparsepp | 1 + 4 files changed, 20 insertions(+), 11 deletions(-) create mode 160000 third_party/sparsepp diff --git a/.gitmodules b/.gitmodules index 8dd505f9..f20df4e9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/src/query.cc b/src/query.cc index b1f856da..6f6b7aba 100644 --- a/src/query.cc +++ b/src/query.cc @@ -72,8 +72,9 @@ void AddMergeableRange( // time at the cost of some additional memory. // Build lookup table. - google::dense_hash_map> id_to_index; - id_to_index.set_empty_key(TId(-1)); + //google::dense_hash_map> id_to_index; + //id_to_index.set_empty_key(TId(-1)); + spp::sparse_hash_map 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); diff --git a/src/query.h b/src/query.h index 9b8ccaac..23e3e618 100644 --- a/src/query.h +++ b/src/query.h @@ -3,7 +3,7 @@ #include "indexer.h" #include "serializer.h" -#include +#include #include @@ -257,10 +257,11 @@ struct QueryDatabase { std::vector vars; // Lookup symbol based on a usr. - google::dense_hash_map usr_to_symbol; + spp::sparse_hash_map usr_to_symbol; + //google::dense_hash_map usr_to_symbol; QueryDatabase() { - usr_to_symbol.set_empty_key(""); + //usr_to_symbol.set_empty_key(""); } //std::unordered_map usr_to_symbol; @@ -310,7 +311,10 @@ struct IdMap { SymbolIdx ToSymbol(IndexFuncId id) const; SymbolIdx ToSymbol(IndexVarId id) const; private: - google::dense_hash_map> cached_type_ids_; - google::dense_hash_map> cached_func_ids_; - google::dense_hash_map> cached_var_ids_; + spp::sparse_hash_map cached_type_ids_; + spp::sparse_hash_map cached_func_ids_; + spp::sparse_hash_map cached_var_ids_; + //google::dense_hash_map> cached_type_ids_; + //google::dense_hash_map> cached_func_ids_; + //google::dense_hash_map> cached_var_ids_; }; diff --git a/third_party/sparsepp b/third_party/sparsepp new file mode 160000 index 00000000..b1d54fbe --- /dev/null +++ b/third_party/sparsepp @@ -0,0 +1 @@ +Subproject commit b1d54fbe547cab3a13d181f16f1de758d6827f81