Skip to content
Snippets Groups Projects
Commit 33b002bf authored by Tobias S. Josefowitz's avatar Tobias S. Josefowitz
Browse files

ADT.CritBit.BigNumTree: off by one error (removed)

Due to an off-by-one error the last limb of bignums was never compared.
This resulted (sometimes) in bignums comparing equal inside of the tree.
parent 9dee38e1
No related branches found
No related tags found
No related merge requests found
......@@ -96,6 +96,12 @@ o Web.Sass
Bug fixes
---------
o ADT.CritBit
- Due to an off-by-one error the last limb of bignums was never compared.
This resulted (sometimes) in unequal bignums comparing equal inside of
the tree.
o Compiler
- Improved variant robustness.
......
......@@ -19,11 +19,13 @@ typedef mp_limb_t CB_NAME(char);
#define cb_char CB_NAME(char)
static CB_INLINE unsigned INT32 gclz(mp_limb_t a) {
if (sizeof(mp_limb_t) == 8) {
#if GMP_NUMB_BITS == 64
return clz64((unsigned INT64)a);
} else {
#elif GMP_NUMB_BITS == 32
return clz32((unsigned INT32)a);
}
#else
#error Only supports limb sizes of 32 or 64 bits.
#endif
}
#define O2G(o) ((MP_INT*)(o->storage))
......@@ -46,11 +48,9 @@ static CB_INLINE mp_limb_t CB_GET_CHAR(cb_string s, ptrdiff_t n) {
MP_INT * i = O2G(s);
n += abs(i->_mp_size);
if (n > 0) {
//fprintf(stderr, ">> %lld %lld\n", n, i->_mp_d[abs(n)]);
return i->_mp_d[abs(i->_mp_size)-n];
if (n >= 0) {
return i->_mp_d[abs(i->_mp_size) - 1 - n];
} else {
//fprintf(stderr, " %lld %lld\n", n, i->_mp_d[abs(n)]);
return 0;
}
}
......
......@@ -200,6 +200,6 @@ test_tree(ADT.CritBit.IPv4Tree, [[mkmapping(map(enumerate(100)+enumerate(1000, -
}), enumerate(2100))]], ADT.CritBit.sort_ipv4)
test_tree(ADT.CritBit.FloatTree, [[mkmapping((array(float))(enumerate(100)+enumerate(1000, -19, 666)+enumerate(1000, Int.NATIVE_MAX/600, Int.NATIVE_MIN)), enumerate(2100))]], sort)
test_tree(ADT.CritBit.DateTree, [[mkmapping(map(enumerate(2000, time()/3000, 1), Function.curry(Calendar.Second)("unix")), enumerate(2000))]], sort)
test_tree(ADT.CritBit.BigNumTree, [[mkmapping(enumerate(10000, 2*Int.NATIVE_MAX, Int.NATIVE_MAX+1), enumerate(10000))]], sort)
END_MARKER
......@@ -25,9 +25,9 @@ static inline void cb_debug_print_key(struct string_builder * buf, cb_key key) {
#ifdef CB_PRINT_CHAR
CB_PRINT_CHAR(buf, key.str, i.chars);
#else
string_builder_sprintf(buf, "(%d, %d) b: ", i.chars, CB_WIDTH(s));
string_builder_sprintf(buf, "(%d, %d) b: ", i.chars, CB_WIDTH(key.str));
for (i.bits = 0; i.bits < CB_WIDTH(s); i.bits++) {
for (i.bits = 0; i.bits < CB_WIDTH(key.str); i.bits++) {
string_builder_sprintf(buf, "%d", CB_GET_BIT(key.str, i));
}
string_builder_putchar(buf, ' ');
......@@ -53,7 +53,7 @@ static inline void cb_print_key(struct string_builder * buf, const cb_key key) {
cb_size i;
for (i.chars = 0; i.chars < key.len.chars; i.chars++) {
for (i.bits = 0; i.bits < CB_WIDTH(s); i.bits++) {
for (i.bits = 0; i.bits < CB_WIDTH(key.str); i.bits++) {
string_builder_putchar(buf, CB_GET_BIT(key.str, i) ? '1' : '0');
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment