removeAll is now O(n+m) if both lists are sorted
This commit is contained in:
@@ -1114,6 +1114,28 @@ public class IntListTest {
|
||||
Assertions.assertEquals(0, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllFromSortedList() {
|
||||
final IntList list = IntList.of(1, 2, 3, 4, 5);
|
||||
final IntList remove = IntList.of(1, 3);
|
||||
|
||||
list.removeAll(remove);
|
||||
Assertions.assertArrayEquals(new int[] { 2, 4, 5 }, list.toArray());
|
||||
Assertions.assertEquals(3, list.size());
|
||||
Assertions.assertTrue(list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllFromSortedList2() {
|
||||
final IntList list = IntList.of(2, 4, 4, 6, 8);
|
||||
final IntList remove = IntList.of(1, 4, 9);
|
||||
|
||||
list.removeAll(remove);
|
||||
Assertions.assertArrayEquals(new int[] { 2, 6, 8 }, list.toArray());
|
||||
Assertions.assertEquals(3, list.size());
|
||||
Assertions.assertTrue(list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetainAll() {
|
||||
final IntList list = IntList.of(-2, -1, 0, 1, 2, 3, 4, 5, 6);
|
||||
|
||||
@@ -1104,6 +1104,28 @@ public class LongListTest {
|
||||
Assertions.assertEquals(0, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllFromSortedList() {
|
||||
final LongList list = LongList.of(1, 2, 3, 4, 5);
|
||||
final LongList remove = LongList.of(1, 3);
|
||||
|
||||
list.removeAll(remove);
|
||||
Assertions.assertArrayEquals(new long[] { 2, 4, 5 }, list.toArray());
|
||||
Assertions.assertEquals(3, list.size());
|
||||
Assertions.assertTrue(list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllFromSortedList2() {
|
||||
final LongList list = LongList.of(2, 4, 4, 6, 8);
|
||||
final LongList remove = LongList.of(1, 4, 9);
|
||||
|
||||
list.removeAll(remove);
|
||||
Assertions.assertArrayEquals(new long[] { 2, 6, 8 }, list.toArray());
|
||||
Assertions.assertEquals(3, list.size());
|
||||
Assertions.assertTrue(list.isSorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetainAll() {
|
||||
final LongList list = LongList.of(-2, -1, 0, 1, 2, 3, 4, 5, 6);
|
||||
|
||||
Reference in New Issue
Block a user