Skip to content

Commit

Permalink
Fix #244 for the long map version. Fix issue for other replace case
Browse files Browse the repository at this point in the history
  • Loading branch information
nitsanw committed May 28, 2019
1 parent 1475be5 commit aeeffff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Expand Up @@ -767,7 +767,7 @@ private static final Object putIfMatch0(
(expVal != MATCH_ANY || V == TOMBSTONE || V == null) &&
!(V==null && expVal == TOMBSTONE) && // Match on null/TOMBSTONE combo
(expVal == null || !expVal.equals(V)) ) // Expensive equals check at the last
return V; // Do not update!
return (V==null) ? TOMBSTONE : V; // Do not update!

// Actually change the Value in the Key,Value pair
if( CAS_val(kvs, idx, V, putval ) ) break;
Expand Down
Expand Up @@ -561,8 +561,8 @@ private Object putIfMatch( final long key, final Object putval, final Object exp
if( K == NO_KEY ) { // Slot is free?
// Found an empty Key slot - which means this Key has never been in
// this table. No need to put a Tombstone - the Key is not here!
if( putval == TOMBSTONE ) return putval; // Not-now & never-been in this table
if( expVal == MATCH_ANY ) return null; // Will not match, even after K inserts
if( putval == TOMBSTONE ) return TOMBSTONE; // Not-now & never-been in this table
if( expVal == MATCH_ANY ) return TOMBSTONE; // Will not match, even after K inserts
// Claim the zero key-slot
if( CAS_key(idx, NO_KEY, key) ) { // Claim slot for Key
_slots.add(1); // Raise key-slots-used count
Expand Down Expand Up @@ -635,7 +635,7 @@ private Object putIfMatch( final long key, final Object putval, final Object exp
(expVal != MATCH_ANY || V == TOMBSTONE || V == null) &&
!(V==null && expVal == TOMBSTONE) && // Match on null/TOMBSTONE combo
(expVal == null || !expVal.equals(V)) ) // Expensive equals check at the last
return V; // Do not update!
return (V==null) ? TOMBSTONE : V; // Do not update!

// Actually change the Value in the Key,Value pair
if( CAS_val(idx, V, putval ) ) {
Expand Down
Expand Up @@ -129,6 +129,13 @@ private void checkSizes(String msg, int sz, Iterator it, int expectedSize)
}


@Test
public void replaceMissingValue() {
NonBlockingHashMapLong<Integer> map = new NonBlockingHashMapLong<>();
assertNull(map.replace(1, 2));
assertFalse(map.replace(1, 2, 3));
}

@Test
public void testIterationBig2()
{
Expand Down

0 comments on commit aeeffff

Please sign in to comment.