Rename methods.

This commit is contained in:
Harpreet Sangar 2023-05-31 13:57:18 +05:30
parent 4e240cfb14
commit 3c0f597b52
3 changed files with 56 additions and 56 deletions

View File

@ -15,9 +15,9 @@ class NumericTrie {
void search_range_helper(const int32_t& low,const int32_t& high, std::vector<Node*>& matches);
void search_lesser_helper(const int32_t& value, char& level, std::vector<Node*>& matches);
void search_less_than_helper(const int32_t& value, char& level, std::vector<Node*>& matches);
void search_greater_helper(const int32_t& value, char& level, std::vector<Node*>& matches);
void search_greater_than_helper(const int32_t& value, char& level, std::vector<Node*>& matches);
public:
@ -38,9 +38,9 @@ class NumericTrie {
void search_range(const int32_t& low, const int32_t& high,
uint32_t*& ids, uint32_t& ids_length);
void search_lesser(const int32_t& value, uint32_t*& ids, uint32_t& ids_length);
void search_less_than(const int32_t& value, uint32_t*& ids, uint32_t& ids_length);
void search_greater(const int32_t& value, uint32_t*& ids, uint32_t& ids_length);
void search_greater_than(const int32_t& value, uint32_t*& ids, uint32_t& ids_length);
};
Node* negative_trie = nullptr;
@ -59,9 +59,9 @@ public:
const int32_t& high, const bool& high_inclusive,
uint32_t*& ids, uint32_t& ids_length);
void search_lesser(const int32_t& value, const bool& inclusive,
uint32_t*& ids, uint32_t& ids_length);
void search_less_than(const int32_t& value, const bool& inclusive,
uint32_t*& ids, uint32_t& ids_length);
void search_greater(const int32_t& value, const bool& inclusive,
uint32_t*& ids, uint32_t& ids_length);
void search_greater_than(const int32_t& value, const bool& inclusive,
uint32_t*& ids, uint32_t& ids_length);
};

View File

