Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions be/test/olap/memory/hash_index_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ inline uint64_t HashCode(uint64_t v) {

TEST(HashIndex, findset) {
size_t sz = 20;
HashIndex hi(sz);
scoped_refptr<HashIndex> hi(new HashIndex(sz));
std::vector<uint32_t> entries;
entries.reserve(10);
// add all
for (size_t i = 0; i < sz * 2; i += 2) {
uint64_t keyHash = HashCode(i);
entries.clear();
uint64_t slot = hi.find(keyHash, &entries);
uint64_t slot = hi->find(keyHash, &entries);
bool found = false;
for (auto& e : entries) {
uint64_t keyHashVerify = HashCode(e);
Expand All @@ -53,13 +53,13 @@ TEST(HashIndex, findset) {
}
EXPECT_FALSE(found);
EXPECT_NE(slot, HashIndex::npos);
hi.set(slot, keyHash, i);
hi->set(slot, keyHash, i);
}
// search
for (size_t i = 0; i < sz * 2; i += 2) {
uint64_t keyHash = HashCode(i);
entries.clear();
hi.find(keyHash, &entries);
hi->find(keyHash, &entries);
uint64_t fslot = HashIndex::npos;
for (auto& e : entries) {
uint64_t keyHashVerify = HashCode(e);
Expand All @@ -73,24 +73,24 @@ TEST(HashIndex, findset) {
}
EXPECT_NE(fslot, HashIndex::npos);
}
LOG(INFO) << hi.dump();
LOG(INFO) << hi->dump();
}

TEST(HashIndex, add) {
srand(1);
size_t N = 1000;
HashIndex hi(N);
scoped_refptr<HashIndex> hi(new HashIndex(N));
std::vector<int64_t> keys(N);
for (size_t i = 0; i < N; ++i) {
keys[i] = rand();
uint64_t hashcode = HashCode(keys[i]);
EXPECT_TRUE(hi.add(hashcode, i));
EXPECT_TRUE(hi->add(hashcode, i));
}
std::vector<uint32_t> entries;
entries.reserve(10);
for (size_t i = 0; i < N; ++i) {
uint64_t hashcode = HashCode(keys[i]);
hi.find(hashcode, &entries);
hi->find(hashcode, &entries);
bool found = false;
for (size_t ei = 0; ei < entries.size(); ++ei) {
int64_t v = keys[entries[ei]];
Expand All @@ -101,7 +101,7 @@ TEST(HashIndex, add) {
}
EXPECT_TRUE(found);
}
LOG(INFO) << hi.dump();
LOG(INFO) << hi->dump();
}

} // namespace memory
Expand Down