mirror of
https://github.com/typesense/typesense.git
synced 2025-05-23 23:30:42 +08:00
Refactor NumericTrie::search_equal_to
.
This commit is contained in:
parent
4635e5cebf
commit
4a19a15222
@ -186,16 +186,25 @@ void NumericTrie::search_less_than(const int32_t& value, const bool& inclusive,
|
||||
}
|
||||
|
||||
void NumericTrie::search_equal_to(const int32_t& value, uint32_t*& ids, uint32_t& ids_length) {
|
||||
uint32_t* match_ids = nullptr;
|
||||
uint32_t match_ids_length = 0;
|
||||
if (value < 0 && negative_trie != nullptr) {
|
||||
negative_trie->search_equal_to(std::abs(value), match_ids, match_ids_length);
|
||||
} else if (value >= 0 && positive_trie != nullptr) {
|
||||
positive_trie->search_equal_to(value, match_ids, match_ids_length);
|
||||
if ((value < 0 && negative_trie == nullptr) || (value >= 0 && positive_trie == nullptr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ids = match_ids;
|
||||
ids_length = match_ids_length;
|
||||
uint32_t* equal_ids = nullptr;
|
||||
uint32_t equal_ids_length = 0;
|
||||
|
||||
if (value < 0) {
|
||||
negative_trie->search_equal_to(std::abs(value), equal_ids, equal_ids_length);
|
||||
} else {
|
||||
positive_trie->search_equal_to(value, equal_ids, equal_ids_length);
|
||||
}
|
||||
|
||||
uint32_t* out = nullptr;
|
||||
ids_length = ArrayUtils::or_scalar(equal_ids, equal_ids_length, ids, ids_length, &out);
|
||||
|
||||
delete [] equal_ids;
|
||||
delete [] ids;
|
||||
ids = out;
|
||||
}
|
||||
|
||||
void NumericTrie::Node::insert(const int32_t& value, const uint32_t& seq_id) {
|
||||
|
@ -388,24 +388,23 @@ TEST_F(NumericRangeTrieTest, SearchEqualTo) {
|
||||
uint32_t ids_length = 0;
|
||||
|
||||
trie->search_equal_to(0, ids, ids_length);
|
||||
std::unique_ptr<uint32_t[]> ids_guard(ids);
|
||||
|
||||
ASSERT_EQ(0, ids_length);
|
||||
|
||||
reset(ids, ids_length);
|
||||
trie->search_equal_to(-32768, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
ASSERT_EQ(1, ids_length);
|
||||
ASSERT_EQ(43, ids[0]);
|
||||
|
||||
reset(ids, ids_length);
|
||||
trie->search_equal_to(24576, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
ASSERT_EQ(1, ids_length);
|
||||
ASSERT_EQ(58, ids[0]);
|
||||
|
||||
reset(ids, ids_length);
|
||||
trie->search_equal_to(0x202020, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
ASSERT_EQ(0, ids_length);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user