bool Deallocate(bitfield &pos);
void Toggle(bitfield &pos, bool state);
+
+ bool Get(bitfield &pos);
+
+ size_t GetSize();
};
/** The irc_char_traits class is used for RFC-style comparison of strings.
}
}
-irc::dynamicbitmask::dynamicbitmask() : bits_size(4)
+irc::dynamicbitmask::dynamicbitmask()
{
/* We start with 4 bytes allocated which is room
* for 4 items. Something makes me doubt its worth
* allocating less than 4 bytes.
*/
+ bits_size = 4;
bits = new unsigned char[bits_size];
freebits = new unsigned char[bits_size];
memset(bits, 0, bits_size);
if (!(freebits[i] & current_pos))
{
freebits[i] |= current_pos;
+ printf("Just allocate at %d:%2x\n", i, current_pos);
return std::make_pair(i, current_pos);
}
}
}
+ printf("Grow set to size %d\n", bits_size + 1);
/* We dont have any free space left, increase by one */
int old_bits_size = bits_size;
bits_size++;
* for this allocation
*/
bits[old_bits_size] = 0;
- bits[old_bits_size] = 1;
+ freebits[old_bits_size] = 1;
/* We already know where we just allocated
* the bitfield, so no loop needed
*/
}
}
+bool irc::dynamicbitmask::Get(irc::bitfield &pos)
+{
+ if (pos.first < bits_size)
+ return (bits[pos.first] & pos.second);
+ else
+ return false;
+}
+
+size_t irc::dynamicbitmask::GetSize()
+{
+ return bits_size;
+}
+