diff options
author | Mike Buland <mike@xagasoft.com> | 2013-04-15 23:45:48 -0600 |
---|---|---|
committer | Mike Buland <mike@xagasoft.com> | 2013-04-15 23:45:48 -0600 |
commit | 44542adf023315d60a8ffc4863f2b161b3c1eb90 (patch) | |
tree | 3500c1d6cfa3e5670bde199e24125c4b8e0c33db /src/packedintarray.cpp | |
parent | f34eb76357fdfc314d6451fd11a2e4d6fcfce434 (diff) | |
download | clic-44542adf023315d60a8ffc4863f2b161b3c1eb90.tar.gz clic-44542adf023315d60a8ffc4863f2b161b3c1eb90.tar.bz2 clic-44542adf023315d60a8ffc4863f2b161b3c1eb90.tar.xz clic-44542adf023315d60a8ffc4863f2b161b3c1eb90.zip |
Addition, subtraction, and multiplication work now
Division isn't working yet, there are too many options, I'll figure out
something eventually :-P
Diffstat (limited to 'src/packedintarray.cpp')
-rw-r--r-- | src/packedintarray.cpp | 29 |
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 | ||
44 | PackedIntArray::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 | |||
44 | PackedIntArray::~PackedIntArray() | 56 | PackedIntArray::~PackedIntArray() |
45 | { | 57 | { |
46 | delete[] aData; | 58 | delete[] aData; |
47 | } | 59 | } |
48 | 60 | ||
61 | void PackedIntArray::clear() | ||
62 | { | ||
63 | iCount = 0; | ||
64 | } | ||
65 | |||
49 | void PackedIntArray::append( PackedIntArray::Unit i ) | 66 | void 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 | ||
73 | void PackedIntArray::remove() | ||
74 | { | ||
75 | if( iCount > 0 ) | ||
76 | iCount--; | ||
77 | } | ||
78 | |||
56 | PackedIntArray::Unit PackedIntArray::get( int idx ) const | 79 | PackedIntArray::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) ); |