summaryrefslogtreecommitdiff
path: root/src/packedintarray.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/packedintarray.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/packedintarray.cpp b/src/packedintarray.cpp
index 817a7ab..7654356 100644
--- a/src/packedintarray.cpp
+++ b/src/packedintarray.cpp
@@ -41,11 +41,28 @@ PackedIntArray::PackedIntArray( PackedIntArray::Unit iBitWidth, int iCount ):
41 uMask |= (1<<j); 41 uMask |= (1<<j);
42} 42}
43 43
44PackedIntArray::PackedIntArray( const PackedIntArray &rSrc ) :
45 iBitWidth( rSrc.iBitWidth ),
46 aData( NULL ),
47 iCapacity( rSrc.iCapacity ),
48 iCount( rSrc.iCount ),
49 uMask( rSrc.uMask )
50{
51 int iSize = StoreCount(iCapacity);
52 aData = new Store[iSize];
53 memcpy( aData, rSrc.aData, iSize*sizeof(Store) );
54}
55
44PackedIntArray::~PackedIntArray() 56PackedIntArray::~PackedIntArray()
45{ 57{
46 delete[] aData; 58 delete[] aData;
47} 59}
48 60
61void PackedIntArray::clear()
62{
63 iCount = 0;
64}
65
49void PackedIntArray::append( PackedIntArray::Unit i ) 66void PackedIntArray::append( PackedIntArray::Unit i )
50{ 67{
51 iCount++; 68 iCount++;
@@ -53,6 +70,12 @@ void PackedIntArray::append( PackedIntArray::Unit i )
53 set( iCount-1, i ); 70 set( iCount-1, i );
54} 71}
55 72
73void PackedIntArray::remove()
74{
75 if( iCount > 0 )
76 iCount--;
77}
78
56PackedIntArray::Unit PackedIntArray::get( int idx ) const 79PackedIntArray::Unit PackedIntArray::get( int idx ) const
57{ 80{
58 int iStore = idx*iBitWidth/StoreBits; 81 int iStore = idx*iBitWidth/StoreBits;
@@ -121,12 +144,12 @@ void PackedIntArray::checkCapacity()
121{ 144{
122 if( iCount > iCapacity ) 145 if( iCount > iCapacity )
123 { 146 {
124 Bu::println("!!! Resizing !!!"); 147// Bu::println("!!! Resizing !!!");
125 Store *aOldData = aData; 148 Store *aOldData = aData;
126 int iNewSize = StoreCount(iCapacity*2); 149 int iNewSize = StoreCount(iCapacity*2);
127 int iSize = StoreCount(iCapacity); 150 int iSize = StoreCount(iCapacity);
128 Bu::println(" %1 => %2 (%3 bit words)").arg( iSize ).arg( iNewSize ) 151// Bu::println(" %1 => %2 (%3 bit words)").arg( iSize ).arg( iNewSize )
129 .arg( StoreBits ); 152// .arg( StoreBits );
130 aData = new Store[iNewSize]; 153 aData = new Store[iNewSize];
131 memset( aData, 0, iNewSize*sizeof(Store) ); 154 memset( aData, 0, iNewSize*sizeof(Store) );
132 memcpy( aData, aOldData, iSize*sizeof(Store) ); 155 memcpy( aData, aOldData, iSize*sizeof(Store) );