PragmaTwice commented on code in PR #2142:
URL: https://github.com/apache/kvrocks/pull/2142#discussion_r1697267794


##########
src/types/redis_hyperloglog.cc:
##########
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "redis_hyperloglog.h"
+
+#include <db_util.h>
+#include <stdint.h>
+
+#include "hyperloglog.h"
+#include "vendor/murmurhash2.h"
+
+namespace redis {
+
+/// Cache for writing to a HyperLogLog.
+///
+/// This is a bit like Bitmap::SegmentCacheStore, but simpler because
+/// 1. We would only use it for writing, hll reading always traverses all 
segments.
+/// 2. Some write access doesn't mark the segment as dirty, because the update 
value
+///    is less than the current value. So that we need to export 
`SegmentEntry` to
+///    the caller.
+///
+/// When read from storage, if the segment exists and it size is not equal to
+/// `kHyperLogLogRegisterBytesPerSegment`, it will be treated as a corruption.
+class HllSegmentCache {
+ public:
+  struct SegmentEntry {
+    /// The segment data, it's would always equal to 
`kHyperLogLogRegisterBytesPerSegment`.
+    std::string data;
+    bool dirty;
+  };
+  std::map<uint32_t, SegmentEntry> segments;
+
+  /// Get the segment from cache or storage.
+  ///
+  /// If the segment in not in the cache and storage, it will be initialized 
with
+  /// string(kHyperLogLogSegmentBytes, 0) and return OK.
+  rocksdb::Status Get(uint32_t segment_index,

Review Comment:
   here we can avoid using std::function by template parameters.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to