Blame view

collaboration/include/BitMap.h 778 Bytes
5ab1c29c   tangwang   first commit
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
  #include <iostream>
  #include <vector>
  
  using namespace std;
  
  class BitMap
  {
  public:
      BitMap(size_t num)
      {
          _v.resize((num >> 5) + 1);
      }
  
      void Set(size_t num) //set 1
      {
          size_t index = num >> 5;
          size_t pos = num & 0x1F;
          _v[index] |= (1 << pos);
      }
  
      void Reset(size_t num) //set 0
      {
          size_t index = num >> 5;
          size_t pos = num & 0x1F;
          _v[index] &= ~(1 << pos);
      }
  
      // 
      void ResetRoughly(size_t num) //set 0
      {
          size_t index = num >> 5;
          _v[index] = 0;
      }
  
      bool Existed(size_t num)//check whether it exists
      {
          size_t index = num >> 5;
          size_t pos = num & 0x1F;
          return (_v[index] & (1 << pos));
      }
  
  private:
      vector<size_t> _v;
  };