-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBitTable.h
47 lines (34 loc) · 1.16 KB
/
BitTable.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
/**
Use an 64bit integer to represent bit table.
Li Song
July 24, 2012
*/
#ifndef _BIT_TABLE_HEADER
#define _BIT_TABLE_HEADER
#include <stdio.h>
typedef unsigned long long int INT64 ;
#define UNIT_SIZE (sizeof( INT64 ) * 8 )
#define UNIT_MASK ((INT64)63)
class BitTable
{
private:
INT64 *tab ; // The bits
int size ; // The size of the table
int asize ; // The size of the array (size/64).
public:
BitTable() ; // Intialize a bit table.
BitTable( int s ) ; // Initalize a bit table with size s.
~BitTable() ;
void Init( int s ) ; // Initialize a bit table with size s.
void Reset() ; // Make every value 0.
void Set( int i ) ; // Set the ith bit.
void Unset( int i ) ; // Unset the ith bit
void Flip( int i ) ; // Flip the ith bit. Same as xor 1.
bool Test( int i ) ; // Test the ith bit.
void Not() ; // Not all the bits.
void And( const BitTable &in ) ; // Do the "and" on each bits.
void Or( const BitTable &in ) ; // Do the "or" on each bits.
int Count() ; // Count how many 1.
bool IsEqual( const BitTable &in ) ; // Test wether two bit tables equal.
} ;
#endif