diff options
author | Mike Buland <mike@xagasoft.com> | 2013-04-23 10:25:26 -0600 |
---|---|---|
committer | Mike Buland <mike@xagasoft.com> | 2013-04-23 10:25:26 -0600 |
commit | 9f138260dafeb5a1b541fff8dd577422439feb0b (patch) | |
tree | 148cecf83d8af00679fdde57a6b31a18f65e0296 /src/packedintarray.cpp | |
parent | e6401f9af190cfbaaab1dc5589546ba5cc2f5293 (diff) | |
download | clic-9f138260dafeb5a1b541fff8dd577422439feb0b.tar.gz clic-9f138260dafeb5a1b541fff8dd577422439feb0b.tar.bz2 clic-9f138260dafeb5a1b541fff8dd577422439feb0b.tar.xz clic-9f138260dafeb5a1b541fff8dd577422439feb0b.zip |
Fixed random zeros bug.0.03
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.
Diffstat (limited to 'src/packedintarray.cpp')
-rw-r--r-- | src/packedintarray.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
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 @@ | |||
4 | 4 | ||
5 | #define bitsizeof( x ) ((sizeof(x))*8) | 5 | #define bitsizeof( x ) ((sizeof(x))*8) |
6 | #define StoreBits ((bitsizeof(PackedIntArray::Store))) | 6 | #define StoreBits ((bitsizeof(PackedIntArray::Store))) |
7 | #define StoreCount( x ) (((x*iBitWidth)/StoreBits)+(((x*iBitWidth)%StoreBits)?1:0)) | 7 | #define StoreCount( x ) ((((x)*iBitWidth)/StoreBits)+((((x)*iBitWidth)%StoreBits)?1:0)) |
8 | 8 | ||
9 | PackedIntArray::PackedIntArray( PackedIntArray::Unit iBitWidth ) : | 9 | PackedIntArray::PackedIntArray( PackedIntArray::Unit iBitWidth ) : |
10 | iBitWidth( iBitWidth ), | 10 | iBitWidth( iBitWidth ), |
@@ -207,10 +207,11 @@ void PackedIntArray::checkCapacity() | |||
207 | { | 207 | { |
208 | // Bu::println("!!! Resizing !!!"); | 208 | // Bu::println("!!! Resizing !!!"); |
209 | Store *aOldData = aData; | 209 | Store *aOldData = aData; |
210 | int iSize = StoreCount(iCapacity); | ||
210 | int iNewSize = (iCapacity==0)?(bitsizeof(Store)/iBitWidth):(iCapacity=StoreCount(iCapacity*2)); | 211 | int iNewSize = (iCapacity==0)?(bitsizeof(Store)/iBitWidth):(iCapacity=StoreCount(iCapacity*2)); |
211 | while( iNewSize < iCount ) | 212 | int iCountSize = StoreCount(iCount); |
213 | while( iNewSize < iCountSize ) | ||
212 | iNewSize *= 2; | 214 | iNewSize *= 2; |
213 | int iSize = StoreCount(iCapacity); | ||
214 | // Bu::println(" %1 => %2 (%3 bit words)").arg( iSize ).arg( iNewSize ) | 215 | // Bu::println(" %1 => %2 (%3 bit words)").arg( iSize ).arg( iNewSize ) |
215 | // .arg( StoreBits ); | 216 | // .arg( StoreBits ); |
216 | aData = new Store[iNewSize]; | 217 | aData = new Store[iNewSize]; |