ngc 1.4.0
 
Loading...
Searching...
No Matches
ngcbBITLIST.hpp
Go to the documentation of this file.
1
7#ifndef ngcbBITLIST_H
8#define ngcbBITLIST_H
9
10
11#ifndef __cplusplus
12#error This is a C++ include file and cannot be used from plain C
13#endif
14
15#include <stdlib.h>
16
21public:
23 ngcbBITLIST() {Init_(32);}
24
26 explicit ngcbBITLIST(int nb) {Init_(nb);}
27
29 ~ngcbBITLIST() {if (ele_ != NULL) free(ele_);}
30
32 void Assert(int b) {
33 int n = b / 32;
34 int p = b % 32;
35 if ((n < num_) && (b >= 0)) ele_[n] |= (1 << p);
36 }
37
39 void Clear(int b) {
40 int n = b / 32;
41 int p = b % 32;
42 if ((n < num_) && (b >= 0)) ele_[n] &= ~(1 << p);
43 }
44
46 void AssertAll() {
47 int i;
48 for (i=0;i<num_;i++) ele_[i] = 0xffffffff;
49 }
50
52 void ClearAll() {
53 int i;
54 for (i=0;i<num_;i++) ele_[i] = 0x0;
55 }
56
58 int Test(int b) {
59 int n = b / 32;
60 int p = b % 32;
61 if ((n >= num_) || (b < 0)) return (0);
62 else if (ele_[n] & (1 << p)) return (1);
63 else return (0);
64 }
65
66protected:
67
68private:
70 int num_;
71
73 int *ele_;
74
76 void Init_(int nb) {
77 num_ = (nb / 32) + 1;
78 if ((nb % 32) == 0) num_--;
79 ele_ = (int *)malloc(num_ * sizeof(int));
80 if (ele_ == NULL) num_ = 0;
81 ClearAll();
82 }
83};
84
85#endif
~ngcbBITLIST()
Destructor.
Definition ngcbBITLIST.hpp:29
void Clear(int b)
Clear a bit.
Definition ngcbBITLIST.hpp:39
int Test(int b)
Test a bit.
Definition ngcbBITLIST.hpp:58
ngcbBITLIST()
Constructor for 32-bit list.
Definition ngcbBITLIST.hpp:23
void AssertAll()
Assert all bits.
Definition ngcbBITLIST.hpp:46
void Assert(int b)
Assert a bit.
Definition ngcbBITLIST.hpp:32
void ClearAll()
Clear all bits.
Definition ngcbBITLIST.hpp:52
ngcbBITLIST(int nb)
Constructor defining the number of bits.
Definition ngcbBITLIST.hpp:26