]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/bloom_filter: s/bits_per_char/CHAR_BIT/
authorKefu Chai <kchai@redhat.com>
Tue, 27 Jul 2021 07:20:07 +0000 (15:20 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 27 Jul 2021 12:03:32 +0000 (20:03 +0800)
use macro defined by standard libary instead of inventing our own.

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

index a9c1f89a8c02fb7830cc9e87a6c2b1e77d44d38a..ff6f707566f923bb895ef3ec8ce85005796de80e 100644 (file)
@@ -27,8 +27,7 @@
 #include "include/mempool.h"
 #include "include/encoding.h"
 
-static const std::size_t bits_per_char = 0x08;    // 8 bits in 1 char(unsigned)
-static const unsigned char bit_mask[bits_per_char] = {
+static const unsigned char bit_mask[CHAR_BIT] = {
   0x01,  //00000001
   0x02,  //00000010
   0x04,  //00000100
@@ -256,7 +255,7 @@ public:
 
   inline virtual std::size_t size() const
   {
-    return table_size_ * bits_per_char;
+    return table_size_ * CHAR_BIT;
   }
 
   inline std::size_t element_count() const
@@ -435,7 +434,7 @@ protected:
 
     size_t salt_count = static_cast<std::size_t>(min_k);
     size_t t = static_cast<std::size_t>(min_m);
-    t += (((t & 7) != 0) ? (bits_per_char - (t & 7)) : 0);
+    t += (((t & 7) != 0) ? (CHAR_BIT - (t & 7)) : 0);
     size_t table_size = t >> 3;
     return {salt_count, table_size};
   }
@@ -511,7 +510,7 @@ public:
 
   inline std::size_t size() const override
   {
-    return size_list.back() * bits_per_char;
+    return size_list.back() * CHAR_BIT;
   }
 
   inline bool compress(const double& target_ratio)
@@ -587,10 +586,10 @@ WRITE_CLASS_ENCODER(compressible_bloom_filter)
 
 /*
   Note 1:
-  If it can be guaranteed that bits_per_char will be of the form 2^n then
+  If it can be guaranteed that CHAR_BIT will be of the form 2^n then
   the following optimization can be used:
 
-  bit_table_[bit_index >> n] |= bit_mask[bit_index & (bits_per_char - 1)];
+  bit_table_[bit_index >> n] |= bit_mask[bit_index & (CHAR_BIT - 1)];
 
   Note 2:
   For performance reasons where possible when allocating memory it should