1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
1241.9.54
by Monty Taylor
Moved bitmap into drizzled. |
16 |
#include "config.h" |
17 |
||
18 |
#include <drizzled/sql_bitmap.h> |
|
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
19 |
#include "drizzled/internal/m_string.h" |
20 |
#include "drizzled/internal/my_bit.h" |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
21 |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
22 |
#include <memory> |
23 |
||
1067.4.10
by Nathan Williams
Converted all cmin/cmax usages in the mysys directory to std::min/max. |
24 |
using namespace std; |
25 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
26 |
namespace drizzled |
27 |
{
|
|
28 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
29 |
void MyBitmap::createLastWordMask() |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
30 |
{
|
31 |
/* Get the number of used bits (1..8) in the last byte */
|
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
32 |
unsigned int const used= 1U + ((n_bits-1U) & 0x7U); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
33 |
|
34 |
/*
|
|
35 |
Create a mask with the upper 'unused' bits set and the lower 'used'
|
|
36 |
bits clear. The bits within each byte is stored in big-endian order.
|
|
37 |
*/
|
|
1126.8.1
by Joe Daly
changes to allow -Wconversion flag to be turned on |
38 |
unsigned char const mask= static_cast<unsigned char const>((~((1 << used) - 1)) & 255); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
39 |
|
40 |
/*
|
|
41 |
The first bytes are to be set to zero since they represent real bits
|
|
42 |
in the bitvector. The last bytes are set to 0xFF since they represent
|
|
43 |
bytes not used by the bitvector. Finally the last byte contains bits
|
|
44 |
as set by the mask above.
|
|
45 |
*/
|
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
46 |
unsigned char *ptr= (unsigned char*)&last_word_mask; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
47 |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
48 |
last_word_ptr= bitmap + numOfWordsInMap()-1; |
49 |
switch (numOfBytesInMap() & 3) |
|
50 |
{
|
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
51 |
case 1: |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
52 |
last_word_mask= UINT32_MAX; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
53 |
ptr[0]= mask; |
54 |
return; |
|
55 |
case 2: |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
56 |
last_word_mask= UINT32_MAX; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
57 |
ptr[0]= 0; |
58 |
ptr[1]= mask; |
|
59 |
return; |
|
60 |
case 3: |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
61 |
last_word_mask= 0; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
62 |
ptr[2]= mask; |
63 |
ptr[3]= 0xFFU; |
|
64 |
return; |
|
65 |
case 0: |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
66 |
last_word_mask= 0U; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
67 |
ptr[3]= mask; |
68 |
return; |
|
69 |
}
|
|
70 |
}
|
|
71 |
||
72 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
73 |
bool MyBitmap::init(my_bitmap_map *buf, uint32_t num_bits) |
74 |
{
|
|
75 |
if (! buf) |
|
76 |
{
|
|
77 |
uint32_t size_in_bytes= bitmap_buffer_size(num_bits); |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
78 |
if (! (buf= new(nothrow) my_bitmap_map[size_in_bytes]())) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
79 |
{
|
80 |
return true; |
|
81 |
}
|
|
82 |
}
|
|
83 |
||
84 |
bitmap= buf; |
|
85 |
n_bits= num_bits; |
|
86 |
createLastWordMask(); |
|
87 |
clearAll(); |
|
88 |
||
89 |
return false; |
|
90 |
}
|
|
91 |
||
92 |
||
93 |
bool MyBitmap::testAndSet(const uint32_t bitPos) |
|
94 |
{
|
|
95 |
unsigned char *value= ((unsigned char*) bitmap) + (bitPos / 8); |
|
1126.8.1
by Joe Daly
changes to allow -Wconversion flag to be turned on |
96 |
unsigned char bit= static_cast<unsigned char>(1 << ((bitPos) & 7)); |
97 |
unsigned char res= static_cast<unsigned char>((*value) & bit); |
|
98 |
*value= static_cast<unsigned char>(*value | bit); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
99 |
return res; |
100 |
}
|
|
101 |
||
102 |
||
1014.2.12
by Monty Taylor
Removed the thread-safe crap in MY_BITMAP. Also remove the temp-pool option for |
103 |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
104 |
bool MyBitmap::testAndClear(const uint32_t bitPos) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
105 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
106 |
unsigned char *byte= (unsigned char*) bitmap + (bitPos / 8); |
1126.8.1
by Joe Daly
changes to allow -Wconversion flag to be turned on |
107 |
unsigned char bit= static_cast<unsigned char>(1 << ((bitPos) & 7)); |
108 |
unsigned char res= static_cast<unsigned char>((*byte) & bit); |
|
109 |
*byte= static_cast<unsigned char>(*byte & ~bit); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
110 |
return res; |
111 |
}
|
|
112 |
||
113 |
||
114 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
115 |
uint32_t MyBitmap::setNext() |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
116 |
{
|
117 |
uint32_t bit_found; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
118 |
assert(bitmap); |
119 |
if ((bit_found= getFirst()) != MY_BIT_NONE) |
|
120 |
{
|
|
121 |
setBit(bit_found); |
|
122 |
}
|
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
123 |
return bit_found; |
124 |
}
|
|
125 |
||
126 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
127 |
void MyBitmap::setPrefix(uint32_t prefix_size) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
128 |
{
|
129 |
uint32_t prefix_bytes, prefix_bits, d; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
130 |
unsigned char *m= (unsigned char *) bitmap; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
131 |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
132 |
assert(bitmap && |
133 |
(prefix_size <= n_bits || prefix_size == UINT32_MAX)); |
|
134 |
set_if_smaller(prefix_size, n_bits); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
135 |
if ((prefix_bytes= prefix_size / 8)) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
136 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
137 |
memset(m, 0xff, prefix_bytes); |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
138 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
139 |
m+= prefix_bytes; |
140 |
if ((prefix_bits= prefix_size & 7)) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
141 |
{
|
1126.8.1
by Joe Daly
changes to allow -Wconversion flag to be turned on |
142 |
*m++= static_cast<unsigned char>((1 << prefix_bits)-1); |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
143 |
}
|
144 |
if ((d= numOfBytesInMap() - prefix_bytes)) |
|
145 |
{
|
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
146 |
memset(m, 0, d); |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
147 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
148 |
}
|
149 |
||
150 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
151 |
bool MyBitmap::isPrefix(const uint32_t prefix_size) const |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
152 |
{
|
153 |
uint32_t prefix_bits= prefix_size & 0x7, res; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
154 |
unsigned char *m= (unsigned char*) bitmap; |
155 |
unsigned char *end_prefix= m + prefix_size/8; |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
156 |
unsigned char *end; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
157 |
assert(m && prefix_size <= n_bits); |
158 |
end= m + numOfBytesInMap(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
159 |
|
160 |
while (m < end_prefix) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
161 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
162 |
if (*m++ != 0xff) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
163 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
164 |
return 0; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
165 |
}
|
166 |
}
|
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
167 |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
168 |
*last_word_ptr&= ~last_word_mask; /*Clear bits*/ |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
169 |
res= 0; |
170 |
if (prefix_bits && *m++ != (1 << prefix_bits)-1) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
171 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
172 |
goto ret; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
173 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
174 |
|
175 |
while (m < end) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
176 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
177 |
if (*m++ != 0) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
178 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
179 |
goto ret; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
180 |
}
|
181 |
}
|
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
182 |
res= 1; |
183 |
ret: |
|
184 |
return res; |
|
185 |
}
|
|
186 |
||
187 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
188 |
bool MyBitmap::isSetAll() const |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
189 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
190 |
my_bitmap_map *data_ptr= bitmap; |
191 |
my_bitmap_map *end= last_word_ptr; |
|
192 |
*last_word_ptr |= last_word_mask; |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
193 |
for (; data_ptr <= end; data_ptr++) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
194 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
195 |
if (*data_ptr != 0xFFFFFFFF) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
196 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
197 |
return false; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
198 |
}
|
199 |
}
|
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
200 |
return true; |
201 |
}
|
|
202 |
||
203 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
204 |
bool MyBitmap::isClearAll() const |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
205 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
206 |
my_bitmap_map *data_ptr= bitmap; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
207 |
my_bitmap_map *end; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
208 |
if (*last_word_ptr & ~last_word_mask) |
209 |
{
|
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
210 |
return false; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
211 |
}
|
212 |
end= last_word_ptr; |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
213 |
for (; data_ptr < end; data_ptr++) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
214 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
215 |
if (*data_ptr) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
216 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
217 |
return false; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
218 |
}
|
219 |
}
|
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
220 |
return true; |
221 |
}
|
|
222 |
||
223 |
/* Return true if map1 is a subset of map2 */
|
|
224 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
225 |
bool bitmap_is_subset(const MyBitmap *map1, const MyBitmap *map2) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
226 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
227 |
my_bitmap_map *m1= map1->getBitmap(), *m2= map2->getBitmap(), *end; |
228 |
||
229 |
assert(map1->getBitmap() && map2->getBitmap() && |
|
230 |
map1->numOfBitsInMap() == map2->numOfBitsInMap()); |
|
231 |
||
232 |
end= map1->getLastWordPtr(); |
|
233 |
map1->subtractMaskFromLastWord(); |
|
234 |
map2->subtractMaskFromLastWord(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
235 |
while (m1 <= end) |
236 |
{
|
|
237 |
if ((*m1++) & ~(*m2++)) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
238 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
239 |
return 0; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
240 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
241 |
}
|
242 |
return 1; |
|
243 |
}
|
|
244 |
||
245 |
/* True if bitmaps has any common bits */
|
|
246 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
247 |
bool bitmap_is_overlapping(const MyBitmap *map1, const MyBitmap *map2) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
248 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
249 |
my_bitmap_map *m1= map1->getBitmap(), *m2= map2->getBitmap(), *end; |
250 |
||
251 |
assert(map1->getBitmap() && map2->getBitmap() && |
|
252 |
map1->numOfBitsInMap() == map2->numOfBitsInMap()); |
|
253 |
||
254 |
end= map1->getLastWordPtr(); |
|
255 |
map1->subtractMaskFromLastWord(); |
|
256 |
map2->subtractMaskFromLastWord(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
257 |
while (m1 <= end) |
258 |
{
|
|
259 |
if ((*m1++) & (*m2++)) |
|
260 |
return 1; |
|
261 |
}
|
|
262 |
return 0; |
|
263 |
}
|
|
264 |
||
265 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
266 |
void bitmap_intersect(MyBitmap *map, const MyBitmap *map2) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
267 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
268 |
my_bitmap_map *to= map->getBitmap(), *from= map2->getBitmap(), *end; |
269 |
uint32_t len= map->numOfWordsInMap(), len2 = map2->numOfWordsInMap(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
270 |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
271 |
assert(map->getBitmap() && map2->getBitmap()); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
272 |
|
1067.4.10
by Nathan Williams
Converted all cmin/cmax usages in the mysys directory to std::min/max. |
273 |
end= to+min(len,len2); |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
274 |
map2->subtractMaskFromLastWord(); /* Clear last bits in map2 */ |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
275 |
while (to < end) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
276 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
277 |
*to++ &= *from++; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
278 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
279 |
|
280 |
if (len2 < len) |
|
281 |
{
|
|
282 |
end+=len-len2; |
|
283 |
while (to < end) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
284 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
285 |
*to++=0; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
286 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
287 |
}
|
288 |
}
|
|
289 |
||
290 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
291 |
void MyBitmap::setAbove(const uint32_t from_byte, const uint32_t use_bit) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
292 |
{
|
1126.8.1
by Joe Daly
changes to allow -Wconversion flag to be turned on |
293 |
unsigned char use_byte= static_cast<unsigned char>(use_bit ? 0xff : 0); |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
294 |
unsigned char *to= (unsigned char *) bitmap + from_byte; |
295 |
unsigned char *end= (unsigned char *) bitmap + (n_bits+7)/8; |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
296 |
|
297 |
while (to < end) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
298 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
299 |
*to++= use_byte; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
300 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
301 |
}
|
302 |
||
303 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
304 |
void bitmap_subtract(MyBitmap *map, const MyBitmap *map2) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
305 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
306 |
my_bitmap_map *to= map->getBitmap(), *from= map2->getBitmap(), *end; |
307 |
assert(map->getBitmap() && map2->getBitmap() && |
|
308 |
map->numOfBitsInMap() == map2->numOfBitsInMap()); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
309 |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
310 |
end= map->getLastWordPtr(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
311 |
|
312 |
while (to <= end) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
313 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
314 |
*to++ &= ~(*from++); |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
315 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
316 |
}
|
317 |
||
318 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
319 |
void bitmap_union(MyBitmap *map, const MyBitmap *map2) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
320 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
321 |
my_bitmap_map *to= map->getBitmap(), *from= map2->getBitmap(), *end; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
322 |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
323 |
assert(map->getBitmap() && map2->getBitmap() && |
324 |
map->numOfBitsInMap() == map2->numOfBitsInMap()); |
|
325 |
end= map->getLastWordPtr(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
326 |
|
327 |
while (to <= end) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
328 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
329 |
*to++ |= *from++; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
330 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
331 |
}
|
332 |
||
333 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
334 |
void bitmap_xor(MyBitmap *map, const MyBitmap *map2) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
335 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
336 |
my_bitmap_map *to= map->getBitmap(); |
337 |
my_bitmap_map *from= map2->getBitmap(); |
|
338 |
my_bitmap_map *end= map->getLastWordPtr(); |
|
339 |
assert(map->getBitmap() && map2->getBitmap() && |
|
340 |
map->numOfBitsInMap() == map2->numOfBitsInMap()); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
341 |
while (to <= end) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
342 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
343 |
*to++ ^= *from++; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
344 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
345 |
}
|
346 |
||
347 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
348 |
void bitmap_invert(MyBitmap *map) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
349 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
350 |
my_bitmap_map *to= map->getBitmap(), *end; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
351 |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
352 |
assert(map->getBitmap()); |
353 |
end= map->getLastWordPtr(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
354 |
|
355 |
while (to <= end) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
356 |
{
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
357 |
*to++ ^= 0xFFFFFFFF; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
358 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
359 |
}
|
360 |
||
361 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
362 |
uint32_t MyBitmap::getBitsSet() |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
363 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
364 |
unsigned char *m= (unsigned char*) bitmap; |
365 |
unsigned char *end= m + numOfBytesInMap(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
366 |
uint32_t res= 0; |
367 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
368 |
assert(bitmap); |
369 |
*last_word_ptr&= ~last_word_mask; /*Reset last bits to zero*/ |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
370 |
while (m < end) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
371 |
{
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
372 |
res+= internal::my_count_bits_uint16(*m++); |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
373 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
374 |
return res; |
375 |
}
|
|
376 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
377 |
MyBitmap::MyBitmap(const MyBitmap& rhs) |
378 |
{
|
|
379 |
my_bitmap_map *to= this->bitmap, *from= rhs.bitmap, *end; |
|
380 |
||
381 |
if (this->bitmap && rhs.bitmap && |
|
382 |
this->n_bits == rhs.n_bits) |
|
383 |
{
|
|
384 |
end= this->last_word_ptr; |
|
385 |
while (to <= end) |
|
386 |
{
|
|
387 |
*to++ = *from++; |
|
388 |
}
|
|
389 |
}
|
|
390 |
else
|
|
391 |
{
|
|
392 |
this->n_bits= rhs.n_bits; |
|
393 |
this->bitmap= rhs.bitmap; |
|
394 |
}
|
|
395 |
}
|
|
396 |
||
397 |
MyBitmap& MyBitmap::operator=(const MyBitmap& rhs) |
|
398 |
{
|
|
399 |
if (this == &rhs) |
|
400 |
return *this; |
|
401 |
||
402 |
my_bitmap_map *to= this->bitmap, *from= rhs.bitmap, *end; |
|
403 |
||
404 |
if (this->bitmap && rhs.bitmap && |
|
405 |
this->n_bits == rhs.n_bits) |
|
406 |
{
|
|
407 |
end= this->last_word_ptr; |
|
408 |
while (to <= end) |
|
409 |
{
|
|
410 |
*to++ = *from++; |
|
411 |
}
|
|
412 |
}
|
|
413 |
else
|
|
414 |
{
|
|
415 |
this->n_bits= rhs.n_bits; |
|
416 |
this->bitmap= rhs.bitmap; |
|
417 |
}
|
|
418 |
||
419 |
return *this; |
|
420 |
}
|
|
421 |
||
422 |
uint32_t MyBitmap::getFirstSet() |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
423 |
{
|
424 |
unsigned char *byte_ptr; |
|
425 |
uint32_t i,j,k; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
426 |
my_bitmap_map *data_ptr, *end= last_word_ptr; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
427 |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
428 |
assert(bitmap); |
429 |
data_ptr= bitmap; |
|
430 |
*last_word_ptr &= ~last_word_mask; |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
431 |
|
432 |
for (i=0; data_ptr <= end; data_ptr++, i++) |
|
433 |
{
|
|
434 |
if (*data_ptr) |
|
435 |
{
|
|
436 |
byte_ptr= (unsigned char*)data_ptr; |
|
437 |
for (j=0; ; j++, byte_ptr++) |
|
438 |
{
|
|
439 |
if (*byte_ptr) |
|
440 |
{
|
|
441 |
for (k=0; ; k++) |
|
442 |
{
|
|
443 |
if (*byte_ptr & (1 << k)) |
|
444 |
return (i*32) + (j*8) + k; |
|
445 |
}
|
|
446 |
}
|
|
447 |
}
|
|
448 |
}
|
|
449 |
}
|
|
450 |
return MY_BIT_NONE; |
|
451 |
}
|
|
452 |
||
453 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
454 |
uint32_t MyBitmap::getFirst() |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
455 |
{
|
456 |
unsigned char *byte_ptr; |
|
457 |
uint32_t i,j,k; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
458 |
my_bitmap_map *data_ptr, *end= last_word_ptr; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
459 |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
460 |
assert(bitmap); |
461 |
data_ptr= bitmap; |
|
462 |
*last_word_ptr|= last_word_mask; |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
463 |
|
464 |
for (i=0; data_ptr <= end; data_ptr++, i++) |
|
465 |
{
|
|
466 |
if (*data_ptr != 0xFFFFFFFF) |
|
467 |
{
|
|
468 |
byte_ptr= (unsigned char*)data_ptr; |
|
469 |
for (j=0; ; j++, byte_ptr++) |
|
470 |
{
|
|
471 |
if (*byte_ptr != 0xFF) |
|
472 |
{
|
|
473 |
for (k=0; ; k++) |
|
474 |
{
|
|
475 |
if (!(*byte_ptr & (1 << k))) |
|
476 |
return (i*32) + (j*8) + k; |
|
477 |
}
|
|
478 |
}
|
|
479 |
}
|
|
480 |
}
|
|
481 |
}
|
|
482 |
return MY_BIT_NONE; |
|
483 |
}
|
|
484 |
||
485 |
||
486 |
#ifdef MAIN
|
|
487 |
||
488 |
uint32_t get_rand_bit(uint32_t bitsize) |
|
489 |
{
|
|
490 |
return (rand() % bitsize); |
|
491 |
}
|
|
492 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
493 |
bool test_set_get_clear_bit(MyBitmap *map, uint32_t bitsize) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
494 |
{
|
495 |
uint32_t i, test_bit; |
|
496 |
uint32_t no_loops= bitsize > 128 ? 128 : bitsize; |
|
497 |
for (i=0; i < no_loops; i++) |
|
498 |
{
|
|
499 |
test_bit= get_rand_bit(bitsize); |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
500 |
map->setBit(test_bit); |
501 |
if (! map->isBitSet(test_bit)) |
|
502 |
{
|
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
503 |
goto error1; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
504 |
}
|
505 |
map->clearBit(test_bit); |
|
506 |
if (map->isBitSet(test_bit)) |
|
507 |
{
|
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
508 |
goto error2; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
509 |
}
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
510 |
}
|
511 |
return false; |
|
512 |
error1: |
|
513 |
printf("Error in set bit, bit %u, bitsize = %u", test_bit, bitsize); |
|
514 |
return true; |
|
515 |
error2: |
|
516 |
printf("Error in clear bit, bit %u, bitsize = %u", test_bit, bitsize); |
|
517 |
return true; |
|
518 |
}
|
|
519 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
520 |
bool test_flip_bit(MyBitmap *map, uint32_t bitsize) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
521 |
{
|
522 |
uint32_t i, test_bit; |
|
523 |
uint32_t no_loops= bitsize > 128 ? 128 : bitsize; |
|
524 |
for (i=0; i < no_loops; i++) |
|
525 |
{
|
|
526 |
test_bit= get_rand_bit(bitsize); |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
527 |
map->flipBit(test_bit); |
528 |
if (!map->isBitSet(test_bit)) |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
529 |
goto error1; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
530 |
map->flipBit(test_bit); |
531 |
if (map->isBitSet(test_bit)) |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
532 |
goto error2; |
533 |
}
|
|
534 |
return false; |
|
535 |
error1: |
|
536 |
printf("Error in flip bit 1, bit %u, bitsize = %u", test_bit, bitsize); |
|
537 |
return true; |
|
538 |
error2: |
|
539 |
printf("Error in flip bit 2, bit %u, bitsize = %u", test_bit, bitsize); |
|
540 |
return true; |
|
541 |
}
|
|
542 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
543 |
bool test_operators(MyBitmap *, uint32_t) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
544 |
{
|
545 |
return false; |
|
546 |
}
|
|
547 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
548 |
bool test_get_all_bits(MyBitmap *map, uint32_t bitsize) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
549 |
{
|
550 |
uint32_t i; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
551 |
map->setAll(); |
552 |
if (!map->isSetAll()) |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
553 |
goto error1; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
554 |
if (!map->isPrefix(bitsize)) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
555 |
goto error5; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
556 |
map->clearAll(); |
557 |
if (!map->isClearAll()) |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
558 |
goto error2; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
559 |
if (!map->isPrefix(0)) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
560 |
goto error6; |
561 |
for (i=0; i<bitsize;i++) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
562 |
map->setBit(i); |
563 |
if (!map->isSetAll()) |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
564 |
goto error3; |
565 |
for (i=0; i<bitsize;i++) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
566 |
map->clearBit(i); |
567 |
if (!map->isClearAll()) |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
568 |
goto error4; |
569 |
return false; |
|
570 |
error1: |
|
571 |
printf("Error in set_all, bitsize = %u", bitsize); |
|
572 |
return true; |
|
573 |
error2: |
|
574 |
printf("Error in clear_all, bitsize = %u", bitsize); |
|
575 |
return true; |
|
576 |
error3: |
|
577 |
printf("Error in bitmap_is_set_all, bitsize = %u", bitsize); |
|
578 |
return true; |
|
579 |
error4: |
|
580 |
printf("Error in bitmap_is_clear_all, bitsize = %u", bitsize); |
|
581 |
return true; |
|
582 |
error5: |
|
583 |
printf("Error in set_all through set_prefix, bitsize = %u", bitsize); |
|
584 |
return true; |
|
585 |
error6: |
|
586 |
printf("Error in clear_all through set_prefix, bitsize = %u", bitsize); |
|
587 |
return true; |
|
588 |
}
|
|
589 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
590 |
bool test_compare_operators(MyBitmap *map, uint32_t bitsize) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
591 |
{
|
592 |
uint32_t i, j, test_bit1, test_bit2, test_bit3,test_bit4; |
|
593 |
uint32_t no_loops= bitsize > 128 ? 128 : bitsize; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
594 |
MyBitmap map2_obj, map3_obj; |
595 |
MyBitmap *map2= &map2_obj, *map3= &map3_obj; |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
596 |
my_bitmap_map map2buf[1024]; |
597 |
my_bitmap_map map3buf[1024]; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
598 |
map2_obj.init(map2buf, bitsize); |
599 |
map3_obj.init(map3buf, bitsize); |
|
600 |
map2->clearAll(); |
|
601 |
map3->clearAll(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
602 |
for (i=0; i < no_loops; i++) |
603 |
{
|
|
604 |
test_bit1=get_rand_bit(bitsize); |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
605 |
map->setPrefix(test_bit1); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
606 |
test_bit2=get_rand_bit(bitsize); |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
607 |
map2->setPrefix(test_bit2); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
608 |
bitmap_intersect(map, map2); |
609 |
test_bit3= test_bit2 < test_bit1 ? test_bit2 : test_bit1; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
610 |
map3->setPrefix(test_bit3); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
611 |
if (!bitmap_cmp(map, map3)) |
612 |
goto error1; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
613 |
map->clearAll(); |
614 |
map2->clearAll(); |
|
615 |
map3->clearAll(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
616 |
test_bit1=get_rand_bit(bitsize); |
617 |
test_bit2=get_rand_bit(bitsize); |
|
618 |
test_bit3=get_rand_bit(bitsize); |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
619 |
map->setPrefix(test_bit1); |
620 |
map2->setPrefix(test_bit2); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
621 |
test_bit3= test_bit2 > test_bit1 ? test_bit2 : test_bit1; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
622 |
map3->setPrefix(test_bit3); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
623 |
bitmap_union(map, map2); |
624 |
if (!bitmap_cmp(map, map3)) |
|
625 |
goto error2; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
626 |
map->clearAll(); |
627 |
map2->clearAll(); |
|
628 |
map3->clearAll(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
629 |
test_bit1=get_rand_bit(bitsize); |
630 |
test_bit2=get_rand_bit(bitsize); |
|
631 |
test_bit3=get_rand_bit(bitsize); |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
632 |
map->setPrefix(test_bit1); |
633 |
map2->setPrefix(test_bit2); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
634 |
bitmap_xor(map, map2); |
635 |
test_bit3= test_bit2 > test_bit1 ? test_bit2 : test_bit1; |
|
636 |
test_bit4= test_bit2 < test_bit1 ? test_bit2 : test_bit1; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
637 |
map3->setPrefix(test_bit3); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
638 |
for (j=0; j < test_bit4; j++) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
639 |
map3->clearBit(j); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
640 |
if (!bitmap_cmp(map, map3)) |
641 |
goto error3; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
642 |
map->clearAll(); |
643 |
map2->clearAll(); |
|
644 |
map3->clearAll(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
645 |
test_bit1=get_rand_bit(bitsize); |
646 |
test_bit2=get_rand_bit(bitsize); |
|
647 |
test_bit3=get_rand_bit(bitsize); |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
648 |
map->setPrefix(test_bit1); |
649 |
map2->setPrefix(test_bit2); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
650 |
bitmap_subtract(map, map2); |
651 |
if (test_bit2 < test_bit1) |
|
652 |
{
|
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
653 |
map3->setPrefix(test_bit1); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
654 |
for (j=0; j < test_bit2; j++) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
655 |
map3->clearBit(j); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
656 |
}
|
657 |
if (!bitmap_cmp(map, map3)) |
|
658 |
goto error4; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
659 |
map->clearAll(); |
660 |
map2->clearAll(); |
|
661 |
map3->clearAll(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
662 |
test_bit1=get_rand_bit(bitsize); |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
663 |
map->setPrefix(test_bit1); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
664 |
bitmap_invert(map); |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
665 |
map3->setAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
666 |
for (j=0; j < test_bit1; j++) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
667 |
map3->clearBit(j); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
668 |
if (!bitmap_cmp(map, map3)) |
669 |
goto error5; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
670 |
map->clearAll(); |
671 |
map3->clearAll(); |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
672 |
}
|
673 |
return false; |
|
674 |
error1: |
|
675 |
printf("intersect error bitsize=%u,size1=%u,size2=%u", bitsize, |
|
676 |
test_bit1,test_bit2); |
|
677 |
return true; |
|
678 |
error2: |
|
679 |
printf("union error bitsize=%u,size1=%u,size2=%u", bitsize, |
|
680 |
test_bit1,test_bit2); |
|
681 |
return true; |
|
682 |
error3: |
|
683 |
printf("xor error bitsize=%u,size1=%u,size2=%u", bitsize, |
|
684 |
test_bit1,test_bit2); |
|
685 |
return true; |
|
686 |
error4: |
|
687 |
printf("subtract error bitsize=%u,size1=%u,size2=%u", bitsize, |
|
688 |
test_bit1,test_bit2); |
|
689 |
return true; |
|
690 |
error5: |
|
691 |
printf("invert error bitsize=%u,size=%u", bitsize, |
|
692 |
test_bit1); |
|
693 |
return true; |
|
694 |
}
|
|
695 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
696 |
bool test_count_bits_set(MyBitmap *map, uint32_t bitsize) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
697 |
{
|
698 |
uint32_t i, bit_count=0, test_bit; |
|
699 |
uint32_t no_loops= bitsize > 128 ? 128 : bitsize; |
|
700 |
for (i=0; i < no_loops; i++) |
|
701 |
{
|
|
702 |
test_bit=get_rand_bit(bitsize); |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
703 |
if (!map->isBitSet(test_bit)) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
704 |
{
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
705 |
map->setBit(test_bit); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
706 |
bit_count++; |
707 |
}
|
|
708 |
}
|
|
709 |
if (bit_count==0 && bitsize > 0) |
|
710 |
goto error1; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
711 |
if (getBitsSet() != bit_count) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
712 |
goto error2; |
713 |
return false; |
|
714 |
error1: |
|
715 |
printf("No bits set bitsize = %u", bitsize); |
|
716 |
return true; |
|
717 |
error2: |
|
718 |
printf("Wrong count of bits set, bitsize = %u", bitsize); |
|
719 |
return true; |
|
720 |
}
|
|
721 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
722 |
bool test_get_first_bit(MyBitmap *map, uint32_t bitsize) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
723 |
{
|
724 |
uint32_t i, test_bit; |
|
725 |
uint32_t no_loops= bitsize > 128 ? 128 : bitsize; |
|
726 |
for (i=0; i < no_loops; i++) |
|
727 |
{
|
|
728 |
test_bit=get_rand_bit(bitsize); |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
729 |
map->setBit(test_bit); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
730 |
if (bitmap_get_first_set(map) != test_bit) |
731 |
goto error1; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
732 |
map->setAll(); |
733 |
map->clearBit(test_bit); |
|
734 |
if (getFirst() != test_bit) |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
735 |
goto error2; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
736 |
map->clearAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
737 |
}
|
738 |
return false; |
|
739 |
error1: |
|
740 |
printf("get_first_set error bitsize=%u,prefix_size=%u",bitsize,test_bit); |
|
741 |
return true; |
|
742 |
error2: |
|
743 |
printf("get_first error bitsize= %u, prefix_size= %u",bitsize,test_bit); |
|
744 |
return true; |
|
745 |
}
|
|
746 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
747 |
bool test_get_next_bit(MyBitmap *map, uint32_t bitsize) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
748 |
{
|
749 |
uint32_t i, j, test_bit; |
|
750 |
uint32_t no_loops= bitsize > 128 ? 128 : bitsize; |
|
751 |
for (i=0; i < no_loops; i++) |
|
752 |
{
|
|
753 |
test_bit=get_rand_bit(bitsize); |
|
754 |
for (j=0; j < test_bit; j++) |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
755 |
setNext(); |
756 |
if (!map->isPrefix(test_bit)) |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
757 |
goto error1; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
758 |
map->clearAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
759 |
}
|
760 |
return false; |
|
761 |
error1: |
|
762 |
printf("get_next error bitsize= %u, prefix_size= %u", bitsize,test_bit); |
|
763 |
return true; |
|
764 |
}
|
|
765 |
||
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
766 |
bool test_prefix(MyBitmap *map, uint32_t bitsize) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
767 |
{
|
768 |
uint32_t i, j, test_bit; |
|
769 |
uint32_t no_loops= bitsize > 128 ? 128 : bitsize; |
|
770 |
for (i=0; i < no_loops; i++) |
|
771 |
{
|
|
772 |
test_bit=get_rand_bit(bitsize); |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
773 |
map->setPrefix(map, test_bit); |
774 |
if (!map->isPrefix(test_bit)) |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
775 |
goto error1; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
776 |
map->clearAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
777 |
for (j=0; j < test_bit; j++) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
778 |
map->setBit(j); |
779 |
if (!map->isPrefix(test_bit)) |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
780 |
goto error2; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
781 |
map->setAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
782 |
for (j=bitsize - 1; ~(j-test_bit); j--) |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
783 |
map->clearBit(j); |
784 |
if (!map->isPrefix(test_bit)) |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
785 |
goto error3; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
786 |
map->clearAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
787 |
}
|
788 |
return false; |
|
789 |
error1: |
|
790 |
printf("prefix1 error bitsize = %u, prefix_size = %u", bitsize,test_bit); |
|
791 |
return true; |
|
792 |
error2: |
|
793 |
printf("prefix2 error bitsize = %u, prefix_size = %u", bitsize,test_bit); |
|
794 |
return true; |
|
795 |
error3: |
|
796 |
printf("prefix3 error bitsize = %u, prefix_size = %u", bitsize,test_bit); |
|
797 |
return true; |
|
798 |
}
|
|
799 |
||
800 |
||
801 |
bool do_test(uint32_t bitsize) |
|
802 |
{
|
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
803 |
MyBitmap map; |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
804 |
my_bitmap_map buf[1024]; |
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
805 |
if (map.init(buf, bitsize)) |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
806 |
{
|
807 |
printf("init error for bitsize %d", bitsize); |
|
808 |
goto error; |
|
809 |
}
|
|
810 |
if (test_set_get_clear_bit(&map,bitsize)) |
|
811 |
goto error; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
812 |
map.clearAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
813 |
if (test_flip_bit(&map,bitsize)) |
814 |
goto error; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
815 |
map.clearAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
816 |
if (test_operators(&map,bitsize)) |
817 |
goto error; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
818 |
map.clearAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
819 |
if (test_get_all_bits(&map, bitsize)) |
820 |
goto error; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
821 |
map.clearAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
822 |
if (test_compare_operators(&map,bitsize)) |
823 |
goto error; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
824 |
map.clearAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
825 |
if (test_count_bits_set(&map,bitsize)) |
826 |
goto error; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
827 |
map.clearAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
828 |
if (test_get_first_bit(&map,bitsize)) |
829 |
goto error; |
|
1103.6.1
by Padraig O'Sullivan
Converted MY_BITMAP from a struct to a class named MyBitmap. Added a copy |
830 |
map.clearAll(); |
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
831 |
if (test_get_next_bit(&map,bitsize)) |
832 |
goto error; |
|
833 |
if (test_prefix(&map,bitsize)) |
|
834 |
goto error; |
|
835 |
return false; |
|
836 |
error: |
|
837 |
printf("\n"); |
|
838 |
return true; |
|
839 |
}
|
|
840 |
||
841 |
int main() |
|
842 |
{
|
|
843 |
int i; |
|
844 |
for (i= 1; i < 4096; i++) |
|
845 |
{
|
|
846 |
printf("Start test for bitsize=%u\n",i); |
|
847 |
if (do_test(i)) |
|
848 |
return -1; |
|
849 |
}
|
|
850 |
printf("OK\n"); |
|
851 |
return 0; |
|
852 |
}
|
|
853 |
||
854 |
/*
|
|
855 |
In directory mysys:
|
|
856 |
make test_bitmap
|
|
857 |
will build the bitmap tests and ./test_bitmap will execute it
|
|
858 |
*/
|
|
859 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
860 |
|
1005.2.1
by Monty Taylor
Reverted a crap-ton of padraig's work. |
861 |
#endif
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
862 |
|
863 |
} /* namespace drizzled */ |