Add documentation.

This commit is contained in:
Tessil 2017-08-12 10:28:11 +02:00
parent c15c8f77e1
commit a40231d0c3
2 changed files with 70 additions and 0 deletions

View File

@ -36,6 +36,41 @@
namespace tsl {
/**
* Implementation of a hash map using open-adressing and the robin hood hashing algorithm.
*
* For operations modifying the hash map (insert, erase, rehash, ...), the strong exception guarantee
* is only guaranteed when the expression 'std::is_nothrow_swappable<std::pair<Key, T>>::value &&
* std::is_nothrow_move_constructible<std::pair<Key, T>>::value' is true, otherwise if an exception
* is thrown during the swap or the move, the hash map may end up in a undefined state. Per the standard
* a Key or T with a noexcept copy constructor and no move constructor also satisfies the
* 'std::is_nothrow_move_constructible<std::pair<Key, T>>::value' criterion (and will thus guarantee the
* strong exception for the map).
*
* When StoreHash is true, 32 bits of the hash is stored alongside the values. It can improve
* the performance during lookups if the KeyEqual function takes time (or engenders a cache-miss for example)
* as we then compare the stored hashes before comparing the keys. When tsl::power_of_two_growth_policy_rh is used
* as GrowthPolicy, it may also speed-up the rehash process as we can avoid to recalculate the hash.
* When it is detected that storing the hash will not incur any memory penality due to alignement (i.e.
* sizeof(tsl::detail_robin_hash::bucket_entry<ValueType, true>) ==
* sizeof(tsl::detail_robin_hash::bucket_entry<ValueType, false>)) and tsl::power_of_two_growth_policy_rh is
* used, the hash will be stored even if StoreHash is false so that we can speed-up the rehash (but it will
* not be used on lookups unless StoreHash is true).
*
* GrowthPolicy defines how the map grows and consequently how a hash value is mapped to a bucket.
* By default the map uses tsl::power_of_two_growth_policy_rh. This policy keeps the number of buckets
* to a power of two and uses a mask to map the hash to a bucket instead of the slow modulo.
* Other growth policies are available and you may define your own growth policy,
* check tsl::power_of_two_growth_policy_rh for the interface.
*
* If the destructor of Key or T throws an exception, the behaviour of the class is undefined.
*
* Iterators invalidation:
* - clear, operator=, reserve, rehash: always invalidate the iterators.
* - insert, emplace, emplace_hint, operator[]: if there is an effective insert, invalidate the iterators.
* - erase: always invalidate the iterators.
*/
template<class Key,
class T,
class Hash = std::hash<Key>,

View File

@ -36,6 +36,41 @@
namespace tsl {
/**
* Implementation of a hash set using open-adressing and the robin hood hashing algorithm.
*
* For operations modifying the hash set (insert, erase, rehash, ...), the strong exception guarantee
* is only guaranteed when the expression 'std::is_nothrow_swappable<Key>::value &&
* std::is_nothrow_move_constructible<Key>::value' is true, otherwise if an exception
* is thrown during the swap or the move, the hash set may end up in a undefined state. Per the standard
* a Key with a noexcept copy constructor and no move constructor also satisfies the
* 'std::is_nothrow_move_constructible<Key>::value' criterion (and will thus guarantee the
* strong exception for the set).
*
* When StoreHash is true, 32 bits of the hash is stored alongside the values. It can improve
* the performance during lookups if the KeyEqual function takes time (or engenders a cache-miss for example)
* as we then compare the stored hashes before comparing the keys. When tsl::power_of_two_growth_policy_rh is used
* as GrowthPolicy, it may also speed-up the rehash process as we can avoid to recalculate the hash.
* When it is detected that storing the hash will not incur any memory penality due to alignement (i.e.
* sizeof(tsl::detail_robin_hash::bucket_entry<ValueType, true>) ==
* sizeof(tsl::detail_robin_hash::bucket_entry<ValueType, false>)) and tsl::power_of_two_growth_policy_rh is
* used, the hash will be stored even if StoreHash is false so that we can speed-up the rehash (but it will
* not be used on lookups unless StoreHash is true).
*
* GrowthPolicy defines how the set grows and consequently how a hash value is mapped to a bucket.
* By default the set uses tsl::power_of_two_growth_policy_rh. This policy keeps the number of buckets
* to a power of two and uses a mask to set the hash to a bucket instead of the slow modulo.
* Other growth policies are available and you may define your own growth policy,
* check tsl::power_of_two_growth_policy_rh for the interface.
*
* If the destructor of Key throws an exception, the behaviour of the class is undefined.
*
* Iterators invalidation:
* - clear, operator=, reserve, rehash: always invalidate the iterators.
* - insert, emplace, emplace_hint, operator[]: if there is an effective insert, invalidate the iterators.
* - erase: always invalidate the iterators.
*/
template<class Key,
class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,