Skip to content

Commit

Permalink
Fix UnifiedSet$ChainedBucket.removeLongChain() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
itohro committed Dec 28, 2015
1 parent c830c86 commit d930a92
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,12 @@ private void removeLongChain(ChainedBucket oldBucket, int i)
bucket.three = null;
return;
default:
if (bucket.three instanceof ChainedBucket)
{
i -= 3;
oldBucket = bucket;
continue;
}
throw new AssertionError();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,12 @@ private void removeLongChain(ChainedBucket oldBucket, int i)
bucket.three = null;
return;
default:
if (bucket.three instanceof ChainedBucket)
{
i -= 3;
oldBucket = bucket;
continue;
}
throw new AssertionError();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.eclipse.collections.impl.block.factory.Functions;
import org.eclipse.collections.impl.block.factory.Procedures;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.factory.Sets;
import org.eclipse.collections.impl.list.fixed.ArrayAdapter;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
import org.eclipse.collections.impl.test.SerializeTestHelper;
Expand Down Expand Up @@ -54,6 +56,9 @@ public abstract class UnifiedMapTestCase extends MutableMapTestCase
Lists.mutable.of(COLLISION_1, COLLISION_2, COLLISION_3, COLLISION_4, COLLISION_5);
protected static final MutableList<Integer> MORE_COLLISIONS = FastList.newList(COLLISIONS)
.with(COLLISION_6, COLLISION_7, COLLISION_8, COLLISION_9);
protected static final String[] FREQUENT_COLLISIONS = {"\u9103\ufffe", "\u9104\uffdf",
"\u9105\uffc0", "\u9106\uffa1", "\u9107\uff82", "\u9108\uff63", "\u9109\uff44",
"\u910a\uff25", "\u910b\uff06", "\u910c\ufee7"};

@Test
public void valuesCollection_toArray()
Expand Down Expand Up @@ -824,6 +829,29 @@ public void equalsAndHashCode()
Assert.assertEquals(0, this.newMapWithKeyValue(null, null).hashCode());
}

@Test
public void frequentCollision()
{
String[] expected = ArrayAdapter.adapt(FREQUENT_COLLISIONS)
.subList(0, FREQUENT_COLLISIONS.length - 2)
.toArray(new String[FREQUENT_COLLISIONS.length - 2]);
MutableMap<String, String> map = this.newMap();
MutableSet<String> set = Sets.mutable.of(expected);

ArrayIterate.forEach(FREQUENT_COLLISIONS, each -> map.put(each, each));

Iterator<String> itr = map.iterator();
while (itr.hasNext())
{
if (!set.contains(itr.next()))
{
itr.remove();
}
}

Assert.assertArrayEquals(expected, map.keysView().toArray());
}

private static final class NoInstanceOfInEquals
{
private final int value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.collections.impl.collection.mutable.AbstractCollectionTestCase;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.list.Interval;
import org.eclipse.collections.impl.list.fixed.ArrayAdapter;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.test.Verify;
import org.eclipse.collections.impl.utility.Iterate;
Expand Down Expand Up @@ -62,6 +63,9 @@ public abstract class AbstractMutableSetTestCase extends AbstractCollectionTestC
protected static final MutableList<Integer> MORE_COLLISIONS = FastList.newList(COLLISIONS)
.with(COLLISION_6, COLLISION_7, COLLISION_8, COLLISION_9);
protected static final int SIZE = 8;
protected static final String[] FREQUENT_COLLISIONS = {"\u9103\ufffe", "\u9104\uffdf",
"\u9105\uffc0", "\u9106\uffa1", "\u9107\uff82", "\u9108\uff63", "\u9109\uff44",
"\u910a\uff25", "\u910b\uff06", "\u910c\ufee7"};

@Override
protected abstract <T> MutableSet<T> newWith(T... littleElements);
Expand Down Expand Up @@ -881,4 +885,21 @@ public void toSortedBagBy()
MutableSortedBag<Integer> bag = integers.toSortedBagBy(String::valueOf);
Verify.assertSortedBagsEqual(TreeBag.newBagWith(1, 2, 3, 4), bag);
}

@Test
public void frequentCollisions()
{
String[] expected = ArrayAdapter.adapt(FREQUENT_COLLISIONS)
.subList(0, FREQUENT_COLLISIONS.length - 2)
.toArray(new String[FREQUENT_COLLISIONS.length - 2]);
MutableSet<String> set1 = this.newWith();
MutableSet<String> set2 = this.newWith();

Collections.addAll(set1, FREQUENT_COLLISIONS);
Collections.addAll(set2, expected);

set1.retainAll(set2);

Assert.assertArrayEquals(expected, set1.toArray());
}
}

0 comments on commit d930a92

Please sign in to comment.