1 | #include "BitArray.h"
|
---|
2 |
|
---|
3 | BitArray::BitArray(unsigned long newsize)
|
---|
4 | {
|
---|
5 | arraysize = newsize;
|
---|
6 | bitlongs = ((arraysize - 1) >> 5) + 1;
|
---|
7 | bits = new unsigned long[bitlongs];
|
---|
8 | }
|
---|
9 |
|
---|
10 | BitArray::BitArray(const BitArray& b)
|
---|
11 | {
|
---|
12 | arraysize = b.arraysize;
|
---|
13 | bitlongs = b.bitlongs;
|
---|
14 | bits = new unsigned long[bitlongs];
|
---|
15 | for (unsigned long i = 0; i < bitlongs; i++)
|
---|
16 | bits[i] = b.bits[i];
|
---|
17 | }
|
---|
18 |
|
---|
19 | BitArray::BitArray(unsigned long newsize, bool bitvalues)
|
---|
20 | {
|
---|
21 | arraysize = newsize;
|
---|
22 | bitlongs = ((arraysize - 1) >> 5) + 1;
|
---|
23 | bits = new unsigned long[bitlongs];
|
---|
24 | if (bitvalues) set(); else clear();
|
---|
25 | }
|
---|
26 |
|
---|
27 | BitArray::BitArray(unsigned long newsize, unsigned long *newbits)
|
---|
28 | {
|
---|
29 | arraysize = newsize;
|
---|
30 | bitlongs = ((arraysize - 1) >> 5) + 1;
|
---|
31 | bits = new unsigned long[bitlongs];
|
---|
32 | for (unsigned long i = 0; i < bitlongs; i++)
|
---|
33 | bits[i] = newbits[i];
|
---|
34 | }
|
---|
35 |
|
---|
36 | BitArray::~BitArray()
|
---|
37 | {
|
---|
38 | delete []bits;
|
---|
39 | }
|
---|
40 |
|
---|
41 | BitArray& BitArray::operator =(const BitArray& b)
|
---|
42 | {
|
---|
43 | bool equalsize = arraysize == b.arraysize;
|
---|
44 |
|
---|
45 | arraysize = b.arraysize;
|
---|
46 | bitlongs = b.bitlongs;
|
---|
47 |
|
---|
48 | if (!equalsize) {
|
---|
49 | delete []bits;
|
---|
50 | bits = new unsigned long[bitlongs];
|
---|
51 | }
|
---|
52 | for (unsigned long i = 0; i < bitlongs; i++)
|
---|
53 | bits[i] = b.bits[i];
|
---|
54 |
|
---|
55 | return (*this);
|
---|
56 | }
|
---|
57 |
|
---|
58 | BitArray BitArray::operator ~(void)
|
---|
59 | {
|
---|
60 | BitArray result(arraysize);
|
---|
61 |
|
---|
62 | for (unsigned long i = 0; i < bitlongs; i++)
|
---|
63 | result.bits[i] = ~bits[i];
|
---|
64 |
|
---|
65 | return (result);
|
---|
66 | }
|
---|
67 |
|
---|
68 | BitArray& BitArray::operator ^=(const BitArray& b)
|
---|
69 | {
|
---|
70 | for (unsigned long i = 0; i < ((bitlongs < b.bitlongs) ? bitlongs : b.bitlongs); i++)
|
---|
71 | bits[i] ^= b.bits[i];
|
---|
72 | return (*this);
|
---|
73 | }
|
---|
74 |
|
---|
75 | BitArray& BitArray::operator &=(const BitArray& b)
|
---|
76 | {
|
---|
77 | for (unsigned long i = 0; i < ((bitlongs < b.bitlongs) ? bitlongs : b.bitlongs); i++)
|
---|
78 | bits[i] &= b.bits[i];
|
---|
79 | return (*this);
|
---|
80 | }
|
---|
81 |
|
---|
82 | BitArray& BitArray::operator |=(const BitArray& b)
|
---|
83 | {
|
---|
84 | for (unsigned long i = 0; i < (bitlongs < b.bitlongs ? bitlongs : b.bitlongs); i++)
|
---|
85 | bits[i] |= b.bits[i];
|
---|
86 | return (*this);
|
---|
87 | }
|
---|
88 |
|
---|
89 | BitArray BitArray::operator ^(const BitArray& b)
|
---|
90 | {
|
---|
91 | BitArray result((arraysize < b.arraysize) ? arraysize : b.arraysize);
|
---|
92 |
|
---|
93 | for (unsigned long i = 0; i < result.bitlongs; i++)
|
---|
94 | result.bits[i] = bits[i] ^ b.bits[i];
|
---|
95 | return (result);
|
---|
96 | }
|
---|
97 |
|
---|
98 | BitArray BitArray::operator &(const BitArray& b)
|
---|
99 | {
|
---|
100 | BitArray result((arraysize < b.arraysize) ? arraysize : b.arraysize);
|
---|
101 |
|
---|
102 | for (unsigned long i = 0; i < result.bitlongs; i++)
|
---|
103 | result.bits[i] = bits[i] & b.bits[i];
|
---|
104 | return (result);
|
---|
105 | }
|
---|
106 |
|
---|
107 | BitArray BitArray::operator |(const BitArray& b)
|
---|
108 | {
|
---|
109 | BitArray result((arraysize < b.arraysize) ? arraysize : b.arraysize);
|
---|
110 |
|
---|
111 | for (unsigned long i = 0; i < result.bitlongs; i++)
|
---|
112 | result.bits[i] = bits[i] | b.bits[i];
|
---|
113 | return (result);
|
---|
114 | }
|
---|