Skip to content

Commit

Permalink
Fix typos.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tessil committed May 17, 2020
1 parent 59e03db commit 1945d17
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ int main() {
```

#### Deny of Service (DoS) attack
In addition to `tsl::hopscotch_map` and `tsl::hopscotch_set`, the library provides two more "secure" options: `tsl::bhopscotch_map` and `tsl::bhopscotch_set` (all with their `pg` counterpars).
In addition to `tsl::hopscotch_map` and `tsl::hopscotch_set`, the library provides two more "secure" options: `tsl::bhopscotch_map` and `tsl::bhopscotch_set` (all with their `pg` counterparts).

These two additions have a worst-case asymptotic complexity of O(log n) for lookups and deletions and an amortized worst case of O(log n) for insertions (amortized due to the possibility of rehash which would be in O(n)). Even if the hash function maps all the elements to the same bucket, the O(log n) would still hold.

Expand Down
24 changes: 12 additions & 12 deletions include/tsl/bhopscotch_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class bhopscotch_map {

/**
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup to the value if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup to the value if you already have the hash.
*/
size_type erase(const key_type& key, std::size_t precalculated_hash) {
return m_ht.erase(key, precalculated_hash);
Expand All @@ -378,7 +378,7 @@ class bhopscotch_map {
* @copydoc erase(const K& key)
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup to the value if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup to the value if you already have the hash.
*/
template<class K, class KE = KeyEqual, class CP = Compare,
typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* = nullptr>
Expand All @@ -396,7 +396,7 @@ class bhopscotch_map {

/**
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
T& at(const Key& key, std::size_t precalculated_hash) { return m_ht.at(key, precalculated_hash); }

Expand All @@ -420,7 +420,7 @@ class bhopscotch_map {
* @copydoc at(const K& key)
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
template<class K, class KE = KeyEqual, class CP = Compare,
typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* = nullptr>
Expand Down Expand Up @@ -453,7 +453,7 @@ class bhopscotch_map {

/**
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
size_type count(const Key& key, std::size_t precalculated_hash) const { return m_ht.count(key, precalculated_hash); }

Expand All @@ -470,7 +470,7 @@ class bhopscotch_map {
* @copydoc count(const K& key) const
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
template<class K, class KE = KeyEqual, class CP = Compare,
typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* = nullptr>
Expand All @@ -483,7 +483,7 @@ class bhopscotch_map {

/**
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
iterator find(const Key& key, std::size_t precalculated_hash) { return m_ht.find(key, precalculated_hash); }

Expand All @@ -507,7 +507,7 @@ class bhopscotch_map {
* @copydoc find(const K& key)
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
template<class K, class KE = KeyEqual, class CP = Compare,
typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* = nullptr>
Expand All @@ -534,7 +534,7 @@ class bhopscotch_map {

/**
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
bool contains(const Key& key, std::size_t precalculated_hash) const {
return m_ht.contains(key, precalculated_hash);
Expand All @@ -551,7 +551,7 @@ class bhopscotch_map {
* @copydoc contains(const K& key) const
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
bool contains(const K& key, std::size_t precalculated_hash) const {
Expand All @@ -565,7 +565,7 @@ class bhopscotch_map {

/**
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
std::pair<iterator, iterator> equal_range(const Key& key, std::size_t precalculated_hash) {
return m_ht.equal_range(key, precalculated_hash);
Expand Down Expand Up @@ -593,7 +593,7 @@ class bhopscotch_map {
* @copydoc equal_range(const K& key)
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
template<class K, class KE = KeyEqual, class CP = Compare,
typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* = nullptr>
Expand Down
22 changes: 11 additions & 11 deletions include/tsl/bhopscotch_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class bhopscotch_set {

/**
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup to the value if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup to the value if you already have the hash.
*/
size_type erase(const key_type& key, std::size_t precalculated_hash) {
return m_ht.erase(key, precalculated_hash);
Expand All @@ -287,7 +287,7 @@ class bhopscotch_set {
* @copydoc erase(const K& key)
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup to the value if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup to the value if you already have the hash.
*/
template<class K, class KE = KeyEqual, class CP = Compare,
typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* = nullptr>
Expand All @@ -306,7 +306,7 @@ class bhopscotch_set {

/**
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
size_type count(const Key& key, std::size_t precalculated_hash) const { return m_ht.count(key, precalculated_hash); }

Expand All @@ -323,7 +323,7 @@ class bhopscotch_set {
* @copydoc count(const K& key) const
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
template<class K, class KE = KeyEqual, class CP = Compare,
typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* = nullptr>
Expand All @@ -336,7 +336,7 @@ class bhopscotch_set {

/**
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
iterator find(const Key& key, std::size_t precalculated_hash) { return m_ht.find(key, precalculated_hash); }

Expand All @@ -360,7 +360,7 @@ class bhopscotch_set {
* @copydoc find(const K& key)
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
template<class K, class KE = KeyEqual, class CP = Compare,
typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* = nullptr>
Expand All @@ -377,7 +377,7 @@ class bhopscotch_set {
* @copydoc find(const K& key)
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
template<class K, class KE = KeyEqual, class CP = Compare,
typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* = nullptr>
Expand All @@ -390,7 +390,7 @@ class bhopscotch_set {

/**
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
bool contains(const Key& key, std::size_t precalculated_hash) const {
return m_ht.contains(key, precalculated_hash);
Expand All @@ -407,7 +407,7 @@ class bhopscotch_set {
* @copydoc contains(const K& key) const
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
bool contains(const K& key, std::size_t precalculated_hash) const {
Expand All @@ -421,7 +421,7 @@ class bhopscotch_set {

/**
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
std::pair<iterator, iterator> equal_range(const Key& key, std::size_t precalculated_hash) {
return m_ht.equal_range(key, precalculated_hash);
Expand Down Expand Up @@ -449,7 +449,7 @@ class bhopscotch_set {
* @copydoc equal_range(const K& key)
*
* Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be the same
* as hash_function()(key). Usefull to speed-up the lookup if you already have the hash.
* as hash_function()(key). Useful to speed-up the lookup if you already have the hash.
*/
template<class K, class KE = KeyEqual, class CP = Compare,
typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* = nullptr>
Expand Down
16 changes: 8 additions & 8 deletions include/tsl/hopscotch_growth_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class power_of_two_growth_policy {
*/
explicit power_of_two_growth_policy(std::size_t& min_bucket_count_in_out) {
if(min_bucket_count_in_out > max_bucket_count()) {
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maxmimum size.");
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maximum size.");
}

if(min_bucket_count_in_out > 0) {
Expand All @@ -111,7 +111,7 @@ class power_of_two_growth_policy {
*/
std::size_t next_bucket_count() const {
if((m_mask + 1) > max_bucket_count() / GrowthFactor) {
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maxmimum size.");
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maximum size.");
}

return (m_mask + 1) * GrowthFactor;
Expand Down Expand Up @@ -171,7 +171,7 @@ class mod_growth_policy {
public:
explicit mod_growth_policy(std::size_t& min_bucket_count_in_out) {
if(min_bucket_count_in_out > max_bucket_count()) {
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maxmimum size.");
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maximum size.");
}

if(min_bucket_count_in_out > 0) {
Expand All @@ -188,12 +188,12 @@ class mod_growth_policy {

std::size_t next_bucket_count() const {
if(m_mod == max_bucket_count()) {
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maxmimum size.");
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maximum size.");
}

const double next_bucket_count = std::ceil(double(m_mod) * REHASH_SIZE_MULTIPLICATION_FACTOR);
if(!std::isnormal(next_bucket_count)) {
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maxmimum size.");
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maximum size.");
}

if(next_bucket_count > double(max_bucket_count())) {
Expand Down Expand Up @@ -293,15 +293,15 @@ static constexpr const std::array<std::size_t(*)(std::size_t), TSL_HH_NB_PRIMES>
* Due to the constant variable in the modulo the compiler is able to optimize the operation
* by a series of multiplications, substractions and shifts.
*
* The 'hash % 5' could become something like 'hash - (hash * 0xCCCCCCCD) >> 34) * 5' in a 64 bits environement.
* The 'hash % 5' could become something like 'hash - (hash * 0xCCCCCCCD) >> 34) * 5' in a 64 bits environment.
*/
class prime_growth_policy {
public:
explicit prime_growth_policy(std::size_t& min_bucket_count_in_out) {
auto it_prime = std::lower_bound(detail::PRIMES.begin(),
detail::PRIMES.end(), min_bucket_count_in_out);
if(it_prime == detail::PRIMES.end()) {
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maxmimum size.");
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maximum size.");
}

m_iprime = static_cast<unsigned int>(std::distance(detail::PRIMES.begin(), it_prime));
Expand All @@ -319,7 +319,7 @@ class prime_growth_policy {

std::size_t next_bucket_count() const {
if(m_iprime + 1 >= detail::PRIMES.size()) {
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maxmimum size.");
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The hash table exceeds its maximum size.");
}

return detail::PRIMES[m_iprime + 1];
Expand Down
8 changes: 4 additions & 4 deletions include/tsl/hopscotch_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ class hopscotch_hash: private Hash, private KeyEqual, private GrowthPolicy {
m_nb_elements(0)
{
if(bucket_count > max_bucket_count()) {
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The map exceeds its maxmimum size.");
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The map exceeds its maximum size.");
}

if(bucket_count > 0) {
Expand All @@ -623,7 +623,7 @@ class hopscotch_hash: private Hash, private KeyEqual, private GrowthPolicy {
this->max_load_factor(max_load_factor);


// Check in the constructor instead of outside of a function to avoi compilation issues
// Check in the constructor instead of outside of a function to avoid compilation issues
// when value_type is not complete.
static_assert(std::is_nothrow_move_constructible<value_type>::value ||
std::is_copy_constructible<value_type>::value,
Expand All @@ -646,7 +646,7 @@ class hopscotch_hash: private Hash, private KeyEqual, private GrowthPolicy {
{

if(bucket_count > max_bucket_count()) {
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The map exceeds its maxmimum size.");
TSL_HH_THROW_OR_TERMINATE(std::length_error, "The map exceeds its maximum size.");
}

if(bucket_count > 0) {
Expand All @@ -662,7 +662,7 @@ class hopscotch_hash: private Hash, private KeyEqual, private GrowthPolicy {
this->max_load_factor(max_load_factor);


// Check in the constructor instead of outside of a function to avoi compilation issues
// Check in the constructor instead of outside of a function to avoid compilation issues
// when value_type is not complete.
static_assert(std::is_nothrow_move_constructible<value_type>::value ||
std::is_copy_constructible<value_type>::value,
Expand Down
Loading

0 comments on commit 1945d17

Please sign in to comment.