951c3eefacedcdbdb2cebf245f043aa3e81fb483 |
|
31-Jul-2015 |
Martin Mikkelsen <mamikk@mamikk.no> |
bitmap: make bitmap_clear free the bitmap array
Given two bitmaps and the following code:
Bitmap *a = bitmap_new(), *b = bitmap_new();
bitmap_set(a, 1);
bitmap_clear(a);
bitmap_set(a, 0);
bitmap_set(b, 0);
These two bitmaps should now have the same bits set and they should be
equal but bitmap_equal() will return false in this case because while
bitmap_clear() resets the number of elements in the array it does not
clear the array and bitmap_set() expects the array to be cleared.
GREEDY_REALLOC0 looks at the allocated size and not the actual size so
it does not clear any memory.
Fix this by freeing the allocated memory and resetting the whole Bitmap
to an initial state in bitmap_clear().
This also adds test code for this issue. |
d5fa81995849cb263ecfcd0aa6ab661360d9213e |
|
31-Jul-2015 |
Martin Mikkelsen <mamikk@mamikk.no> |
bitmap: fix bitmap_equal on bitmaps with unset bits
Given two bitmaps and the following code:
Bitmap *a = bitmap_new(), *b = bitmap_new();
bitmap_set(a, 0);
bitmap_unset(a, 0);
These two bitmaps should now have the same bits set and they should be
equal but bitmap_equal() will return false in this case because the
bitmaps array in a is larger because of the bit which was previously
set.
Fix this by comparing only the bits which exists in both bitmaps and
then check that the rest of the bits (if any) is all zero.
This also adds test code for this issue. |
cdf6f5ae0465a8fb25d2afc758911985cc542a07 |
|
17-Jul-2015 |
Tom Gundersen <teg@jklm.no> |
basic: bitmap - complete fix for bitshift overflow
The bug found by David existed in several places, fix them all. Also
extend the tests to cover these cases. |
cb57dd41595adddb08095298bb1ed258c8ea4877 |
|
16-Jul-2015 |
Tom Gundersen <teg@jklm.no> |
bitmap: use external iterator
Reuse the Iterator object from hashmap.h and expose a similar API.
This allows us to do
{
Iterator i;
unsigned n;
BITMAP_FOREACH(n, b, i) {
Iterator j;
unsigned m;
BITMAP_FOREACH(m, b, j) {
...
}
}
}
without getting confused. Requested by David. |
5ffa42cb8028833440040c2e240e0d788f11c112 |
|
14-Jul-2015 |
Tom Gundersen <teg@jklm.no> |
basic: add a Bitmap implementation
For when a Hashmap is overkill. |