summaryrefslogtreecommitdiff
path: root/src/packedintarray.h
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2013-04-15 15:28:12 -0600
committerMike Buland <mike@xagasoft.com>2013-04-15 15:28:12 -0600
commitf34eb76357fdfc314d6451fd11a2e4d6fcfce434 (patch)
treed4769ae51a1c703b0e55af0ef38a31991f9f7c3a /src/packedintarray.h
downloadclic-f34eb76357fdfc314d6451fd11a2e4d6fcfce434.tar.gz
clic-f34eb76357fdfc314d6451fd11a2e4d6fcfce434.tar.bz2
clic-f34eb76357fdfc314d6451fd11a2e4d6fcfce434.tar.xz
clic-f34eb76357fdfc314d6451fd11a2e4d6fcfce434.zip
Initial checkin.
This project will most likely just be stuck into libbu++, but I didn't want to deal with building it all in windows.
Diffstat (limited to 'src/packedintarray.h')
-rw-r--r--src/packedintarray.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/packedintarray.h b/src/packedintarray.h
new file mode 100644
index 0000000..953492b
--- /dev/null
+++ b/src/packedintarray.h
@@ -0,0 +1,36 @@
1#ifndef PACKED_INT_ARRAY_H
2#define PACKED_INT_ARRAY_H
3
4#include <bu/string.h>
5
6class PackedIntArray
7{
8public:
9 typedef uint_fast8_t Unit;
10 PackedIntArray( Unit iBitWidth );
11 PackedIntArray( Unit iBitWidth, int iCapacity );
12 virtual ~PackedIntArray();
13
14 void append( Unit i );
15 Unit operator[]( int idx ) const { return get( idx ); }
16 Unit get( int idx ) const;
17 Unit set( int idx, Unit i );
18 int getSize() const { return iCount; }
19
20 Bu::String toBitString() const;
21 Bu::String toString() const;
22
23private:
24 void checkCapacity();
25
26private:
27 typedef uint_fast32_t Store;
28 Unit iBitWidth;
29 Store *aData;
30 int iCapacity;
31 int iCount;
32 int iMaxSpan;
33 Unit uMask;
34};
35
36#endif