Skip to content

Commit

Permalink
fix up tests and union impl
Browse files Browse the repository at this point in the history
  • Loading branch information
d2fn committed Aug 2, 2012
1 parent 2daed1b commit f8a7515
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/main/java/org/cliffc/high_scale_lib/NonBlockingSetInt.java
Expand Up @@ -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);
}

/**************************************************************************/
Expand All @@ -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;
}
Expand Down
Expand Up @@ -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));
Expand Down

0 comments on commit f8a7515

Please sign in to comment.