#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);
#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] = {
* .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