@ -32,13 +32,13 @@ void NumericTrie::search_range(const int32_t& low, const bool& low_inclusive,
if (negative_trie != nullptr && !(low == -1 && !low_inclusive)) { // No need to search for (-1, ...
auto abs_low = std::abs(low);
// Since we store absolute values, search_lesser would yield result for >low from negative_trie.
negative_trie->search_lesser(low_inclusive ? abs_low : abs_low - 1, negative_ids, negative_ids_length);
negative_trie->search_less_than(low_inclusive ? abs_low : abs_low - 1, negative_ids, negative_ids_length);
}
uint32_t* positive_ids = nullptr;
uint32_t positive_ids_length = 0;
if (positive_trie != nullptr && !(high == 0 && !high_inclusive)) { // No need to search for ..., 0)
positive_trie->search_lesser(high_inclusive ? high : high - 1, positive_ids, positive_ids_length);
positive_trie->search_less_than(high_inclusive ? high : high - 1, positive_ids, positive_ids_length);
}
ids_length = ArrayUtils::or_scalar(negative_ids, negative_ids_length, positive_ids, positive_ids_length, &ids);
@ -75,7 +75,7 @@ void NumericTrie::search_range(const int32_t& low, const bool& low_inclusive,
}
}
void NumericTrie::search_greater(const int32_t& value, const bool& inclusive, uint32_t*& ids, uint32_t& ids_length) {
void NumericTrie::search_greater_than(const int32_t& value, const bool& inclusive, uint32_t*& ids, uint32_t& ids_length) {
if ((value == 0 && inclusive) || (value == -1 && !inclusive)) { // [0, ∞), (-1, ∞)
if (positive_trie != nullptr) {
positive_trie->get_all_ids(ids, ids_length);
@ -87,7 +87,7 @@ void NumericTrie::search_greater(const int32_t& value, const bool& inclusive, ui
uint32_t* positive_ids = nullptr;
uint32_t positive_ids_length = 0;
if (positive_trie != nullptr) {
positive_trie->search_greater(inclusive ? value : value + 1, positive_ids, positive_ids_length);
positive_trie->search_greater_than(inclusive ? value : value + 1, positive_ids, positive_ids_length);
}
ids_length = positive_ids_length;
@ -100,7 +100,7 @@ void NumericTrie::search_greater(const int32_t& value, const bool& inclusive, ui
// Since we store absolute values, search_lesser would yield result for >value from negative_trie.
if (negative_trie != nullptr) {
auto abs_low = std::abs(value);
negative_trie->search_lesser(inclusive ? abs_low : abs_low - 1, negative_ids, negative_ids_length);
negative_trie->search_less_than(inclusive ? abs_low : abs_low - 1, negative_ids, negative_ids_length);
}
uint32_t* positive_ids = nullptr;
@ -117,7 +117,7 @@ void NumericTrie::search_greater(const int32_t& value, const bool& inclusive, ui
}
}
void NumericTrie::search_lesser(const int32_t& value, const bool& inclusive, uint32_t*& ids, uint32_t& ids_length) {
void NumericTrie::search_less_than(const int32_t& value, const bool& inclusive, uint32_t*& ids, uint32_t& ids_length) {
if ((value == 0 && !inclusive) || (value == -1 && inclusive)) { // (-∞, 0), (-∞, -1]
if (negative_trie != nullptr) {
negative_trie->get_all_ids(ids, ids_length);
@ -131,7 +131,7 @@ void NumericTrie::search_lesser(const int32_t& value, const bool& inclusive, uin
// Since we store absolute values, search_greater would yield result for <value from negative_trie.
if (negative_trie != nullptr) {
auto abs_low = std::abs(value);
negative_trie->search_greater(inclusive ? abs_low : abs_low + 1, negative_ids, negative_ids_length);
negative_trie->search_greater_than(inclusive ? abs_low : abs_low + 1, negative_ids, negative_ids_length);
}
ids_length = negative_ids_length;
@ -142,7 +142,7 @@ void NumericTrie::search_lesser(const int32_t& value, const bool& inclusive, uin
uint32_t* positive_ids = nullptr;
uint32_t positive_ids_length = 0;
if (positive_trie != nullptr) {
positive_trie->search_lesser(inclusive ? value : value - 1, positive_ids, positive_ids_length);
positive_trie->search_less_than(inclusive ? value : value - 1, positive_ids, positive_ids_length);
}
uint32_t* negative_ids = nullptr;
@ -204,10 +204,10 @@ void NumericTrie::Node::get_all_ids(uint32_t*& ids, uint32_t& ids_length) {
ids_length = seq_ids.getLength();
}
void NumericTrie::Node::search_lesser(const int32_t& value, uint32_t*& ids, uint32_t& ids_length) {
void NumericTrie::Node::search_less_than(const int32_t& value, uint32_t*& ids, uint32_t& ids_length) {
char level = 0;
std::vector<NumericTrie::Node*> matches;
search_lesser_helper(value, level, matches);
search_less_than_helper(value, level, matches);
for (auto const& match: matches) {
uint32_t* out = nullptr;
@ -220,7 +220,7 @@ void NumericTrie::Node::search_lesser(const int32_t& value, uint32_t*& ids, uint
}
}
void NumericTrie::Node::search_lesser_helper(const int32_t& value, char& level, std::vector<NumericTrie::Node*>& matches) {
void NumericTrie::Node::search_less_than_helper(const int32_t& value, char& level, std::vector<NumericTrie::Node*>& matches) {
if (level == MAX_LEVEL) {
matches.push_back(this);
return;
@ -230,7 +230,7 @@ void NumericTrie::Node::search_lesser_helper(const int32_t& value, char& level,
auto index = get_index(value, ++level);
if (children[index] != nullptr) {
children[index]->search_lesser_helper(value, level, matches);
children[index]->search_less_than_helper(value, level, matches);
}
while (--index >= 0) {
@ -291,7 +291,7 @@ void NumericTrie::Node::search_range_helper(const int32_t& low, const int32_t& h
if (root->children[low_index] != nullptr) {
// Collect all the sub-nodes that are greater than low.
root->children[low_index]->search_greater_helper(low, level, matches);
root->children[low_index]->search_greater_than_helper(low, level, matches);
}
auto index = low_index + 1;
@ -306,14 +306,14 @@ void NumericTrie::Node::search_range_helper(const int32_t& low, const int32_t& h
if (index < EXPANSE && index == high_index && root->children[index] != nullptr) {
// Collect all the sub-nodes that are lesser than high.
root->children[index]->search_lesser_helper(high, level, matches);
root->children[index]->search_less_than_helper(high, level, matches);
}
}
void NumericTrie::Node::search_greater(const int32_t& value, uint32_t*& ids, uint32_t& ids_length) {
void NumericTrie::Node::search_greater_than(const int32_t& value, uint32_t*& ids, uint32_t& ids_length) {
char level = 0;
std::vector<NumericTrie::Node*> matches;
search_greater_helper(value, level, matches);
search_greater_than_helper(value, level, matches);
for (auto const& match: matches) {
uint32_t* out = nullptr;
@ -326,7 +326,7 @@ void NumericTrie::Node::search_greater(const int32_t& value, uint32_t*& ids, uin
}
}
void NumericTrie::Node::search_greater_helper(const int32_t& value, char& level, std::vector<NumericTrie::Node*>& matches) {
void NumericTrie::Node::search_greater_than_helper(const int32_t& value, char& level, std::vector<NumericTrie::Node*>& matches) {
if (level == MAX_LEVEL) {
matches.push_back(this);
return;
@ -336,7 +336,7 @@ void NumericTrie::Node::search_greater_helper(const int32_t& value, char& level,
auto index = get_index(value, ++level);
if (children[index] != nullptr) {
children[index]->search_greater_helper(value, level, matches);
children[index]->search_greater_than_helper(value, level, matches);
}
while (++index < EXPANSE) {

View File

@ -194,7 +194,7 @@ TEST_F(NumericRangeTrieTest, SearchGreater) {
uint32_t* ids = nullptr;
uint32_t ids_length = 0;
trie->search_greater(0, true, ids, ids_length);
trie->search_greater_than(0, true, ids, ids_length);
std::unique_ptr<uint32_t[]> ids_guard(ids);
ASSERT_EQ(4, ids_length);
@ -202,7 +202,7 @@ TEST_F(NumericRangeTrieTest, SearchGreater) {
ASSERT_EQ(pairs[i].second, ids[j]);
}
trie->search_greater(-1, false, ids, ids_length);
trie->search_greater_than(-1, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(4, ids_length);
@ -210,7 +210,7 @@ TEST_F(NumericRangeTrieTest, SearchGreater) {
ASSERT_EQ(pairs[i].second, ids[j]);
}
trie->search_greater(-1, true, ids, ids_length);
trie->search_greater_than(-1, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(4, ids_length);
@ -218,7 +218,7 @@ TEST_F(NumericRangeTrieTest, SearchGreater) {
ASSERT_EQ(pairs[i].second, ids[j]);
}
trie->search_greater(-24576, true, ids, ids_length);
trie->search_greater_than(-24576, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(7, ids_length);
@ -227,7 +227,7 @@ TEST_F(NumericRangeTrieTest, SearchGreater) {
ASSERT_EQ(pairs[i].second, ids[j++]);
}
trie->search_greater(-32768, false, ids, ids_length);
trie->search_greater_than(-32768, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(7, ids_length);
@ -236,7 +236,7 @@ TEST_F(NumericRangeTrieTest, SearchGreater) {
ASSERT_EQ(pairs[i].second, ids[j++]);
}
trie->search_greater(8192, true, ids, ids_length);
trie->search_greater_than(8192, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(4, ids_length);
@ -244,7 +244,7 @@ TEST_F(NumericRangeTrieTest, SearchGreater) {
ASSERT_EQ(pairs[i].second, ids[j]);
}
trie->search_greater(8192, false, ids, ids_length);
trie->search_greater_than(8192, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(3, ids_length);
@ -252,12 +252,12 @@ TEST_F(NumericRangeTrieTest, SearchGreater) {
ASSERT_EQ(pairs[i].second, ids[j]);
}
trie->search_greater(1000000, false, ids, ids_length);
trie->search_greater_than(1000000, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(0, ids_length);
trie->search_greater(-1000000, false, ids, ids_length);
trie->search_greater_than(-1000000, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(8, ids_length);
@ -287,7 +287,7 @@ TEST_F(NumericRangeTrieTest, SearchLesser) {
uint32_t* ids = nullptr;
uint32_t ids_length = 0;
trie->search_lesser(0, true, ids, ids_length);
trie->search_less_than(0, true, ids, ids_length);
std::unique_ptr<uint32_t[]> ids_guard(ids);
ASSERT_EQ(4, ids_length);
@ -295,7 +295,7 @@ TEST_F(NumericRangeTrieTest, SearchLesser) {
ASSERT_EQ(pairs[i].second, ids[j]);
}
trie->search_lesser(0, false, ids, ids_length);
trie->search_less_than(0, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(4, ids_length);
@ -303,7 +303,7 @@ TEST_F(NumericRangeTrieTest, SearchLesser) {
ASSERT_EQ(pairs[i].second, ids[i]);
}
trie->search_lesser(-1, true, ids, ids_length);
trie->search_less_than(-1, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(4, ids_length);
@ -311,7 +311,7 @@ TEST_F(NumericRangeTrieTest, SearchLesser) {
ASSERT_EQ(pairs[i].second, ids[i]);
}
trie->search_lesser(-16384, true, ids, ids_length);
trie->search_less_than(-16384, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(3, ids_length);
@ -319,7 +319,7 @@ TEST_F(NumericRangeTrieTest, SearchLesser) {
ASSERT_EQ(pairs[i].second, ids[i]);
}
trie->search_lesser(-16384, false, ids, ids_length);
trie->search_less_than(-16384, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(2, ids_length);
@ -327,7 +327,7 @@ TEST_F(NumericRangeTrieTest, SearchLesser) {
ASSERT_EQ(pairs[i].second, ids[i]);
}
trie->search_lesser(8192, true, ids, ids_length);
trie->search_less_than(8192, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(5, ids_length);
@ -335,7 +335,7 @@ TEST_F(NumericRangeTrieTest, SearchLesser) {
ASSERT_EQ(pairs[i].second, ids[i]);
}
trie->search_lesser(8192, false, ids, ids_length);
trie->search_less_than(8192, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(4, ids_length);
@ -343,12 +343,12 @@ TEST_F(NumericRangeTrieTest, SearchLesser) {
ASSERT_EQ(pairs[i].second, ids[i]);
}
trie->search_lesser(-1000000, false, ids, ids_length);
trie->search_less_than(-1000000, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(0, ids_length);
trie->search_lesser(1000000, true, ids, ids_length);
trie->search_less_than(1000000, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(8, ids_length);
@ -385,7 +385,7 @@ TEST_F(NumericRangeTrieTest, MultivalueData) {
uint32_t* ids = nullptr;
uint32_t ids_length = 0;
trie->search_lesser(0, false, ids, ids_length);
trie->search_less_than(0, false, ids, ids_length);
std::unique_ptr<uint32_t[]> ids_guard(ids);
std::vector<uint32_t> expected = {5, 8, 32, 35, 43};
@ -395,7 +395,7 @@ TEST_F(NumericRangeTrieTest, MultivalueData) {
ASSERT_EQ(expected[i], ids[i]);
}
trie->search_lesser(-16380, false, ids, ids_length);
trie->search_less_than(-16380, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(4, ids_length);
@ -405,7 +405,7 @@ TEST_F(NumericRangeTrieTest, MultivalueData) {
ASSERT_EQ(expected[i], ids[i]);
}
trie->search_lesser(16384, false, ids, ids_length);
trie->search_less_than(16384, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(7, ids_length);
@ -415,7 +415,7 @@ TEST_F(NumericRangeTrieTest, MultivalueData) {
ASSERT_EQ(expected[i], ids[i]);
}
trie->search_greater(0, true, ids, ids_length);
trie->search_greater_than(0, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(7, ids_length);
@ -425,7 +425,7 @@ TEST_F(NumericRangeTrieTest, MultivalueData) {
ASSERT_EQ(expected[i], ids[i]);
}
trie->search_greater(256, true, ids, ids_length);
trie->search_greater_than(256, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(5, ids_length);
@ -435,7 +435,7 @@ TEST_F(NumericRangeTrieTest, MultivalueData) {
ASSERT_EQ(expected[i], ids[i]);
}
trie->search_greater(-32768, true, ids, ids_length);
trie->search_greater_than(-32768, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(9, ids_length);
@ -478,32 +478,32 @@ TEST_F(NumericRangeTrieTest, EmptyTrieOperations) {
ASSERT_EQ(0, ids_length);
trie->search_greater(0, true, ids, ids_length);
trie->search_greater_than(0, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(0, ids_length);
trie->search_greater(15, true, ids, ids_length);
trie->search_greater_than(15, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(0, ids_length);
trie->search_greater(-15, true, ids, ids_length);
trie->search_greater_than(-15, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(0, ids_length);
trie->search_lesser(0, false, ids, ids_length);
trie->search_less_than(0, false, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(0, ids_length);
trie->search_lesser(-15, true, ids, ids_length);
trie->search_less_than(-15, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(0, ids_length);
trie->search_lesser(15, true, ids, ids_length);
trie->search_less_than(15, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(0, ids_length);