X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=bit-vector.hpp;h=76ed8706f2ec232e44f16e7accba830db1c4b939;hb=HEAD;hp=cd6382e1dcf16a220f8a1af05f5acf1aa8017355;hpb=c6266d8fd1872fad45b18d3d554410d080b65099;p=SXSI%2FXMLTree.git diff --git a/bit-vector.hpp b/bit-vector.hpp index cd6382e..76ed870 100644 --- a/bit-vector.hpp +++ b/bit-vector.hpp @@ -56,7 +56,7 @@ class bit_vector { /** Sets the idxth bit to b. The bit_vector is resized if necessary */ void set(size_t idx, bool b); - + void set_le(size_t idx, bool b); /** Adds bit b at the end of the bit_vector. The bit_vector is resized if necessary */ void push_back(bool b); @@ -94,7 +94,7 @@ class bit_vector { /** Efficient unsafe get/get_field */ bool unsafe_get(size_t idx) const; uint32_t unsafe_get_field(size_t idx, size_t len) const; - + void debug(void) const; private: // true if get_vector_ptr() was called @@ -117,7 +117,9 @@ private: */ inline bool bit_vector::unsafe_get(size_t idx) const { - return (_vector[idx / W] >> (idx % W)) & true; + size_t i = idx / W; + size_t j = idx % W; + return (_vector[i] >> (W - 1 - j)) & true; }; /** Unsafe version of get_field. Does not perform bound checking. @@ -125,6 +127,7 @@ inline bool bit_vector::unsafe_get(size_t idx) const */ inline uint32_t bit_vector::unsafe_get_field(size_t idx, size_t len) const { + //TODO FIX TO REFLECT BIG ENDIAN ORDER. switch (len){ case 8: return ((uint8_t*)_vector)[idx];