]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/unordered/doc/intro.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / unordered / doc / intro.qbk
CommitLineData
7c673cae
FG
1[/ Copyright 2006-2008 Daniel James.
2 / Distributed under the Boost Software License, Version 1.0. (See accompanying
3 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ]
4
5[def __hash-table__ [@http://en.wikipedia.org/wiki/Hash_table
6 hash table]]
7[def __hash-function__ [@http://en.wikipedia.org/wiki/Hash_function
8 hash function]]
9
10[section:intro Introduction]
11
12For accessing data based on key lookup, the C++ standard library offers `std::set`,
13`std::map`, `std::multiset` and `std::multimap`. These are generally
14implemented using balanced binary trees so that lookup time has
15logarithmic complexity. That is generally okay, but in many cases a
16__hash-table__ can perform better, as accessing data has constant complexity,
17on average. The worst case complexity is linear, but that occurs rarely and
18with some care, can be avoided.
19
20Also, the existing containers require a 'less than' comparison object
21to order their elements. For some data types this is impossible to implement
22or isn't practical. In contrast, a hash table only needs an equality function
23and a hash function for the key.
24
25With this in mind, unordered associative containers were added to the C++
26standard. This is an implementation of the containers described in C++11,
27with some [link unordered.compliance deviations from the standard] in
28order to work with non-C++11 compilers and libraries.
29
30`unordered_set` and `unordered_multiset` are defined in the header
31<[headerref boost/unordered_set.hpp]>
32
33 namespace boost {
34 template <
35 class Key,
36 class Hash = ``[classref boost::hash]``<Key>,
37 class Pred = std::equal_to<Key>,
38 class Alloc = std::allocator<Key> >
39 class ``[classref boost::unordered_set unordered_set]``;
40
41 template<
42 class Key,
43 class Hash = ``[classref boost::hash]``<Key>,
44 class Pred = std::equal_to<Key>,
45 class Alloc = std::allocator<Key> >
46 class ``[classref boost::unordered_multiset unordered_multiset]``;
47 }
48
49`unordered_map` and `unordered_multimap` are defined in the header
50<[headerref boost/unordered_map.hpp]>
51
52 namespace boost {
53 template <
54 class Key, class Mapped,
55 class Hash = ``[classref boost::hash]``<Key>,
56 class Pred = std::equal_to<Key>,
57 class Alloc = std::allocator<std::pair<Key const, Mapped> > >
58 class ``[classref boost::unordered_map unordered_map]``;
59
60 template<
61 class Key, class Mapped,
62 class Hash = ``[classref boost::hash]``<Key>,
63 class Pred = std::equal_to<Key>,
64 class Alloc = std::allocator<std::pair<Key const, Mapped> > >
65 class ``[classref boost::unordered_multimap unordered_multimap]``;
66 }
67
68When using Boost.TR1, these classes are included from `<unordered_set>` and
69`<unordered_map>`, with the classes added to the `std::tr1` namespace.
70
71The containers are used in a similar manner to the normal associative
72containers:
73
74[import src_code/intro.cpp]
75[intro_example1_2]
76
77But since the elements aren't ordered, the output of:
78
79[intro_example1_3]
80
81can be in any order. For example, it might be:
82
83 two,2
84 one,1
85 three,3
86
87To store an object in an unordered associative container requires both an
88key equality function and a hash function. The default function objects in
89the standard containers support a few basic types including integer types,
90floating point types, pointer types, and the standard strings. Since
91Boost.Unordered uses [classref boost::hash] it also supports some other types,
92including standard containers. To use any types not supported by these methods
93you have to [link hash.custom extend Boost.Hash to support the type] or use
94your own custom equality predicates and hash functions. See the
95[link unordered.hash_equality Equality Predicates and Hash Functions] section
96for more details.
97
98There are other differences, which are listed in the
99[link unordered.comparison Comparison with Associative Containers] section.
100
101[endsect]