]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Fix this so it works, passes test case. Provide a method to query for a bit and to...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 17 Nov 2006 23:51:35 +0000 (23:51 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 17 Nov 2006 23:51:35 +0000 (23:51 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5758 e03df62e-2008-0410-955e-edbf42e46eb7

include/hashcomp.h
src/hashcomp.cpp

index 4a5dd72ad63d6ad9c2abbd5c9eda04f47fbc6c17..73d9f53f245ee175f9e8385f3bb34322207e9179 100644 (file)
@@ -376,6 +376,10 @@ namespace irc
                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.
index 23d4928a627873607f3670c20df54828b26e4866..ff2bf0572fab3bb5a8b721bb9542cb00dc74023e 100644 (file)
@@ -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;
+}
+