-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitset.hpp
More file actions
72 lines (67 loc) · 2.32 KB
/
bitset.hpp
File metadata and controls
72 lines (67 loc) · 2.32 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* mini-cp is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3
* as published by the Free Software Foundation.
*
* mini-cp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with mini-cp. If not, see http://www.gnu.org/licenses/lgpl-3.0.en.html
*
* Copyright (c) 2018. by Laurent Michel, Pierre Schaus, Pascal Van Hentenryck
*
* StaticBitSet Implementation: Tim Curry
*/
#ifndef __BITSET_H
#define __BITSET_H
#include "trailable.hpp"
#include "handle.hpp"
#include "store.hpp"
#include <vector>
#include <bitset>
class StaticBitSet {
std::vector<int> _words;
int _sz;
public:
StaticBitSet() {}
StaticBitSet(int sz);
StaticBitSet(StaticBitSet&& bs) : _words(std::move(bs._words)),_sz(bs._sz) {}
int operator[] (int i) { return _words[i];}
void clear();
void remove (int pos);
bool contains(int pos) const;
};
class SparseBitSet {
std::vector<trail<int>> _words; // length = nbWords
std::vector<int> _index; // length = nbWords
std::vector<int> _mask; // length = nbWords
trail<int> _limit;
int _sz;
int _nbWords;
public:
SparseBitSet(Trailer::Ptr eng, Storage::Ptr store, int sz);
bool isEmpty() { return _limit == -1;}
void clearBit(int b);
void clearMask();
void reverseMask();
void addToMask(StaticBitSet& m);
void intersectWithMask();
int intersectIndex(StaticBitSet& m);
trail<int>& operator[] (int i) { return _words[i];}
int operator[] (int i) const { return _words[i].value();}
friend std::ostream& operator<<(std::ostream& os,const SparseBitSet& sbs) {
os << "L=" << sbs._limit << " S="<< sbs._sz << " #W=" << sbs._nbWords;
os << "\tIDX=[";
for(auto i=0;i<=sbs._limit;i++)
os << sbs._index[i] << ' ';
os << "] WORDS=[";
for(auto i=0;i<=sbs._limit;i++) {
std::bitset<32> wi(sbs._words[sbs._index[i]]);
os << wi << ' ';
}
return os << ']';
}
};
#endif