Static Value-Flow Analysis
CoreBitVector.h
Go to the documentation of this file.
1 //===- CoreBitVector.h -- Dynamically sized bit vector data structure ------------//
2 
3 /*
4  * CoreBitVector.h
5  *
6  * Contiguous bit vector which resizes as required by common operations.
7  *
8  * Created on: Jan 31, 2021
9  * Author: Mohamad Barbar
10  */
11 
12 #ifndef COREBITVECTOR_H_
13 #define COREBITVECTOR_H_
14 
15 #include <assert.h>
16 #include <vector>
17 
18 #include "SVFIR/SVFType.h"
19 
20 namespace SVF
21 {
22 
31 {
32 public:
33  typedef unsigned long long Word;
34  static const size_t WordSize;
35 
39 
40 public:
42  CoreBitVector(void);
43 
45  CoreBitVector(size_t n);
46 
48  CoreBitVector(const CoreBitVector &cbv);
49 
52 
55 
58 
60  bool empty(void) const;
61 
63  u32_t count(void) const;
64 
66  void clear(void);
67 
69  bool test(u32_t bit) const;
70 
73  bool test_and_set(u32_t bit);
74 
76  void set(u32_t bit);
77 
79  void reset(u32_t bit);
80 
82  bool contains(const CoreBitVector &rhs) const;
83 
85  bool intersects(const CoreBitVector &rhs) const;
86 
88  bool operator==(const CoreBitVector &rhs) const;
89 
91  bool operator!=(const CoreBitVector &rhs) const;
92 
95  bool operator|=(const CoreBitVector &rhs);
96 
99  bool operator&=(const CoreBitVector &rhs);
100 
103  bool operator-=(const CoreBitVector &rhs);
104 
107  bool intersectWithComplement(const CoreBitVector &rhs);
108 
110  void intersectWithComplement(const CoreBitVector &lhs, const CoreBitVector &rhs);
111 
113  size_t hash(void) const;
114 
115  const_iterator begin(void) const;
116  const_iterator end(void) const;
117 
118 private:
120  void extendBackward(u32_t bit);
121 
123  void extendForward(u32_t bit);
124 
126  void extendTo(u32_t bit);
127 
129  size_t indexForBit(u32_t bit) const;
130 
132  bool canHold(u32_t bit) const;
133 
135  u32_t finalBit(void) const;
136 
138  u32_t firstCommonBit(const CoreBitVector &rhs) const;
139 
144  size_t nextSetIndex(const size_t start) const;
145 
146 public:
148  {
149  public:
150  using iterator_category = std::forward_iterator_tag;
151  using value_type = u32_t;
152  using difference_type = std::ptrdiff_t;
153  using pointer = u32_t *;
154  using reference = u32_t &;
155 
156  CoreBitVectorIterator(void) = delete;
157 
160  CoreBitVectorIterator(const CoreBitVector *cbv, bool end=false);
161 
164 
167 
169  const CoreBitVectorIterator &operator++(void);
170 
173 
175  u32_t operator*(void) const;
176 
178  bool operator==(const CoreBitVectorIterator &rhs) const;
179 
181  bool operator!=(const CoreBitVectorIterator &rhs) const;
182 
183  private:
184  bool atEnd(void) const;
185 
186  private:
190  std::vector<Word>::const_iterator wordIt;
194  };
195 
196 private:
200  std::vector<Word> words;
201 };
202 
203 template <>
205 {
206  size_t operator()(const CoreBitVector &cbv) const
207  {
208  return cbv.hash();
209  }
210 };
211 
212 } // End namespace SVF
213 
214 #endif // COREBITVECTOR_H_
cJSON * n
Definition: cJSON.cpp:2558
const CoreBitVectorIterator & operator++(void)
Pre-increment: ++it.
const CoreBitVector * cbv
CoreBitVector we are iterating over.
std::vector< Word >::const_iterator wordIt
Word in words we are looking at.
CoreBitVectorIterator & operator=(CoreBitVectorIterator &&cbv)=default
std::forward_iterator_tag iterator_category
CoreBitVectorIterator(const CoreBitVectorIterator &cbv)=default
bool operator==(const CoreBitVectorIterator &rhs) const
Equality: *this == rhs.
CoreBitVectorIterator & operator=(const CoreBitVectorIterator &cbv)=default
CoreBitVectorIterator(CoreBitVectorIterator &&cbv)=default
bool operator!=(const CoreBitVectorIterator &rhs) const
Inequality: *this != rhs.
u32_t operator*(void) const
Dereference: *it.
size_t nextSetIndex(const size_t start) const
bool operator==(const CoreBitVector &rhs) const
Returns true if this CBV and rhs have the same bits set.
bool intersects(const CoreBitVector &rhs) const
Returns true if this CBV and rhs share any set bits.
u32_t firstCommonBit(const CoreBitVector &rhs) const
Returns the first bit position that both this CBV and rhs can hold.
void clear(void)
Empty the CBV.
bool test_and_set(u32_t bit)
CoreBitVector & operator=(const CoreBitVector &rhs)
Copy assignment.
bool canHold(u32_t bit) const
Returns true if bit can fit in this CBV without resizing.
void reset(u32_t bit)
Resets bit in the CBV.
CoreBitVectorIterator const_iterator
Definition: CoreBitVector.h:36
void set(u32_t bit)
Sets bit in the CBV.
bool operator-=(const CoreBitVector &rhs)
void extendForward(u32_t bit)
Add enough words (append) to be able to include bit.
const_iterator iterator
Definition: CoreBitVector.h:38
static const size_t WordSize
Definition: CoreBitVector.h:34
bool operator&=(const CoreBitVector &rhs)
void extendTo(u32_t bit)
Add enough words (append xor prepend) to be able to include bit.
u32_t offset
The first bit of the first word.
bool test(u32_t bit) const
Returns true if bit is set in this CBV.
std::vector< Word > words
Our actual bit vector.
const_iterator begin(void) const
u32_t finalBit(void) const
Returns the last bit that this CBV can hold.
bool intersectWithComplement(const CoreBitVector &rhs)
const_iterator end(void) const
bool empty(void) const
Returns true if no bits are set.
unsigned long long Word
Definition: CoreBitVector.h:33
void extendBackward(u32_t bit)
Add enough words (prepend) to be able to include bit.
u32_t count(void) const
Returns number of bits set.
size_t indexForBit(u32_t bit) const
Returns the index into words which would hold bit.
CoreBitVector(void)
Construct empty CBV.
bool contains(const CoreBitVector &rhs) const
Returns true if this CBV is a superset of rhs.
bool operator!=(const CoreBitVector &rhs) const
Returns true if either this CBV or rhs has a bit set unique to the other.
bool operator|=(const CoreBitVector &rhs)
size_t hash(void) const
Hash for this CBV.
for isBitcode
Definition: BasicTypes.h:68
unsigned u32_t
Definition: GeneralType.h:46
size_t operator()(const CoreBitVector &cbv) const
provide extra hash function for std::pair handling
Definition: GeneralType.h:85