Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
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  SegmentTree
 class representation of the segment tree More...
 
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.
 
static std::size_t hashStr (std::string const &s)
 Hash function, to get hash for the given string.
 
std::size_t hashInt_1 (int x)
 Hash function for test
 
std::size_t hashInt_2 (int x)
 Hash function for test
 

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

Stack Data Structure Using the Queue Data Structure.

Data-structure algorithms.

For assert.

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

Data Structures algorithms

For IO operations For std::vector For std::min and std::max

for std::array for assert

Data Structures algorithms

Using 2 Queues inside the Stack class, we can easily implement Stack data structure with heavy computation in push function.

References used: StudyTonight

Author
tushar2407 for assert for IO operations for queue data structure

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
sstring to get hash from
Returns
hash for a string
166 {
167 std::size_t hash = 5381;
168 for (char c : s) {
169 hash = ((hash << 5) + hash) + c;
170 }
171 return hash;
172}

◆ hashInt_1()

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

Hash function for test

Parameters
xto get hash from
Returns
hash for the x parameter
199 {
200 x = ((x >> 16) ^ x) * 0x45d9f3b;
201 x = ((x >> 16) ^ x) * 0x45d9f3b;
202 x = (x >> 16) ^ x;
203 return x;
204}

◆ hashInt_2()

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

Hash function for test

Parameters
xto get hash from
Returns
hash for the x parameter
213 {
214 auto y = static_cast<std::size_t>(x);
215 y = (y ^ (y >> 30)) * static_cast<std::size_t>(0xbf58476d1ce4e5b9);
216 y = (y ^ (y >> 27)) * static_cast<std::size_t>(0x94d049bb133111eb);
217 y = y ^ (y >> 31);
218 return y;
219}

◆ hashStr()

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

Hash function, to get hash for the given string.

Parameters
sstring to get hash from
Returns
hash for the given string
182 {
183 std::size_t hash = 37;
184 std::size_t primeNum1 = 54059;
185 std::size_t primeNum2 = 76963;
186 for (char c : s) {
187 hash = (hash * primeNum1) ^ (c * primeNum2);
188 }
189 return hash;
190}