From f34eb76357fdfc314d6451fd11a2e4d6fcfce434 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 15 Apr 2013 15:28:12 -0600 Subject: 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. --- src/packedintarray.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/packedintarray.h (limited to 'src/packedintarray.h') 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 @@ +#ifndef PACKED_INT_ARRAY_H +#define PACKED_INT_ARRAY_H + +#include + +class PackedIntArray +{ +public: + typedef uint_fast8_t Unit; + PackedIntArray( Unit iBitWidth ); + PackedIntArray( Unit iBitWidth, int iCapacity ); + virtual ~PackedIntArray(); + + void append( Unit i ); + Unit operator[]( int idx ) const { return get( idx ); } + Unit get( int idx ) const; + Unit set( int idx, Unit i ); + int getSize() const { return iCount; } + + Bu::String toBitString() const; + Bu::String toString() const; + +private: + void checkCapacity(); + +private: + typedef uint_fast32_t Store; + Unit iBitWidth; + Store *aData; + int iCapacity; + int iCount; + int iMaxSpan; + Unit uMask; +}; + +#endif -- cgit v1.2.3