diff --git a/doc/comparison.qbk b/doc/comparison.qbk index b9cbc562..8684283c 100644 --- a/doc/comparison.qbk +++ b/doc/comparison.qbk @@ -1,70 +1,26 @@ [section:comparison Comparison to Associative Containers] -The unordered associative containers have a very similar interface to the -associative containers. For example: - - #include - - ... - - typedef ``[classref boost::unordered_map]`` map; - map x; - x["one"] = 1; - x["two"] = 2; - x["three"] = 3; - - std::cout<, - typename Pred = std::equal_to, - typename Alloc = std::allocator > - class ``[classref boost::unordered_set unordered_set]``; - -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 behaviour -of the equality predicate you would have to change the hash function to match -it. - -For example, if you wanted to use +* The elements in an unordered container are organised into buckets, in an + unpredictable order. There are member functions to.... TODO +* The unordered associative containers don't support the comparison operators. +* Instead of being parameterized by an ordering relation `Compare`, + the unordered associative container are parameterized by a function object + `Hash` and an equivalence realtion `Pred`. The member types and accessor + member functions reflect this. +* Because of this, equivalent keys for unordered container are defined in + terms of `Pred`, while for the associative containers it's defined in terms + of `Compare`. +* Unordered associative containers' iterators can be invalidated by rehashing + or by inserting elements. +* Unordered associative containers' iterators are of at least the forward + iterator category. Associative containers' iterators are bidirectional. +* The unordered associative containers' constructors have extra parameters + for the number of buckets, the hash function and the equality predicate. +* The unordered associative container don't have a `lower_bound` or + `upper_bound` method - they wouldn't make any sense since the elements + aren't ordered. +* TODO: Complexity guarantees. +* TODO: Behaviour when exceptions throw. The unordered containers seem + a lot stronger defined here? [endsect] diff --git a/doc/hash_equality.qbk b/doc/hash_equality.qbk new file mode 100644 index 00000000..f0d9bdf9 --- /dev/null +++ b/doc/hash_equality.qbk @@ -0,0 +1,23 @@ +[section:hash_equality Equality Predicates and Hash Functions] + +[/TODO: A better introduction to hash functions?] + +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] +is declared as: + + template, + typename Pred = std::equal_to, + typename Alloc = std::allocator > + class ``[classref boost::unordered_set unordered_set]``; + +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 behaviour +of the equality predicate you would have to change the hash function to match +it. + +For example, if you wanted to use + +[endsect] diff --git a/doc/intro.qbk b/doc/intro.qbk index 7addd14f..b9db3ec9 100644 --- a/doc/intro.qbk +++ b/doc/intro.qbk @@ -72,6 +72,19 @@ containers: assert(x["missing"] == 0); } -But there are some major differences, which will be detailed later. +But since the elements aren't ordered, the output of: + + BOOST_FOREACH(map::value_type i, x) { + std::cout<