From 9f138260dafeb5a1b541fff8dd577422439feb0b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 23 Apr 2013 10:25:26 -0600 Subject: Fixed random zeros bug. They weren't that random, the resize routine in PackedIntArray was written poorly. It was growing too much and computing the size of the original array incorrectly, so not all the data was being copied every time. --- src/packedintarray.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/packedintarray.cpp') diff --git a/src/packedintarray.cpp b/src/packedintarray.cpp index b91358e..824f589 100644 --- a/src/packedintarray.cpp +++ b/src/packedintarray.cpp @@ -4,7 +4,7 @@ #define bitsizeof( x ) ((sizeof(x))*8) #define StoreBits ((bitsizeof(PackedIntArray::Store))) -#define StoreCount( x ) (((x*iBitWidth)/StoreBits)+(((x*iBitWidth)%StoreBits)?1:0)) +#define StoreCount( x ) ((((x)*iBitWidth)/StoreBits)+((((x)*iBitWidth)%StoreBits)?1:0)) PackedIntArray::PackedIntArray( PackedIntArray::Unit iBitWidth ) : iBitWidth( iBitWidth ), @@ -207,10 +207,11 @@ void PackedIntArray::checkCapacity() { // Bu::println("!!! Resizing !!!"); Store *aOldData = aData; + int iSize = StoreCount(iCapacity); int iNewSize = (iCapacity==0)?(bitsizeof(Store)/iBitWidth):(iCapacity=StoreCount(iCapacity*2)); - while( iNewSize < iCount ) + int iCountSize = StoreCount(iCount); + while( iNewSize < iCountSize ) iNewSize *= 2; - int iSize = StoreCount(iCapacity); // Bu::println(" %1 => %2 (%3 bit words)").arg( iSize ).arg( iNewSize ) // .arg( StoreBits ); aData = new Store[iNewSize]; -- cgit v1.2.3