00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _UT_BitArray_
00021 #define _UT_BitArray_
00022
00023 #include "UT_API.h"
00024 #include <SYS/SYS_Types.h>
00025 #include <iostream.h>
00026
00027 class UT_IStream;
00028
00029
00030
00031
00032 class UT_API UT_BitArray {
00033 public:
00034 UT_BitArray();
00035 UT_BitArray(const UT_BitArray &src);
00036 explicit UT_BitArray(int size);
00037 ~UT_BitArray();
00038
00039 void insert(int index, bool value);
00040 void append(bool value) { insert(myBitCount, value); }
00041 void remove(int index);
00042
00043 void resize(int size);
00044 int getSize() const { return myBitCount; }
00045
00046 int numBitsSet() const;
00047 int numBitsClear() const;
00048
00049 int allBitsSet() const;
00050 int allBitsClear() const;
00051
00052 bool getBit(int index) const;
00053 bool setBit(int index, bool value);
00054 bool toggleBit(int index);
00055
00056 void setBits(int index, int nbits, bool value);
00057 void toggleBits(int index, int nbits);
00058
00059 void setAllBits(bool value);
00060 void toggleAllBits();
00061
00062
00063 int save(ostream &os, int binary = 0) const;
00064 bool load(UT_IStream &is);
00065
00066
00067
00068
00069
00070
00071
00072 void iterateInit(int ¤tBit) const;
00073 int iterateNext(int currentBit) const;
00074
00075
00076
00077
00078 int findFirstBit() const;
00079 int findLastBit() const;
00080
00081
00082
00083 int operator()(int index) const { return getBit(index); }
00084 int operator[](int index) const { return getBit(index); }
00085 UT_BitArray &operator&=(const UT_BitArray &inMap);
00086 UT_BitArray &operator|=(const UT_BitArray &inMap);
00087 UT_BitArray &operator^=(const UT_BitArray &inMap);
00088 UT_BitArray &operator-=(const UT_BitArray &inMap);
00089 UT_BitArray &operator=(const UT_BitArray &inMap);
00090 unsigned operator==(const UT_BitArray &inMap) const;
00091
00092
00093 bool intersects(const UT_BitArray &inMap) const;
00094
00095 int64 getMemoryUsage() const
00096 { return (sizeof(*this) + myWordCount*sizeof(int)); }
00097
00098 uint computeHash() const;
00099
00100 private:
00101 unsigned int *myBits;
00102 int myBitCount;
00103 int myWordCount;
00104
00105 #ifdef DEBUG
00106 void outTo(ostream &os) const;
00107 friend ostream &operator<<(ostream &os, const UT_BitArray &map)
00108 {
00109 map.outTo(os);
00110 return os;
00111 }
00112 #endif
00113 };
00114 #endif