|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72499 - sandbox/bloom_filter/trunk/libs/bloom_filter/doc/html
From: cpp.cabrera_at_[hidden]
Date: 2011-06-08 21:38:03
Author: alejandro
Date: 2011-06-08 21:38:02 EDT (Wed, 08 Jun 2011)
New Revision: 72499
URL: http://svn.boost.org/trac/boost/changeset/72499
Log:
Added extended example detailing advanced usage of Bloom Filter class.
Text files modified:
sandbox/bloom_filter/trunk/libs/bloom_filter/doc/html/tutorial.html | 57 ++++++++++++++++++++++++++++++++++++---
1 files changed, 52 insertions(+), 5 deletions(-)
Modified: sandbox/bloom_filter/trunk/libs/bloom_filter/doc/html/tutorial.html
==============================================================================
--- sandbox/bloom_filter/trunk/libs/bloom_filter/doc/html/tutorial.html (original)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/doc/html/tutorial.html 2011-06-08 21:38:02 EDT (Wed, 08 Jun 2011)
@@ -85,7 +85,7 @@
<li>Advanced template parameters:
<ul>
<li><code>HashFunctions</code>:
- an mpl::vector or std::tuple (a compile-time sequence) of Hasher objects.</li>
+ a boost::mpl::vector of Hasher objects.</li>
</ul>
</li>
<li>Advanced state monitoring functions:
@@ -99,12 +99,59 @@
<p>
A Hasher is a function object that overloads operator() such that the following interface is satisfied:
- <div class="listing">
- <code class="c_keyword">template</code> <<code class="c_keyword">typename</code> <code class="c_id">T</code>>
+ </p>
+
+ <div class="listing">
+ <code class="c_keyword">template</code> <<code class="c_keyword">typename</code> <code class="c_id">T, Seed</code>>
<code class="c_keyword">struct</code> <code class="c_id">ExampleHasher</code> {
- <code class="c_type">size_t</code> <code class="c_func">operator</code>()(<code class="c_keyword">const</code> <code class="c_type">T</code>&) <code class="c_keyword">const</code>;
+ <code class="c_type">size_t</code> <code class="c_func">operator</code>()(<code class="c_keyword">const</code> <code class="c_type">T</code>&) <code class="c_keyword">const</code>;
};
- </div>
+ </div>
+ <p>
+ Note that the template parameter Seed isn't strictly required, as
+ long as some form of seeding is present in the Hasher object. Now
+ we can use a richer Bloom filter:
+ </p>
+
+ <div class="listing">
+ <code class="c_comment">// advanced Boost.BloomFilter program</code>
+ <code class="c_keyword">#include</code> <code class="c_include"><boost/bloom_filter/bloom.hpp></code>
+ <code class="c_keyword">#include</code> <code class="c_include"><iostream></code>
+ <code class="c_keyword">using namespace</code> <code class="c_namespace">boost::bloom_filter</code>;
+ <code class="c_keyword">using namespace</code> <code class="c_namespace">std</code>;
+
+ <code class="c_type">int</code> <code class="c_func">main</code>() {
+ <code class="c_keyword">typedef</code> <code class="c_namespace">boost::mpl::vector</code><<code class="c_type">Hasher</code><<code class="c_id">int, 1</code>>,
+ <code class="c_type">Hasher</code><<code class="c_id">int, 2</code>>,
+ <code class="c_type">Hasher</code><<code class="c_id">int, 3</code>> > <code class="c_type">HashFns</code>;
+ <code class="c_type"> bloom_filter</code><int, 1024, HashFns> <code class="c_id">bloom</code>;
+
+ cout << "false positive rate: "
+ << bloom.false_positive_rate()
+ << endl;
+
+ <code class="c_keyword">for</code> (<code class="c_type">int</code><code class="c_id"> i</code> = 0; i < 5000; ++i) {
+ bloom.insert(i);
+ }
+
+ <code class="c_keyword">for</code> (<code class="c_type">int</code><code class="c_id"> i</code> = 5000; i < 10000; ++i) {
+ <code class="c_keyword">if</code> (bloom.contains(i)) cout << "collision" << endl;
+ }
+
+ cout << "false positive rate: "
+ << bloom.false_positive_rate()
+ << endl;
+
+ <code class="c_keyword">return</code> 0;
+ }
+ </div>
+
+ <p>
+ All the details of insertion and querying the Bloom filter are handled
+ transparently by the insert() and contains() functions, regardless
+ of the type, bit size, and hash functions used. This makes it very
+ convenient to experiment with different Bloom filter parameters in
+ projects you commit to.
</p>
<hr/>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk