move some generally useful bitset functions from heap.cpp to common.h

This commit is contained in:
Joel Dice
2008-01-06 12:21:38 -07:00
parent 7a0079e258
commit a8e9cc521c
2 changed files with 31 additions and 18 deletions

View File

@ -166,6 +166,34 @@ getBit(uintptr_t* map, unsigned i)
>> bitOf(i);
}
inline void
clearBits(uintptr_t* map, unsigned bitsPerRecord, unsigned index)
{
for (unsigned i = index, limit = index + bitsPerRecord; i < limit; ++i) {
clearBit(map, i);
}
}
inline void
setBits(uintptr_t* map, unsigned bitsPerRecord, int index, unsigned v)
{
for (int i = index + bitsPerRecord - 1; i >= index; --i) {
if (v & 1) markBit(map, i); else clearBit(map, i);
v >>= 1;
}
}
inline unsigned
getBits(uintptr_t* map, unsigned bitsPerRecord, unsigned index)
{
unsigned v = 0;
for (unsigned i = index, limit = index + bitsPerRecord; i < limit; ++i) {
v <<= 1;
v |= getBit(map, i);
}
return v;
}
template <class T>
inline T&
cast(void* p, unsigned offset)