summaryrefslogtreecommitdiff
path: root/src/packedintarray.h
blob: eb7b25adb8ff1bc08753dd4f30958f20424b1fb1 (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
41
42
43
44
45
46
47
#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 zero();
    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 );
    void insert( int idx, Unit i );
    int getSize() const { return iCount; }
    void setSize( int iNewSize );
    void set( const PackedIntArray &rSrc, int iStart, int iSize );
    void set( const PackedIntArray &rSrc );
    void copy( int iDest, const PackedIntArray &rSrc, int iStart, int iSize );
    void trim();
    int getBitWidth() const { return iBitWidth; }

    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