-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitarray.h
More file actions
56 lines (42 loc) · 1.43 KB
/
bitarray.h
File metadata and controls
56 lines (42 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Created by Ole on 10.09.2017.
//
#pragma once
#include <bitset>
#include <vector>
#include <iostream>
#define BITSET_SIZE 128
namespace vivid { namespace util {
class BitArray {
private:
std::vector<std::bitset<BITSET_SIZE>*> bitsets;
std::bitset<BITSET_SIZE>* current;
unsigned short localSize = 0;
unsigned int totalSize = 0;
public:
BitArray();
BitArray(const BitArray& other);
explicit BitArray(const unsigned int& length);
BitArray(const int& value, unsigned int length);
explicit BitArray(const std::string& bits);
BitArray(const bool* bits, const unsigned int& size);
~BitArray();
void pushBack(const bool& one);
void pushBack(const unsigned char& byte);
void pushBack(const std::string& one);
void pushFront(const bool& one);
void setBit(const unsigned int& pos, bool one);
bool getBit(const unsigned int& pos) const;
void addBit(const unsigned int& position);
void add(const unsigned int& value);
void add(const BitArray& value);
unsigned int read(const unsigned int& position, const unsigned int& length, const bool& reverse = false);
inline const unsigned int& getSize() const { return totalSize; }
const std::string toString() const;
bool operator==(const BitArray& right) const;
private:
void updateSize();
};
std::ostream& operator<<(std::ostream& stream, const BitArray& array);
std::ostream& operator<<(std::ostream& stream, const BitArray* const array);
}}