summaryrefslogtreecommitdiff
path: root/src/hashcomp.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-17 23:51:35 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-11-17 23:51:35 +0000
commitbc8ba059b9463d21112510325700db0c7a50df3f (patch)
tree02fc41a5c1944642c336871d167210aad1385518 /src/hashcomp.cpp
parent11f73970236f910a63ff77fbc8e2ee4a8ee23bc3 (diff)
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
Diffstat (limited to 'src/hashcomp.cpp')
-rw-r--r--src/hashcomp.cpp20
1 files changed, 18 insertions, 2 deletions
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;
+}
+