Skip to content

Commit

Permalink
Merge pull request ceph#638 from ceph/wip-bloom
Browse files Browse the repository at this point in the history
bloom filter cleanups, encodability, and unit tests
  • Loading branch information
Loic Dachary committed Oct 3, 2013
2 parents d3ba8da + 8cfeb83 commit 739696e
Show file tree
Hide file tree
Showing 11 changed files with 945 additions and 547 deletions.
4 changes: 4 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Files: src/include/ceph_hash.cc
Copyright: None
License: Public domain

Files: src/common/bloom_filter.hpp
Copyright: Copyright (C) 2000 Arash Partow <[email protected]>
License: Boost Software License, Version 1.0

Files: m4/acx_pthread.m4
Copyright: Steven G. Johnson <[email protected]>
License: GPLWithACException
Expand Down
4 changes: 4 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Files: src/include/ceph_hash.cc
Copyright: None
License: Public domain

Files: src/common/bloom_filter.hpp
Copyright: Copyright (C) 2000 Arash Partow
License: Boost Software License, Version 1.0

Files: m4/acx_pthread.m4
Copyright: Steven G. Johnson <[email protected]>
License: GPLWithACException
Expand Down
4 changes: 3 additions & 1 deletion src/common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ libcommon_la_SOURCES = \
common/ceph_strings.cc \
common/ceph_frag.cc \
common/addr_parsing.c \
common/hobject.cc
common/hobject.cc \
common/bloom_filter.cc

if LINUX
libcommon_la_SOURCES += common/secret.c
Expand Down Expand Up @@ -97,6 +98,7 @@ LIBCOMMON_DEPS += libcommon_crc.la
noinst_LTLIBRARIES += libcommon_crc.la

noinst_HEADERS += \
common/bloom_filter.hpp \
common/sctp_crc32.h \
common/crc32c_intel_baseline.h \
common/crc32c_intel_fast.h
Expand Down
76 changes: 76 additions & 0 deletions src/common/bloom_filter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "include/types.h"
#include "common/bloom_filter.hpp"

void bloom_filter::encode(bufferlist& bl) const
{
ENCODE_START(1, 1, bl);
::encode((uint64_t)salt_count_, bl);
::encode((uint64_t)table_size_, bl);
::encode((uint64_t)inserted_element_count_, bl);
::encode((uint64_t)random_seed_, bl);
bufferptr bp((const char*)bit_table_, raw_table_size_);
::encode(bp, bl);
ENCODE_FINISH(bl);
}

void bloom_filter::decode(bufferlist::iterator& p)
{
DECODE_START(1, p);
uint64_t v;
::decode(v, p);
salt_count_ = v;
::decode(v, p);
table_size_ = v;
::decode(v, p);
inserted_element_count_ = v;
::decode(v, p);
random_seed_ = v;
bufferlist t;
::decode(t, p);

salt_.clear();
generate_unique_salt();
raw_table_size_ = t.length();
assert(raw_table_size_ == table_size_ / bits_per_char);
delete bit_table_;
bit_table_ = new cell_type[raw_table_size_];
t.copy(0, raw_table_size_, (char *)bit_table_);

DECODE_FINISH(p);
}

void bloom_filter::dump(Formatter *f) const
{
f->dump_unsigned("salt_count", salt_count_);
f->dump_unsigned("table_size", table_size_);
f->dump_unsigned("raw_table_size", raw_table_size_);
f->dump_unsigned("insert_count", inserted_element_count_);
f->dump_unsigned("random_seed", random_seed_);

f->open_array_section("salt_table");
for (std::vector<bloom_type>::const_iterator i = salt_.begin(); i != salt_.end(); ++i)
f->dump_unsigned("salt", *i);
f->close_section();

f->open_array_section("bit_table");
for (unsigned i = 0; i < raw_table_size_; ++i)
f->dump_unsigned("byte", (unsigned)bit_table_[i]);
f->close_section();
}

void bloom_filter::generate_test_instances(list<bloom_filter*>& ls)
{
ls.push_back(new bloom_filter(10, .5, 1));
ls.push_back(new bloom_filter(10, .5, 1));
ls.back()->insert("foo");
ls.back()->insert("bar");
ls.push_back(new bloom_filter(50, .5, 1));
ls.back()->insert("foo");
ls.back()->insert("bar");
ls.back()->insert("baz");
ls.back()->insert("boof");
ls.back()->insert("boogggg");
}
Loading

0 comments on commit 739696e

Please sign in to comment.