diff --git a/include/index.h b/include/index.h index e179f271..38c02238 100644 --- a/include/index.h +++ b/include/index.h @@ -307,8 +307,6 @@ private: spp::sparse_hash_map geo_range_index; -// spp::sparse_hash_map>*> geopoint_index; - // geo_array_field => (seq_id => values) used for exact filtering of geo array records spp::sparse_hash_map*> geo_array_index; diff --git a/src/index.cpp b/src/index.cpp index 6a5a642e..cf5ec95a 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -78,7 +78,7 @@ Index::Index(const std::string& name, const uint32_t collection_id, const Store* art_tree_init(t); search_index.emplace(a_field.name, t); } else if(a_field.is_geopoint()) { - geo_range_index.emplace(a_field.name, new NumericTrie(64)); + geo_range_index.emplace(a_field.name, new NumericTrie()); if(!a_field.is_single_geopoint()) { spp::sparse_hash_map * doc_to_geos = new spp::sparse_hash_map(); @@ -5630,7 +5630,7 @@ void Index::refresh_schemas(const std::vector& new_fields, const std::vec art_tree_init(t); search_index.emplace(new_field.name, t); } else if(new_field.is_geopoint()) { - geo_range_index.emplace(new_field.name, new NumericTrie(64)); + geo_range_index.emplace(new_field.name, new NumericTrie()); if(!new_field.is_single_geopoint()) { auto geo_array_map = new spp::sparse_hash_map(); geo_array_index.emplace(new_field.name, geo_array_map); diff --git a/src/numeric_range_trie.cpp b/src/numeric_range_trie.cpp index 71970894..7ac88590 100644 --- a/src/numeric_range_trie.cpp +++ b/src/numeric_range_trie.cpp @@ -415,8 +415,9 @@ inline int get_index(const int64_t& value, const char& level, const char& max_le return (value >> (8 * (max_level - level))) & 0xFF; } -inline int get_geopoint_index(const uint64_t& cell_id, const char& level, const char& max_level) { - return (cell_id >> (8 * (max_level - level))) & 0xFF; +inline int get_geopoint_index(const uint64_t& cell_id, const char& level) { + // Doing 8-level since cell_id is a 64 bit number. + return (cell_id >> (8 * (8 - level))) & 0xFF; } void NumericTrie::Node::insert_helper(const int64_t& value, const uint32_t& seq_id, char& level, const char& max_level) { @@ -459,7 +460,7 @@ void NumericTrie::Node::insert_geopoint_helper(const uint64_t& cell_id, const ui children = new NumericTrie::Node* [EXPANSE]{nullptr}; } - auto index = get_geopoint_index(cell_id, level, max_level); + auto index = get_geopoint_index(cell_id, level); if (children[index] == nullptr) { children[index] = new NumericTrie::Node(); } @@ -472,7 +473,7 @@ char get_max_search_level(const uint64_t& cell_id, const char& max_level) { // For cell id 0x47E66C3000000000, we only have to prefix match the top four bytes since rest of the bytes are 0. // So the max search level would be 4 in this case. - uint64_t mask = 0xff; + auto mask = (uint64_t) 0xFF << (8 * (8 - max_level)); // We're only indexing top 8-max_level bytes. char i = max_level; while (((cell_id & mask) == 0) && --i > 0) { mask <<= 8; @@ -485,7 +486,7 @@ void NumericTrie::Node::search_geopoints_helper(const uint64_t& cell_id, const c std::set& matches) { char level = 1; Node* root = this; - auto index = get_geopoint_index(cell_id, level, max_index_level); + auto index = get_geopoint_index(cell_id, level); auto max_search_level = get_max_search_level(cell_id, max_index_level); while (level < max_search_level) { @@ -494,7 +495,7 @@ void NumericTrie::Node::search_geopoints_helper(const uint64_t& cell_id, const c } root = root->children[index]; - index = get_geopoint_index(cell_id, ++level, max_index_level); + index = get_geopoint_index(cell_id, ++level); } matches.insert(root); @@ -523,7 +524,7 @@ void NumericTrie::Node::search_geopoints(const std::vector& cell_ids, void NumericTrie::Node::delete_geopoint(const uint64_t& cell_id, uint32_t id, const char& max_level) { char level = 1; Node* root = this; - auto index = get_geopoint_index(cell_id, level, max_level); + auto index = get_geopoint_index(cell_id, level); while (level < max_level) { root->seq_ids.remove_value(id); @@ -533,9 +534,10 @@ void NumericTrie::Node::delete_geopoint(const uint64_t& cell_id, uint32_t id, co } root = root->children[index]; - index = get_geopoint_index(cell_id, ++level, max_level); + index = get_geopoint_index(cell_id, ++level); } + root->seq_ids.remove_value(id); if (root->children != nullptr || root->children[index] != nullptr) { delete root->children[index]; root->children[index] = nullptr;