projects
/
SXSI
/
XMLTree.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c6266d8
)
Change get_bit/set_bit to access the vector in big endian (to match
author
Kim Nguyễn
<kn@lri.fr>
Fri, 6 Apr 2012 12:01:26 +0000
(14:01 +0200)
committer
Kim Nguyễn
<kn@lri.fr>
Fri, 6 Apr 2012 12:01:26 +0000
(14:01 +0200)
libbp).
bit-vector.cpp
patch
|
blob
|
history
bit-vector.hpp
patch
|
blob
|
history
diff --git
a/bit-vector.cpp
b/bit-vector.cpp
index
d69c177
..
5450989
100644
(file)
--- a/
bit-vector.cpp
+++ b/
bit-vector.cpp
@@
-1,5
+1,6
@@
#include <stdexcept>
#include "bit-vector.hpp"
#include <stdexcept>
#include "bit-vector.hpp"
+#include <cstdio>
static inline uint8_t pow2_mult8(uint8_t x){
return (~((x & (x-1))==0) + 1) & (x >> 3);
static inline uint8_t pow2_mult8(uint8_t x){
return (~((x & (x-1))==0) + 1) & (x >> 3);
@@
-11,10
+12,9
@@
static inline size_t uint32bits(size_t bits){
}
}
-
-void array_copy(const uint32_t * src, uint32_t * dst, size_t len)
+static void array_copy(const uint32_t * src, uint32_t * dst, size_t len)
{
{
-
while (len--) *dst++ = *src++
;
+
for(size_t i = 0; i < len; i++) dst[i] = src[i]
;
}
size_t bit_vector::allocforsize(size_t bits)
}
size_t bit_vector::allocforsize(size_t bits)
@@
-135,23
+135,24
@@
void bit_vector::pack()
size_t nalloc = uint32bits(_size);
uint32_t * nvector = new uint32_t[nalloc];
size_t nalloc = uint32bits(_size);
uint32_t * nvector = new uint32_t[nalloc];
- array_copy(_vector,
nvector,
nalloc);
- if (!_leaked) delete [] _vector;
+ array_copy(_vector,
nvector,
nalloc);
+ if (!_leaked
&& _vector
) delete [] _vector;
_alloc = nalloc;
_alloc = nalloc;
- _vector = nvector;
- _leaked = false;
+
this->
_vector = nvector;
+
this->
_leaked = false;
}
//sets the idxth bit to b
void bit_vector::set(size_t idx, bool b)
{
}
//sets the idxth bit to b
void bit_vector::set(size_t idx, bool b)
{
- size_t i = idx / sizeof(uint32_t);
- size_t j = idx % sizeof(uint32_t);
+
+ size_t i = idx / W;
+ size_t j = idx % W;
grow(allocforsize(idx+1));
if (idx >= _size)
_size = idx+1;
grow(allocforsize(idx+1));
if (idx >= _size)
_size = idx+1;
- uint32_t mask = 1 <<
j
;
+ uint32_t mask = 1 <<
(W - 1 - j)
;
if (b)
_vector[i] |= mask;
else
if (b)
_vector[i] |= mask;
else
diff --git
a/bit-vector.hpp
b/bit-vector.hpp
index
cd6382e
..
697581d
100644
(file)
--- a/
bit-vector.hpp
+++ b/
bit-vector.hpp
@@
-117,7
+117,9
@@
private:
*/
inline bool bit_vector::unsafe_get(size_t idx) const
{
*/
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.
};
/** 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
{
*/
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];
switch (len){
case 8:
return ((uint8_t*)_vector)[idx];