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