00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __UT_RLEBitArray__
00023 #define __UT_RLEBitArray__
00024
00025 #include "UT_API.h"
00026 #include <limits.h>
00027 #include "UT_LinkList.h"
00028 #include "UT_Algorithm.h"
00029
00030 class UT_API UT_RLEBitArray
00031 {
00032 public:
00033 enum { LOWEST_INDEX = INT_MIN };
00034
00035 UT_RLEBitArray();
00036 ~UT_RLEBitArray();
00037
00038 void swap( UT_RLEBitArray &other );
00039
00040
00041
00042 int numBitsSet() const;
00043
00044 int getBit(int idx) const;
00045 bool getBitRun(int idx, int &start, int &end) const;
00046
00047 void setBitTrue(int idx);
00048 void setBitFalse(int idx);
00049 void setBit( int idx, int value)
00050 {
00051 if( value )
00052 setBitTrue( idx );
00053 else
00054 setBitFalse( idx );
00055 }
00056 void setBitRunTrue( int start, int end );
00057
00058 int toggleBit(int idx);
00059
00060 void clear();
00061 bool isEmpty() const;
00062 int getNextRun(int &start, int &end, bool first=false);
00063
00064
00065
00066
00067
00068
00069
00070
00071 bool iterate( int ¤tBit );
00072
00073 int64 getMemoryUsage() const;
00074
00075 void display() const;
00076
00077
00078 int operator()(int index) const { return getBit(index); }
00079 int operator[](int index) const { return getBit(index); }
00080
00081 const UT_RLEBitArray&operator&=(const UT_RLEBitArray &v);
00082
00083 const UT_RLEBitArray&operator|=(const UT_RLEBitArray &v);
00084
00085 const UT_RLEBitArray&operator^=(const UT_RLEBitArray &v);
00086
00087 const UT_RLEBitArray&operator-=(const UT_RLEBitArray &v);
00088 const UT_RLEBitArray&operator= (const UT_RLEBitArray &v);
00089 int operator==(const UT_RLEBitArray &v) const;
00090 int operator!=(const UT_RLEBitArray &v) const;
00091
00092 protected:
00093 void restartSearch() const;
00094 void restartSearchForIndex( int idx ) const;
00095 void advanceSearchNode() const;
00096
00097 class Node;
00098
00099 UT_LinkList myList;
00100 mutable Node *mySearchNode;
00101 mutable int myLastIndex;
00102 };
00103
00104 UT_SWAPPER_CLASS( UT_RLEBitArray )
00105
00106 #endif