-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitMask.h
50 lines (46 loc) · 1.33 KB
/
BitMask.h
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
#pragma once
#include <vector>
#include <fstream>
#include <unordered_map>
#include <map>
#include <set>
using namespace std;
//interesting tool class
class BitMask {
public:
protected:
vector<unsigned int> m_vectorData;
int m_iRightMostOne;
int m_iLeftMostOne;
int m_iNumOnes;
int m_iWidth;
public:
BitMask():m_vectorData(1), m_iWidth(1) {};
BitMask(int iWidth);
BitMask(const char axStr[]);
void set(int iPos);
int get(int iPos) const;
inline int getWidth() const { return m_iWidth; }
inline int getRightMostPos() const { return m_iRightMostOne; }
inline int getLeftMostPos() const { return m_iLeftMostOne; }
inline int getNumOnes() const { return m_iNumOnes; }
bool operator >= (const BitMask & rhs) const;
bool operator <= (const BitMask & rhs) const;
bool operator < (const BitMask & rhs) const;
protected:
};
class BitMaskBasedSubSupsetQuery {
public:
protected:
typedef map<int, set<BitMask>> RightMostOnePartition;
typedef map<int, RightMostOnePartition> NumOnesPartition;
NumOnesPartition m_cPartition;
public:
BitMaskBasedSubSupsetQuery() {}
void insert(const BitMask & rcBitMask);
void insert(BitMaskBasedSubSupsetQuery & rcOther);
pair<bool, BitMask> existSupset(BitMask & rcBitMask);
pair<bool, BitMask> existSubset(BitMask & rcBitMask);
protected:
};
void testBitMask();