Permalink
Browse files

fix up tests and union impl

  • Loading branch information...
1 parent 2daed1b commit f8a7515783e38f502ea5708e0b507a51f9ca7827 @d2fn d2fn committed Aug 2, 2012
@@ -451,12 +451,12 @@ public boolean union(NBSI dest, NBSI a, NBSI b) {
return true;
if(has_bits(a) || has_bits(b)) {
for(int i = 0; i < dest._bits.length; i++) {
- long left = a.safe_read_word(i,0);
- long right = b.safe_read_word(i,0);
+ long left = a == null ? 0L : a.safe_read_word(i,0);
+ long right = b == null ? 0L : b.safe_read_word(i,0);
dest._bits[i] = (left | right) & Long.MAX_VALUE;
}
}
- return union(dest._nbsi64, a._nbsi64, b._nbsi64);
+ return union(dest._nbsi64, a == null ? null : a._nbsi64, b == null ? null : b._nbsi64);
}
/**************************************************************************/
@@ -468,7 +468,11 @@ private long safe_read_word(int i, long default_word) {
}
long word = _bits[i];
if(word < 0) {
- word = help_copy_impl(i).help_copy()._bits[i];
+ NBSI nb = help_copy_impl(i);
+ if(nb._non_blocking_set_int == null) {
+ return default_word;
+ }
+ word = nb.help_copy()._bits[i];
}
return word;
}
@@ -30,20 +30,16 @@ public void testSetOperations() {
NonBlockingSetInt a = new NonBlockingSetInt();
NonBlockingSetInt b = new NonBlockingSetInt();
NonBlockingSetInt empty = new NonBlockingSetInt();
- int max = 10000;
+ int max = 20000000;
for(int i = 0; i < max; i++) {
NonBlockingSetInt t = (i&63) == 63 ? a : b;
t.add(i);
assertTrue(t.contains(i));
}
- a.add(1213446);
- NonBlockingSetInt c = a.union(empty);
- assertTrue(c.contains(1213446));
-
// c should contain the empty set since a and b are disjoint
- c = a.intersect(b);
+ NonBlockingSetInt c = a.intersect(b);
NonBlockingSetInt d = b.intersect(a);
for(int i = 0; i < max; i++) {
assertFalse(c.contains(i));

0 comments on commit f8a7515

Please sign in to comment.