# Algorithms_in_C++: data_structures Namespace Reference

Loading...
Searching...
No Matches
data_structures Namespace Reference

for IO operations More...

## Classes

class | Bitset
| Simple bitset implementation for bloom filter. More...
class | BloomFilter
| Bloom filter template class. More...
struct | Node
class | SkipList
class | trie
| Trie implementation for small-case English alphabets `a-z` More...

## Functions

static std::size_t | hashDJB2 (std::string const &s)
| Function djb2 to get hash for the given string. More...
static std::size_t | hashStr (std::string const &s)
| Hash function, to get hash for the given string. More...
std::size_t | hashInt_1 (int x)
| Hash function for test More...
std::size_t | hashInt_2 (int x)
| Hash function for test More...

## Variables

constexpr int | MAX_LEVEL = 2
| Maximum level of skip list.
constexpr float | PROBABILITY = 0.5
| Current probability for "coin toss".

## Detailed Description

for IO operations

for std::vector

for std::to_string

Data-structure algorithms.

for managing dynamic storage

Algorithms with data structures.

for assert

Data Structures algorithms.

for assert for list of hash functions for bloom filter constructor for initializer_list for bloom filter constructor for testing on strings for std::vector

Data Structures algorithms

for io operations for std::array

Algorithms with data structures

for assert for I/O operations for dynamic memory

Data Structures algorithms

for std::array for assert

Data Structures algorithms

for std::array for assert for std::ofstream for std::cout for std::unique_ptr for std::queue

Algorithms with data structures

for assert for IO operations for std::shared_ptr for std::stack for std::unordered_map

Data structures algorithms

## Function Documentation

## hashDJB2()

static std::size_t data_structures::hashDJB2 | ( | std::string const & | s | ) |

static

Function djb2 to get hash for the given string.

Parameters

  s | string to get hash from

Returns
  hash for a string

{
std::size_t hash = 5381;
for (char c : s) {
hash = ((hash << 5) + hash) + c;
}
return hash;
}
std::size_t

## hashInt_1()

std::size_t data_structures::hashInt_1 | ( | int | x | ) |

Hash function for test

Parameters

  x | to get hash from

Returns
  hash for the `x` parameter

{
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = (x >> 16) ^ x;
return x;
}

## hashInt_2()

std::size_t data_structures::hashInt_2 | ( | int | x | ) |

Hash function for test

Parameters

  x | to get hash from

Returns
  hash for the `x` parameter

{
auto y = static_cast< std::size_t >(x);
y = (y ^ (y >> 30)) * static_cast< std::size_t >(0xbf58476d1ce4e5b9);
y = (y ^ (y >> 27)) * static_cast< std::size_t >(0x94d049bb133111eb);
y = y ^ (y >> 31);
return y;
}

## hashStr()

static std::size_t data_structures::hashStr | ( | std::string const & | s | ) |

static

Hash function, to get hash for the given string.

Parameters

  s | string to get hash from

Returns
  hash for the given string

{
std::size_t hash = 37;
std::size_t primeNum1 = 54059;
std::size_t primeNum2 = 76963;
for (char c : s) {
hash = (hash * primeNum1) ^ (c * primeNum2);
}
return hash;
}