summaryrefslogtreecommitdiff
path: root/src/packedintarray.h
blob: a865df5f3efdae8cc139077c7b786cb89ec634f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef PACKED_INT_ARRAY_H
#define PACKED_INT_ARRAY_H

#include <bu/string.h>

class PackedIntArray
{
public:
    typedef uint_fast8_t Unit;
    PackedIntArray( Unit iBitWidth );
    PackedIntArray( Unit iBitWidth, int iCapacity );
    PackedIntArray( const PackedIntArray &rSrc );
    virtual ~PackedIntArray();

    void clear();
    void append( Unit i );
    void remove();
    Unit operator[]( int idx ) const { return get( idx ); }
    Unit get( int idx ) const;
    void set( int idx, Unit i );
    int getSize() const { return iCount; }
    void set( const PackedIntArray &rSrc, int iStart, int iSize );

    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