Skip to content

Commit

Permalink
remove the code for merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU committed Jul 30, 2024
1 parent 7cf88ef commit d3b2978
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 94 deletions.
33 changes: 0 additions & 33 deletions src/types/redis_hyperloglog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,39 +132,6 @@ rocksdb::Status HyperLogLog::Count(const Slice &user_key, uint64_t *ret) {
return rocksdb::Status::OK();
}

/*
rocksdb::Status HyperLogLog::Merge(const std::vector<Slice> &user_keys) {
std::vector<uint8_t> max(kHyperLogLogRegisterBytes);
for (const auto &user_key : user_keys) {
std::vector<uint8_t> registers(kHyperLogLogRegisterBytes);
auto s = getRegisters(user_key, &registers);
if (!s.ok()) return s;
HllMerge(&max, registers);
}
std::string ns_key = AppendNamespacePrefix(user_keys[0]);
LockGuard guard(storage_->GetLockManager(), ns_key);
HyperLogLogMetadata metadata;
rocksdb::Status s = GetMetadata(GetOptions(), ns_key, &metadata);
if (!s.ok() && !s.IsNotFound()) return s;
auto batch = storage_->GetWriteBatchBase();
WriteBatchLogData log_data(kRedisHyperLogLog);
batch->PutLogData(log_data.Encode());
Bitmap::SegmentCacheStore cache(storage_, metadata_cf_handle_, ns_key, &metadata);
for (uint32_t segment_index = 0; segment_index < kHyperLogLogSegmentCount; segment_index++) {
std::string *segment = nullptr;
s = cache.GetMut(segment_index, &segment);
if (!s.ok()) return s;
(*segment).assign(reinterpret_cast<const char *>(max.data()) + segment_index * kHyperLogLogRegisterBytesPerSegment,
kHyperLogLogRegisterBytesPerSegment);
}
cache.BatchForFlush(batch);
return storage_->Write(storage_->DefaultWriteOptions(), batch->GetWriteBatch());
}
*/

rocksdb::Status HyperLogLog::getRegisters(const Slice &user_key, std::vector<uint8_t> *registers) {
std::string ns_key = AppendNamespacePrefix(user_key);

Expand Down
61 changes: 0 additions & 61 deletions tests/cppunit/types/hyperloglog_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,64 +70,3 @@ TEST_F(RedisHyperLogLogTest, PFCOUNT_returns_approximated_cardinality_of_set) {
// pf count is 10
ASSERT_TRUE(hll_->Count("hll", &ret).ok() && ret == 10);
}

/*
TEST_F(RedisHyperLogLogTest, PFMERGE_results_on_the_cardinality_of_union_of_sets) {
uint64_t ret = 0;
// pf add hll1 a b c
ASSERT_TRUE(hll_->Add("hll1", computeHashes({"a", "b", "c"}), &ret).ok() && ret == 1);
// pf add hll2 b c d
ASSERT_TRUE(hll_->Add("hll2", {"b", "c", "d"}, &ret).ok() && ret == 1);
// pf add hll3 c d e
ASSERT_TRUE(hll_->Add("hll3", {"c", "d", "e"}, &ret).ok() && ret == 1);
// pf merge hll hll1 hll2 hll3
ASSERT_TRUE(hll_->Merge({"hll", "hll1", "hll2", "hll3"}).ok());
// pf count hll is 5
ASSERT_TRUE(hll_->Count("hll", &ret).ok());
ASSERT_TRUE(ret == 5) << "ret: " << ret;
}
TEST_F(RedisHyperLogLogTest, PFCOUNT_multiple_keys_merge_returns_cardinality_of_union_1) {
for (int x = 1; x < 1000; x++) {
uint64_t ret = 0;
ASSERT_TRUE(hll_->Add("hll0", {"foo-" + std::to_string(x)}, &ret).ok());
ASSERT_TRUE(hll_->Add("hll1", {"bar-" + std::to_string(x)}, &ret).ok());
ASSERT_TRUE(hll_->Add("hll2", {"zap-" + std::to_string(x)}, &ret).ok());
std::vector<uint64_t> cards(3);
ASSERT_TRUE(hll_->Count("hll0", &cards[0]).ok());
ASSERT_TRUE(hll_->Count("hll1", &cards[1]).ok());
ASSERT_TRUE(hll_->Count("hll2", &cards[2]).ok());
auto card = static_cast<double>(cards[0] + cards[1] + cards[2]);
double realcard = x * 3;
// assert the ABS of 'card' and 'realcart' is within 5% of the cardinality
double left = std::abs(card - realcard);
double right = card / 100 * 5;
ASSERT_LT(left, right) << "left : " << left << ", right: " << right;
}
}
TEST_F(RedisHyperLogLogTest, PFCOUNT_multiple_keys_merge_returns_cardinality_of_union_2) {
std::srand(time(nullptr));
std::vector<int> realcard_vec;
for (auto i = 1; i < 1000; i++) {
for (auto j = 0; j < 3; j++) {
uint64_t ret = 0;
int rint = std::rand() % 20000;
ASSERT_TRUE(hll_->Add("hll" + std::to_string(j), {std::to_string(rint)}, &ret).ok());
realcard_vec.push_back(rint);
}
}
std::vector<uint64_t> cards(3);
ASSERT_TRUE(hll_->Count("hll0", &cards[0]).ok());
ASSERT_TRUE(hll_->Count("hll1", &cards[1]).ok());
ASSERT_TRUE(hll_->Count("hll2", &cards[2]).ok());
auto card = static_cast<double>(cards[0] + cards[1] + cards[2]);
auto realcard = static_cast<double>(realcard_vec.size());
double left = std::abs(card - realcard);
double right = card / 100 * 5;
ASSERT_LT(left, right) << "left : " << left << ", right: " << right;
}
*/

0 comments on commit d3b2978

Please sign in to comment.