# Algorithms_in_C++: data_structures::Bitset Class Reference

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. More...
std::size_t | size ()
| Utility function to return the size of the inner array. More...
void | add (std::size_t)
| Turn bit on position x to 1s. More...
bool | contains (std::size_t)
| Doest bitset contains element x. More...

## 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.

## Constructor & Destructor Documentation

## Bitset()

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

explicit

BitSet class constructor.

Parameters

  initSize | amount of blocks, each contain sizeof(std::size_t) bits

: data(initSize) {}
data_structures::Bitset::data
std::vector< std::size_t > data
short info of this variable
Definition: bloom_filter.cpp:42

## Member Function Documentation

## add()

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

Turn bit on position x to 1s.

Parameters

  x | position to turn bit on

Returns
  void

{
std::size_t blockIndex = x / blockSize;
if (blockIndex >= data.size()) {
data.resize(blockIndex + 1);
}
data[blockIndex] |= 1 << (x % blockSize);
}
data_structures::Bitset::blockSize
static const std::size_t blockSize
Definition: bloom_filter.cpp:43
std::vector::resize
T resize(T... args)
std::vector::size
T size(T... args)
std::size_t
Here is the call graph for this function:

## contains()

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

Doest bitset contains element x.

Parameters

  x | position in bitset to check

Returns
  true if bit position x is 1
  false if bit position x is 0

{
std::size_t blockIndex = x / blockSize;
if (blockIndex >= data.size()) {
return false;
}
return data[blockIndex] & (1 << (x % blockSize));
}
Here is the call graph for this function:

## size()

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

Utility function to return the size of the inner array.

Returns
  the size of inner array

{ return data.size(); }
Here is the call graph for this function:

## 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

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

- data_structures/bloom_filter.cpp