]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/bloom_filter: move bloom_filter::density() to .cc 42502/head
authorKefu Chai <kchai@redhat.com>
Tue, 27 Jul 2021 10:13:36 +0000 (18:13 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 28 Jul 2021 04:57:13 +0000 (12:57 +0800)
for faster compilation, also, bloom_filter::density()
is not sitting in the critical paths, so no need to make it an
inline function.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/bloom_filter.cc
src/common/bloom_filter.hpp

index 0845c3febbf9aa3d20d2ac6203f065eed0086baf..9fb28efed68e5d321bf74da695594f781a37a530 100644 (file)
@@ -3,10 +3,25 @@
 
 #include "common/bloom_filter.hpp"
 
+#include <numeric>
+#include "include/intarith.h"
+
 using ceph::bufferlist;
 using ceph::bufferptr;
 using ceph::Formatter;
 
+double bloom_filter::density() const
+{
+  // TODO: use transform_reduce() in GCC-9 and up
+  unsigned set = std::accumulate(
+    bit_table_.begin(),
+    bit_table_.begin() + table_size_,
+    0u, [](unsigned set, cell_type cell) {
+      return set + popcount(cell);
+    });
+  return (double)set / (table_size_ * sizeof(cell_type) * CHAR_BIT);
+}
+
 void bloom_filter::encode(bufferlist& bl) const
 {
   ENCODE_START(2, 2, bl);
index 3e75e4e60a7baa960fcf8b626b9597e5d2a90827..639516fe40e5a2d17a8f2995c784cdbd53b3ad0b 100644 (file)
 #define COMMON_BLOOM_FILTER_HPP
 
 #include <cmath>
-#include <numeric>
 
 #include "include/encoding.h"
-#include "include/intarith.h"
 #include "include/mempool.h"
 
 static const unsigned char bit_mask[CHAR_BIT] = {
@@ -277,15 +275,7 @@ public:
    *    .75 = 200% target insertions
    *   1.0  = all bits set... infinite insertions
    */
-  inline double density() const
-  {
-    unsigned set = std::transform_reduce(
-      bit_table_.begin(),
-      bit_table_.begin() + table_size_,
-      0, std::plus<>(),
-      popcount<cell_type>);
-    return (double)set / (table_size_ * sizeof(cell_type) * CHAR_BIT);
-  }
+  double density() const;
 
   virtual inline double approx_unique_element_count() const {
     // this is not a very good estimate; a better solution should have