Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2008-03-24 11:46:57


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

Log:
Use an unordered_map consistently for the dictionary example (Thanks to Graham Mark).
Text files modified:
   branches/unordered/trunk/libs/unordered/doc/hash_equality.qbk | 23 ++++++++++++++---------
   branches/unordered/trunk/libs/unordered/doc/src_code/insensitive.cpp | 23 ++++++++---------------
   2 files changed, 22 insertions(+), 24 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:46:56 EDT (Mon, 24 Mar 2008)
@@ -6,14 +6,15 @@
 
 While the associative containers use an ordering relation to specify how the
 elements are stored, the unordered associative containers use an equality
-predicate and a hash function. For example, [classref boost::unordered_set]
+predicate and a hash function. For example, [classref boost::unordered_map]
 is declared as:
 
- template<typename Value,
- typename Hash = ``[classref boost::hash]``<Value>,
- typename Pred = std::equal_to<Value>,
- typename Alloc = std::allocator<Value> >
- class ``[classref boost::unordered_set unordered_set]``;
+ template <
+ class Key, class Mapped,
+ class Hash = ``[classref boost::hash]``<Key>,
+ class Pred = std::equal_to<Key>,
+ class Alloc = std::allocator<Key> >
+ class ``[classref boost::unordered_map unordered_map]``;
 
 The hash function comes first as you might want to change the hash function
 but not the equality predicate, while if you were to change the behavior
@@ -21,17 +22,21 @@
 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_set]``<std::string, hash::fnv_1> words;
+ ``[classref boost::unordered_map]``<std::string, int, word_info, hash::fnv_1> dictionary;
 
 An example implementation of FNV-1, and some other hash functions are supplied
 in the examples directory.
 
 Alternatively, you might wish to use a different equality function. If you do
-this you will need to use a hash function that matches it. So to implement a
-case-insensitive dictionary:
+this you will also need to use a matching hash function that matches it. For
+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:
+
 [case_insensitive_dictionary]
 
 This is a simplified version of the example at

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:46:56 EDT (Mon, 24 Mar 2008)
@@ -35,45 +35,38 @@
             return seed;
         }
     };
-
- struct word_info;
 //]
 
- struct word_info {
- int tag;
- explicit word_info(int t = 0) : tag(t) {}
- };
-
 int main() {
 //[case_insensitive_dictionary
- boost::unordered_map<std::string, word_info, ihash, iequal_to>
+ boost::unordered_map<std::string, int, ihash, iequal_to>
         idictionary;
 //]
 
     BOOST_TEST(idictionary.empty());
 
- idictionary["one"] = word_info(1);
+ idictionary["one"] = 1;
     BOOST_TEST(idictionary.size() == 1);
     BOOST_TEST(idictionary.find("ONE") != idictionary.end() &&
         idictionary.find("ONE") == idictionary.find("one"));
 
- idictionary.insert(std::make_pair("ONE", word_info(2)));
+ idictionary.insert(std::make_pair("ONE", 2));
     BOOST_TEST(idictionary.size() == 1);
     BOOST_TEST(idictionary.find("ONE") != idictionary.end() &&
             idictionary.find("ONE")->first == "one" &&
- idictionary.find("ONE")->second.tag == 1);
+ idictionary.find("ONE")->second == 1);
 
- idictionary["One"] = word_info(3);
+ idictionary["One"] = 3;
     BOOST_TEST(idictionary.size() == 1);
     BOOST_TEST(idictionary.find("ONE") != idictionary.end() &&
             idictionary.find("ONE")->first == "one" &&
- idictionary.find("ONE")->second.tag == 3);
+ idictionary.find("ONE")->second == 3);
 
- idictionary["two"] = word_info(4);
+ idictionary["two"] = 4;
     BOOST_TEST(idictionary.size() == 2);
     BOOST_TEST(idictionary.find("two") != idictionary.end() &&
             idictionary.find("TWO")->first == "two" &&
- idictionary.find("Two")->second.tag == 4);
+ idictionary.find("Two")->second == 4);
 
     return boost::report_errors();
 }


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