Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72593 - sandbox/bloom_filter/trunk/libs/bloom_filter/example
From: cpp.cabrera_at_[hidden]
Date: 2011-06-14 17:20:00


Author: alejandro
Date: 2011-06-14 17:19:59 EDT (Tue, 14 Jun 2011)
New Revision: 72593
URL: http://svn.boost.org/trac/boost/changeset/72593

Log:
Added examples using strings and urls. Primitive, but illustrates the basic use.
Added:
   sandbox/bloom_filter/trunk/libs/bloom_filter/example/.gitignore (contents, props changed)
   sandbox/bloom_filter/trunk/libs/bloom_filter/example/string_bloom.cpp (contents, props changed)
   sandbox/bloom_filter/trunk/libs/bloom_filter/example/url_bloom.cpp (contents, props changed)

Added: sandbox/bloom_filter/trunk/libs/bloom_filter/example/.gitignore
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/example/.gitignore 2011-06-14 17:19:59 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,3 @@
+*bloom
+makefile
+*.o

Added: sandbox/bloom_filter/trunk/libs/bloom_filter/example/string_bloom.cpp
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/example/string_bloom.cpp 2011-06-14 17:19:59 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,52 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Alejandro Cabrera 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/bloom_filter for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+// introductory Boost.BloomFilter program
+#include <boost/bloom_filter/bloom.hpp>
+#include <sstream>
+#include <string>
+#include <iostream>
+using namespace boost::bloom_filter;
+using namespace std;
+
+const string gen_string(const size_t num)
+{
+ static stringstream stringer;
+ string result;
+
+ stringer << num;
+ stringer >> result;
+ stringer.clear();
+
+ return result;
+}
+
+int main () {
+ static const size_t INSERT_MAX = 5000;
+ static const size_t CONTAINS_MAX = 10000;
+ static const size_t NUM_BITS = 32768; // 8KB
+
+ bloom_filter<string, NUM_BITS> bloom;
+ size_t collisions = 0;
+
+ for (size_t i = 0; i < INSERT_MAX; ++i) {
+ bloom.insert(gen_string(i));
+ }
+
+ for (size_t i = INSERT_MAX; i < CONTAINS_MAX; ++i) {
+ if (bloom.contains(gen_string(i))) ++collisions;
+ }
+
+ cout << "collisions: " << collisions << endl;
+
+ return 0;
+}

Added: sandbox/bloom_filter/trunk/libs/bloom_filter/example/url_bloom.cpp
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/example/url_bloom.cpp 2011-06-14 17:19:59 EDT (Tue, 14 Jun 2011)
@@ -0,0 +1,54 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Alejandro Cabrera 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/bloom_filter for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+// introductory Boost.BloomFilter program
+#include <boost/bloom_filter/bloom.hpp>
+#include <sstream>
+#include <string>
+#include <iostream>
+using namespace boost::bloom_filter;
+using namespace std;
+
+const string gen_url(const size_t num)
+{
+ static const string start_url("https://www.");
+ static const string end_url(".com/");
+ static stringstream stringer;
+ string result;
+
+ stringer << num;
+ stringer >> result;
+ stringer.clear();
+
+ return start_url + result + end_url;
+}
+
+int main () {
+ static const size_t INSERT_MAX = 5000;
+ static const size_t CONTAINS_MAX = 10000;
+ static const size_t NUM_BITS = 32768; // 8KB
+
+ bloom_filter<string, NUM_BITS> bloom;
+ size_t collisions = 0;
+
+ for (size_t i = 0; i < INSERT_MAX; ++i) {
+ bloom.insert(gen_url(i));
+ }
+
+ for (size_t i = INSERT_MAX; i < CONTAINS_MAX; ++i) {
+ if (bloom.contains(gen_url(i))) ++collisions;
+ }
+
+ cout << "collisions: " << collisions << endl;
+
+ return 0;
+}


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