Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
948cf78
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
88c0239
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
b49cb17
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
51162a2
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
ba2c430
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
085aa69
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
b2815d5
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
b410f8e
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
2613767
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
b29d44b
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
87606b0
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
bb57d85
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
46c7eef
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
b2e2b57
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
1271ffb
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
069ff85
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
56c18df
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
57d3820
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
914e46a
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
f14289f
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
8f84c06
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
41863b0
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
c9ba490
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
89b0da4
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
26750fb
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
f74d9b1
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
2f0f134
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
2f3ae2c
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
649a417
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
563f4bd
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
f6d466f
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
27b684b
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
9cb778b
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
356c681
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
404baed
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
a5dd4b2
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
b8588c0
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
da4fb68
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
d38088c
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
2ac9569
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
508f678
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
f9e18fb
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
9209ef2
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
b361ed1
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
755ed4d
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
3adb7e4
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
12114fc
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
7cd144e
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
840f4c3
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
68bec4c
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
8efe4cc
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
e95d03b
Added translation using Weblate (Chinese (Simplified Han script))
will-cppa Jun 5, 2026
35a8e6f
Update translation files
weblate Jun 5, 2026
0f868c8
Update translation files
weblate Jun 5, 2026
9dfd142
Update translation files
weblate Jun 5, 2026
d6b8911
Update translation files
weblate Jun 5, 2026
9714a40
Update translation files
weblate Jun 5, 2026
971071d
Update translation files
weblate Jun 5, 2026
a778cd7
Update translation files
weblate Jun 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added translation using Weblate (Chinese (Simplified Han script))
  • Loading branch information
will-cppa authored and weblate committed Jun 5, 2026
commit ba2c430d6c013ab8a44af875dd0221c67d15bd6a
70 changes: 70 additions & 0 deletions doc/modules/ROOT/pages/hash_equality_zh_Hans.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[#hash_equality]

:idprefix: hash_equality_

= Equality Predicates and 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, `xref:reference/unordered_map.adoc[boost::unordered_map]` is declared as:

```cpp template < class Key, class Mapped, class Hash = boost::hash<Key>, class Pred = std::equal_to<Key>, class Alloc = std::allocator<std::pair<Key const, Mapped> > > class unordered_map; ```

The hash function comes first as you might want to change the hash function but not the equality predicate. For example, if you wanted to use the https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash[FNV-1a hash^] you could write:

```cpp boost::unordered_map<std::string, int, hash::fnv_1a> dictionary; ```

There is an link:../../../examples/fnv1.hpp[implementation of FNV-1a^] in the examples directory.

If you wish to use a different equality function, you will also need to use a matching hash function. For example, to implement a case insensitive dictionary you need to define a case insensitive equality predicate and hash function:

```cpp struct iequal_to { bool operator()(std::string const& x, std::string const& y) const { return boost::algorithm::iequals(x, y, std::locale()); } };

struct ihash { std::size_t operator()(std::string const& x) const { std::size_t seed = 0; std::locale locale;

for(std::string::const_iterator it = x.begin(); it != x.end(); ++it) { boost::hash_combine(seed, std::toupper(*it, locale)); }

return seed; } }; ```

Which you can then use in a case insensitive dictionary: ```cpp boost::unordered_map<std::string, int, ihash, iequal_to> idictionary; ```

This is a simplified version of the example at link:../../../examples/case_insensitive.hpp[/libs/unordered/examples/case_insensitive.hpp^] which supports other locales and string types.

CAUTION: Be careful when using the equality (`==`) operator with custom equality
predicates, especially if you're using a function pointer. If you compare two containers with different equality predicates then the result is undefined. For most stateless function objects this is impossible - since you can only compare objects with the same equality predicate you know the equality predicates must be equal. But if you're using function pointers or a stateful equality predicate (e.g. `boost::function`) then you can get into trouble.

== Custom Types

Similarly, a custom hash function can be used for custom types:

```cpp struct point { int x; int y; };

bool operator==(point const& p1, point const& p2) { return p1.x == p2.x && p1.y == p2.y; }

struct point_hash { std::size_t operator()(point const& p) const { std::size_t seed = 0; boost::hash_combine(seed, p.x); boost::hash_combine(seed, p.y); return seed; } };

boost::unordered_multiset<point, point_hash> points; ```

Since the default hash function is link:../../../../container_hash/index.html[Boost.Hash^], we can extend it to support the type so that the hash function doesn't need to be explicitly given:

```cpp struct point { int x; int y; };

bool operator==(point const& p1, point const& p2) { return p1.x == p2.x && p1.y == p2.y; }

std::size_t hash_value(point const& p) { std::size_t seed = 0; boost::hash_combine(seed, p.x); boost::hash_combine(seed, p.y); return seed; }

// Now the default function objects work.
boost::unordered_multiset<point> points; ```

See the link:../../../../container_hash/index.html[Boost.Hash documentation^] for more detail on how to do this. Remember that it relies on extensions to the standard - so it won't work for other implementations of the unordered associative containers, you'll need to explicitly use Boost.Hash.

[caption=, title='Table {counter:table-counter} Methods for accessing the hash and equality functions']
[cols="1,.^1", frame=all, grid=rows]
|===
|Method |Description

|`hasher hash_function() const`
|Returns the container's hash function.

|`key_equal key_eq() const`
|Returns the container's key equality function..

|===