diff --git a/be/test/olap/memory/hash_index_test.cpp b/be/test/olap/memory/hash_index_test.cpp index 8c861b6b44010a..a27b8999dda55c 100644 --- a/be/test/olap/memory/hash_index_test.cpp +++ b/be/test/olap/memory/hash_index_test.cpp @@ -32,14 +32,14 @@ inline uint64_t HashCode(uint64_t v) { TEST(HashIndex, findset) { size_t sz = 20; - HashIndex hi(sz); + scoped_refptr hi(new HashIndex(sz)); std::vector 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); @@ -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); @@ -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 hi(new HashIndex(N)); std::vector 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 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]]; @@ -101,7 +101,7 @@ TEST(HashIndex, add) { } EXPECT_TRUE(found); } - LOG(INFO) << hi.dump(); + LOG(INFO) << hi->dump(); } } // namespace memory