From bc8ba059b9463d21112510325700db0c7a50df3f Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 17 Nov 2006 23:51:35 +0000 Subject: Fix this so it works, passes test case. Provide a method to query for a bit and to return the total size in bytes of the bitset git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5758 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/hashcomp.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/hashcomp.cpp') diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 23d4928a6..ff2bf0572 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -473,12 +473,13 @@ long irc::portparser::GetToken() } } -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); @@ -501,10 +502,12 @@ irc::bitfield irc::dynamicbitmask::Allocate() 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++; @@ -527,7 +530,7 @@ irc::bitfield irc::dynamicbitmask::Allocate() * 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 */ @@ -568,3 +571,16 @@ void irc::dynamicbitmask::Toggle(irc::bitfield &pos, bool state) } } +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; +} + -- cgit v1.2.3