Merged conflicts with matej's push
This commit is contained in:
@@ -8,7 +8,7 @@ namespace epics { namespace pvData {
|
||||
initWords(BITS_PER_WORD);
|
||||
}
|
||||
|
||||
BitSet::BitSet(epicsUInt32 nbits) : words(0), wordsLength(0), wordsInUse(0) {
|
||||
BitSet::BitSet(uint32 nbits) : words(0), wordsLength(0), wordsInUse(0) {
|
||||
initWords(nbits);
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace epics { namespace pvData {
|
||||
delete words;
|
||||
}
|
||||
|
||||
void BitSet::initWords(epicsUInt32 nbits) {
|
||||
epicsUInt32 length = (nbits <= 0) ? 1 : wordIndex(nbits-1) + 1;
|
||||
void BitSet::initWords(uint32 nbits) {
|
||||
uint32 length = (nbits <= 0) ? 1 : wordIndex(nbits-1) + 1;
|
||||
if (words) delete words;
|
||||
words = new epicsUInt64[length];
|
||||
bzero(words, sizeof(epicsUInt64)*length);
|
||||
words = new uint64[length];
|
||||
bzero(words, sizeof(uint64)*length);
|
||||
wordsLength = length;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace epics { namespace pvData {
|
||||
return;
|
||||
|
||||
// Traverse the bitset until a used word is found
|
||||
epicsUInt32 i;
|
||||
uint32 i;
|
||||
for (i = wordsInUse-1; i >= 0; i--)
|
||||
if (words[i] != 0)
|
||||
break;
|
||||
@@ -38,67 +38,67 @@ namespace epics { namespace pvData {
|
||||
wordsInUse = i+1; // The new logical size
|
||||
}
|
||||
|
||||
void BitSet::ensureCapacity(epicsUInt32 wordsRequired) {
|
||||
void BitSet::ensureCapacity(uint32 wordsRequired) {
|
||||
if (wordsLength < wordsRequired) {
|
||||
|
||||
// create and copy
|
||||
epicsUInt64* newwords = new epicsUInt64[wordsRequired];
|
||||
bzero(newwords, sizeof(epicsUInt64)*wordsRequired);
|
||||
memcpy(newwords, words, sizeof(epicsUInt64)*wordsLength);
|
||||
uint64* newwords = new uint64[wordsRequired];
|
||||
bzero(newwords, sizeof(uint64)*wordsRequired);
|
||||
memcpy(newwords, words, sizeof(uint64)*wordsLength);
|
||||
if (words) delete words;
|
||||
words = newwords;
|
||||
wordsLength = wordsRequired;
|
||||
}
|
||||
}
|
||||
|
||||
void BitSet::expandTo(epicsUInt32 wordIndex) {
|
||||
epicsUInt32 wordsRequired = wordIndex+1;
|
||||
void BitSet::expandTo(uint32 wordIndex) {
|
||||
uint32 wordsRequired = wordIndex+1;
|
||||
if (wordsInUse < wordsRequired) {
|
||||
ensureCapacity(wordsRequired);
|
||||
wordsInUse = wordsRequired;
|
||||
}
|
||||
}
|
||||
|
||||
void BitSet::flip(epicsUInt32 bitIndex) {
|
||||
void BitSet::flip(uint32 bitIndex) {
|
||||
|
||||
epicsUInt32 wordIdx = wordIndex(bitIndex);
|
||||
uint32 wordIdx = wordIndex(bitIndex);
|
||||
expandTo(wordIdx);
|
||||
|
||||
words[wordIdx] ^= (((epicsUInt64)1) << (bitIndex % BITS_PER_WORD));
|
||||
words[wordIdx] ^= (((uint64)1) << (bitIndex % BITS_PER_WORD));
|
||||
|
||||
recalculateWordsInUse();
|
||||
}
|
||||
|
||||
void BitSet::set(epicsUInt32 bitIndex) {
|
||||
void BitSet::set(uint32 bitIndex) {
|
||||
|
||||
epicsUInt32 wordIdx = wordIndex(bitIndex);
|
||||
uint32 wordIdx = wordIndex(bitIndex);
|
||||
expandTo(wordIdx);
|
||||
|
||||
words[wordIdx] |= (((epicsUInt64)1) << (bitIndex % BITS_PER_WORD));
|
||||
words[wordIdx] |= (((uint64)1) << (bitIndex % BITS_PER_WORD));
|
||||
}
|
||||
|
||||
void BitSet::clear(epicsUInt32 bitIndex) {
|
||||
void BitSet::clear(uint32 bitIndex) {
|
||||
|
||||
epicsUInt32 wordIdx = wordIndex(bitIndex);
|
||||
uint32 wordIdx = wordIndex(bitIndex);
|
||||
if (wordIdx >= wordsInUse)
|
||||
return;
|
||||
|
||||
words[wordIdx] &= ~(((epicsUInt64)1) << (bitIndex % BITS_PER_WORD));
|
||||
words[wordIdx] &= ~(((uint64)1) << (bitIndex % BITS_PER_WORD));
|
||||
|
||||
recalculateWordsInUse();
|
||||
}
|
||||
|
||||
void BitSet::set(epicsUInt32 bitIndex, bool value) {
|
||||
void BitSet::set(uint32 bitIndex, bool value) {
|
||||
if (value)
|
||||
set(bitIndex);
|
||||
else
|
||||
clear(bitIndex);
|
||||
}
|
||||
|
||||
bool BitSet::get(epicsUInt32 bitIndex) const {
|
||||
epicsUInt32 wordIdx = wordIndex(bitIndex);
|
||||
bool BitSet::get(uint32 bitIndex) const {
|
||||
uint32 wordIdx = wordIndex(bitIndex);
|
||||
return ((wordIdx < wordsInUse)
|
||||
&& ((words[wordIdx] & (((epicsUInt64)1) << (bitIndex % BITS_PER_WORD))) != 0));
|
||||
&& ((words[wordIdx] & (((uint64)1) << (bitIndex % BITS_PER_WORD))) != 0));
|
||||
}
|
||||
|
||||
void BitSet::clear() {
|
||||
@@ -106,12 +106,12 @@ namespace epics { namespace pvData {
|
||||
words[--wordsInUse] = 0;
|
||||
}
|
||||
|
||||
epicsUInt32 BitSet::numberOfTrailingZeros(epicsUInt64 i) {
|
||||
uint32 BitSet::numberOfTrailingZeros(uint64 i) {
|
||||
// HD, Figure 5-14
|
||||
epicsUInt32 x, y;
|
||||
uint32 x, y;
|
||||
if (i == 0) return 64;
|
||||
epicsUInt32 n = 63;
|
||||
y = (epicsUInt32)i; if (y != 0) { n = n -32; x = y; } else x = (epicsUInt32)(i>>32);
|
||||
uint32 n = 63;
|
||||
y = (uint32)i; if (y != 0) { n = n -32; x = y; } else x = (uint32)(i>>32);
|
||||
y = x <<16; if (y != 0) { n = n -16; x = y; }
|
||||
y = x << 8; if (y != 0) { n = n - 8; x = y; }
|
||||
y = x << 4; if (y != 0) { n = n - 4; x = y; }
|
||||
@@ -119,7 +119,7 @@ namespace epics { namespace pvData {
|
||||
return n - ((x << 1) >> 31);
|
||||
}
|
||||
|
||||
epicsUInt32 BitSet::bitCount(epicsUInt64 i) {
|
||||
uint32 BitSet::bitCount(uint64 i) {
|
||||
// HD, Figure 5-14
|
||||
i = i - ((i >> 1) & 0x5555555555555555LL);
|
||||
i = (i & 0x3333333333333333LL) + ((i >> 2) & 0x3333333333333333LL);
|
||||
@@ -127,16 +127,16 @@ namespace epics { namespace pvData {
|
||||
i = i + (i >> 8);
|
||||
i = i + (i >> 16);
|
||||
i = i + (i >> 32);
|
||||
return (epicsUInt32)(i & 0x7f);
|
||||
return (uint32)(i & 0x7f);
|
||||
}
|
||||
|
||||
epicsInt32 BitSet::nextSetBit(epicsUInt32 fromIndex) const {
|
||||
int32 BitSet::nextSetBit(uint32 fromIndex) const {
|
||||
|
||||
epicsUInt32 u = wordIndex(fromIndex);
|
||||
uint32 u = wordIndex(fromIndex);
|
||||
if (u >= wordsInUse)
|
||||
return -1;
|
||||
|
||||
epicsUInt64 word = words[u] & (WORD_MASK << (fromIndex % BITS_PER_WORD));
|
||||
uint64 word = words[u] & (WORD_MASK << (fromIndex % BITS_PER_WORD));
|
||||
|
||||
while (true) {
|
||||
if (word != 0)
|
||||
@@ -147,14 +147,14 @@ namespace epics { namespace pvData {
|
||||
}
|
||||
}
|
||||
|
||||
epicsInt32 BitSet::nextClearBit(epicsUInt32 fromIndex) const {
|
||||
int32 BitSet::nextClearBit(uint32 fromIndex) const {
|
||||
// Neither spec nor implementation handle bitsets of maximal length.
|
||||
|
||||
epicsUInt32 u = wordIndex(fromIndex);
|
||||
uint32 u = wordIndex(fromIndex);
|
||||
if (u >= wordsInUse)
|
||||
return fromIndex;
|
||||
|
||||
epicsUInt64 word = ~words[u] & (WORD_MASK << (fromIndex % BITS_PER_WORD));
|
||||
uint64 word = ~words[u] & (WORD_MASK << (fromIndex % BITS_PER_WORD));
|
||||
|
||||
while (true) {
|
||||
if (word != 0)
|
||||
@@ -169,9 +169,9 @@ namespace epics { namespace pvData {
|
||||
return (wordsInUse == 0);
|
||||
}
|
||||
|
||||
epicsUInt32 BitSet::cardinality() const {
|
||||
epicsUInt32 sum = 0;
|
||||
for (epicsUInt32 i = 0; i < wordsInUse; i++)
|
||||
uint32 BitSet::cardinality() const {
|
||||
uint32 sum = 0;
|
||||
for (uint32 i = 0; i < wordsInUse; i++)
|
||||
sum += bitCount(words[i]);
|
||||
return sum;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ namespace epics { namespace pvData {
|
||||
words[--wordsInUse] = 0;
|
||||
|
||||
// Perform logical AND on words in common
|
||||
for (epicsUInt32 i = 0; i < wordsInUse; i++)
|
||||
for (uint32 i = 0; i < wordsInUse; i++)
|
||||
words[i] &= set.words[i];
|
||||
|
||||
recalculateWordsInUse();
|
||||
@@ -192,7 +192,7 @@ namespace epics { namespace pvData {
|
||||
|
||||
BitSet& BitSet::operator|=(const BitSet& set) {
|
||||
|
||||
epicsUInt32 wordsInCommon;
|
||||
uint32 wordsInCommon;
|
||||
if (wordsInUse < set.wordsInUse) {
|
||||
wordsInCommon = wordsInUse;
|
||||
//ensureCapacity(set.wordsInUse);
|
||||
@@ -202,7 +202,7 @@ namespace epics { namespace pvData {
|
||||
wordsInCommon = set.wordsInUse;
|
||||
|
||||
// Perform logical OR on words in common
|
||||
epicsUInt32 i = 0;
|
||||
uint32 i = 0;
|
||||
for (; i < wordsInCommon; i++)
|
||||
words[i] |= set.words[i];
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace epics { namespace pvData {
|
||||
|
||||
BitSet& BitSet::operator^=(const BitSet& set) {
|
||||
|
||||
epicsUInt32 wordsInCommon;
|
||||
uint32 wordsInCommon;
|
||||
if (wordsInUse < set.wordsInUse) {
|
||||
wordsInCommon = wordsInUse;
|
||||
//ensureCapacity(set.wordsInUse);
|
||||
@@ -225,7 +225,7 @@ namespace epics { namespace pvData {
|
||||
wordsInCommon = set.wordsInUse;
|
||||
|
||||
// Perform logical XOR on words in common
|
||||
epicsUInt32 i = 0;
|
||||
uint32 i = 0;
|
||||
for (; i < wordsInCommon; i++)
|
||||
words[i] ^= set.words[i];
|
||||
|
||||
@@ -238,7 +238,7 @@ namespace epics { namespace pvData {
|
||||
|
||||
BitSet& BitSet::operator-=(const BitSet& set) {
|
||||
|
||||
epicsUInt32 wordsInCommon;
|
||||
uint32 wordsInCommon;
|
||||
if (wordsInUse < set.wordsInUse) {
|
||||
wordsInCommon = wordsInUse;
|
||||
//ensureCapacity(set.wordsInUse);
|
||||
@@ -248,7 +248,7 @@ namespace epics { namespace pvData {
|
||||
wordsInCommon = set.wordsInUse;
|
||||
|
||||
// Perform logical (a & !b) on words in common
|
||||
epicsUInt32 i = 0;
|
||||
uint32 i = 0;
|
||||
for (; i < wordsInCommon; i++)
|
||||
words[i] &= ~set.words[i];
|
||||
|
||||
@@ -266,23 +266,23 @@ namespace epics { namespace pvData {
|
||||
if (wordsLength < set.wordsLength)
|
||||
{
|
||||
if (words) delete words;
|
||||
words = new epicsUInt64[set.wordsLength];
|
||||
words = new uint64[set.wordsLength];
|
||||
wordsLength = set.wordsLength;
|
||||
}
|
||||
memcpy(words, set.words, sizeof(epicsUInt64)*set.wordsInUse);
|
||||
memcpy(words, set.words, sizeof(uint64)*set.wordsInUse);
|
||||
wordsInUse = set.wordsInUse;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void BitSet::or_and(const BitSet& set1, const BitSet& set2) {
|
||||
epicsUInt32 inUse = (set1.wordsInUse < set2.wordsInUse) ? set1.wordsInUse : set2.wordsInUse;
|
||||
uint32 inUse = (set1.wordsInUse < set2.wordsInUse) ? set1.wordsInUse : set2.wordsInUse;
|
||||
|
||||
ensureCapacity(inUse);
|
||||
wordsInUse = inUse;
|
||||
|
||||
// Perform logical AND on words in common
|
||||
for (epicsUInt32 i = 0; i < inUse; i++)
|
||||
for (uint32 i = 0; i < inUse; i++)
|
||||
words[i] |= (set1.words[i] & set2.words[i]);
|
||||
|
||||
// recalculateWordsInUse()...
|
||||
@@ -297,7 +297,7 @@ namespace epics { namespace pvData {
|
||||
return false;
|
||||
|
||||
// Check words in use by both BitSets
|
||||
for (epicsUInt32 i = 0; i < wordsInUse; i++)
|
||||
for (uint32 i = 0; i < wordsInUse; i++)
|
||||
if (words[i] != set.words[i])
|
||||
return false;
|
||||
|
||||
@@ -314,12 +314,12 @@ namespace epics { namespace pvData {
|
||||
void BitSet::toString(StringBuilder buffer, int indentLevel) const
|
||||
{
|
||||
*buffer += '{';
|
||||
epicsInt32 i = nextSetBit(0);
|
||||
int32 i = nextSetBit(0);
|
||||
char tmp[30];
|
||||
if (i != -1) {
|
||||
sprintf(tmp,"%d",i); *buffer += tmp;
|
||||
for (i = nextSetBit(i+1); i >= 0; i = nextSetBit(i+1)) {
|
||||
epicsInt32 endOfRun = nextClearBit(i);
|
||||
int32 endOfRun = nextClearBit(i);
|
||||
do { *buffer += ", "; sprintf(tmp,"%d",i); *buffer += tmp; } while (++i < endOfRun);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user