|
1 | 1 | //// |
2 | 2 | Copyright 2005-2008 Daniel James |
3 | 3 | Copyright 2022 Christian Mazakas |
4 | | -Copyright 2022 Peter Dimov |
| 4 | +Copyright 2022, 2025 Peter Dimov |
5 | 5 | Distributed under the Boost Software License, Version 1.0. |
6 | 6 | https://www.boost.org/LICENSE_1_0.txt |
7 | 7 | //// |
@@ -44,6 +44,8 @@ template<class It> std::size_t hash_range( It first, It last ); |
44 | 44 | template<class It> void hash_unordered_range( std::size_t& seed, It first, It last ); |
45 | 45 | template<class It> std::size_t hash_unordered_range( It first, It last ); |
46 | 46 |
|
| 47 | +template<class Hash> struct hash_is_avalanching; |
| 48 | +
|
47 | 49 | } // namespace boost |
48 | 50 | ---- |
49 | 51 |
|
@@ -572,6 +574,56 @@ where `x` is the currently contained value in `v`. |
572 | 574 | Throws: :: |
573 | 575 | `std::bad_variant_access` when `v.valueless_by_exception()` is `true`. |
574 | 576 |
|
| 577 | +== <boost/container_hash/{zwsp}hash_is_avalanching.hpp> |
| 578 | + |
| 579 | +Defines the trait `boost::hash_is_avalanching`. |
| 580 | + |
| 581 | +[source] |
| 582 | +---- |
| 583 | +namespace boost |
| 584 | +{ |
| 585 | +
|
| 586 | +template<class Hash> struct hash_is_avalanching; |
| 587 | +
|
| 588 | +} // namespace boost |
| 589 | +---- |
| 590 | + |
| 591 | +=== hash_is_avalanching<Hash> |
| 592 | + |
| 593 | +[source] |
| 594 | +---- |
| 595 | +template<class Hash> struct hash_is_avalanching |
| 596 | +{ |
| 597 | + static constexpr bool value = /* see below */; |
| 598 | +}; |
| 599 | +---- |
| 600 | + |
| 601 | +`hash_is_avalanching<Hash>::value` is: |
| 602 | + |
| 603 | +* `false` if `Hash::is_avalanching` is not present, |
| 604 | +* `Hash::is_avalanching::value` if this is present and convertible at compile time to a `bool`, |
| 605 | +* `true` if `Hash::is_avalanching` is `void` (this usage is deprecated), |
| 606 | +* ill-formed otherwise. |
| 607 | + |
| 608 | +A hash function is said to have the _avalanching property_ if small changes |
| 609 | +in the input translate to large changes in the returned hash code |
| 610 | +—ideally, flipping one bit in the representation of the input value results |
| 611 | +in each bit of the hash code flipping with probability 50%. Libraries |
| 612 | +such as link:../../../unordered/index.html[Boost.Unordered] consult this trait |
| 613 | +to determine if the supplied hash function is of high quality. |
| 614 | +`boost::hash` for `std::basic_string<Ch>` and `std::basic_string_view<Ch>` |
| 615 | +has this trait set to `true` when `Ch` is an integral type (this includes |
| 616 | +`std::string` and `std::string_view`, among others). |
| 617 | +Users can set this trait for a particular `Hash` type by: |
| 618 | + |
| 619 | +* Inserting the nested `is_avalanching` typedef in the class definition |
| 620 | +if they have access to its source code. |
| 621 | +* Writing a specialization of `boost::hash_is_avalanching` |
| 622 | +for `Hash`. |
| 623 | + |
| 624 | +Note that usage of this trait is not restricted to hash functions produced |
| 625 | +with Boost.ContainerHash. |
| 626 | + |
575 | 627 | == <boost/container_hash/{zwsp}is_range.hpp> |
576 | 628 |
|
577 | 629 | Defines the trait `boost::container_hash::is_range`. |
|
0 commit comments