TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
data_structures::Bitset Class Reference

Simple bitset implementation for bloom filter. More...

Collaboration diagram for data_structures::Bitset:
[legend]

Public Member Functions

 Bitset (std::size_t)
 BitSet class constructor.
 
std::size_t size ()
 Utility function to return the size of the inner array.
 
void add (std::size_t)
 Turn bit on position x to 1s.
 
bool contains (std::size_t)
 Doest bitset contains element x.
 

Private Attributes

std::vector< std::size_t > data
 short info of this variable
 

Static Private Attributes

static const std::size_t blockSize
 

Detailed Description

Simple bitset implementation for bloom filter.

Definition at line 40 of file bloom_filter.cpp.

Constructor & Destructor Documentation

◆ Bitset()

data_structures::Bitset::Bitset ( std::size_t initSize)
explicit

BitSet class constructor.

Parameters
initSizeamount of blocks, each contain sizeof(std::size_t) bits

Definition at line 63 of file bloom_filter.cpp.

63: data(initSize) {}
std::vector< std::size_t > data
short info of this variable

Member Function Documentation

◆ add()

void data_structures::Bitset::add ( std::size_t x)

Turn bit on position x to 1s.

Parameters
xposition to turn bit on
Returns
void

Definition at line 71 of file bloom_filter.cpp.

71 {
72 std::size_t blockIndex = x / blockSize;
73 if (blockIndex >= data.size()) {
74 data.resize(blockIndex + 1);
75 }
76 data[blockIndex] |= 1 << (x % blockSize);
77}
static const std::size_t blockSize

◆ contains()

bool data_structures::Bitset::contains ( std::size_t x)

Doest bitset contains element x.

Parameters
xposition in bitset to check
Returns
true if bit position x is 1
false if bit position x is 0

Definition at line 86 of file bloom_filter.cpp.

86 {
87 std::size_t blockIndex = x / blockSize;
88 if (blockIndex >= data.size()) {
89 return false;
90 }
91 return data[blockIndex] & (1 << (x % blockSize));
92}

◆ size()

std::size_t data_structures::Bitset::size ( )

Utility function to return the size of the inner array.

Returns
the size of inner array

Definition at line 57 of file bloom_filter.cpp.

57{ return data.size(); }

Member Data Documentation

◆ blockSize

const std::size_t data_structures::Bitset::blockSize
staticprivate
Initial value:
=
sizeof(std::size_t)

size of integer type, that we are using in our bitset

Definition at line 43 of file bloom_filter.cpp.

◆ data

std::vector<std::size_t> data_structures::Bitset::data
private

short info of this variable

Definition at line 42 of file bloom_filter.cpp.


The documentation for this class was generated from the following file: