Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2008-03-24 11:59:37


Author: danieljames
Date: 2008-03-24 11:59:36 EDT (Mon, 24 Mar 2008)
New Revision: 43828
URL: http://svn.boost.org/trac/boost/changeset/43828

Log:
Move the FNV dictionary into the cpp code, so that it can be tested for mistakes (like the one I just made).
Text files modified:
   branches/unordered/trunk/libs/unordered/doc/hash_equality.qbk | 4 ++--
   branches/unordered/trunk/libs/unordered/doc/src_code/insensitive.cpp | 31 +++++++++++++++++++++++++++++++
   2 files changed, 33 insertions(+), 2 deletions(-)

Modified: branches/unordered/trunk/libs/unordered/doc/hash_equality.qbk
==============================================================================
--- branches/unordered/trunk/libs/unordered/doc/hash_equality.qbk (original)
+++ branches/unordered/trunk/libs/unordered/doc/hash_equality.qbk 2008-03-24 11:59:36 EDT (Mon, 24 Mar 2008)
@@ -22,7 +22,8 @@
 it. So, if you wanted to use the
 [@http://www.isthe.com/chongo/tech/comp/fnv/ FNV-1 hash] you could write:
 
- ``[classref boost::unordered_map]``<std::string, int, word_info, hash::fnv_1> dictionary;
+[import src_code/insensitive.cpp]
+[case_sensitive_dictionary_fnv]
 
 An example implementation of FNV-1, and some other hash functions are supplied
 in the examples directory.
@@ -32,7 +33,6 @@
 example, to implement a case insensitive dictionary you need to define a
 case insensitive equality predicate and hash function:
 
-[import src_code/insensitive.cpp]
 [case_insensitive_functions]
 
 Which you can then use in a case insensitive dictionary:

Modified: branches/unordered/trunk/libs/unordered/doc/src_code/insensitive.cpp
==============================================================================
--- branches/unordered/trunk/libs/unordered/doc/src_code/insensitive.cpp (original)
+++ branches/unordered/trunk/libs/unordered/doc/src_code/insensitive.cpp 2008-03-24 11:59:36 EDT (Mon, 24 Mar 2008)
@@ -6,6 +6,7 @@
 #include <boost/unordered_map.hpp>
 #include <boost/detail/lightweight_test.hpp>
 #include <boost/algorithm/string/predicate.hpp>
+#include "../../examples/hash_functions/fnv-1.hpp"
 
 //[case_insensitive_functions
     struct iequal_to
@@ -38,6 +39,36 @@
 //]
 
 int main() {
+//[case_sensitive_dictionary_fnv
+ boost::unordered_map<std::string, int, hash::fnv_1>
+ dictionary;
+//]
+
+ BOOST_TEST(dictionary.empty());
+
+ dictionary["one"] = 1;
+ BOOST_TEST(dictionary.size() == 1);
+ BOOST_TEST(dictionary.find("ONE") == dictionary.end());
+
+ dictionary.insert(std::make_pair("ONE", 2));
+ BOOST_TEST(dictionary.size() == 2);
+ BOOST_TEST(dictionary.find("ONE") != dictionary.end() &&
+ dictionary.find("ONE")->first == "ONE" &&
+ dictionary.find("ONE")->second == 2);
+
+ dictionary["One"] = 3;
+ BOOST_TEST(dictionary.size() == 3);
+ BOOST_TEST(dictionary.find("One") != dictionary.end() &&
+ dictionary.find("One")->first == "One" &&
+ dictionary.find("One")->second == 3);
+
+ dictionary["two"] = 4;
+ BOOST_TEST(dictionary.size() == 4);
+ BOOST_TEST(dictionary.find("Two") == dictionary.end() &&
+ dictionary.find("two") != dictionary.end() &&
+ dictionary.find("two")->second == 4);
+
+
 //[case_insensitive_dictionary
     boost::unordered_map<std::string, int, ihash, iequal_to>
         idictionary;


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