Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions accord-core/src/main/java/accord/utils/SortedArrays.java
Original file line number Diff line number Diff line change
Expand Up @@ -1070,14 +1070,11 @@ public static <V extends Comparable<? super V>> V[] linearSubtract(V[] keep, V[]
}

public static <O, I extends O> O[] linearSubtract(Comparator<? super I> comparator, I[] keep, I[] subtract, ObjectBuffers<O> buffers)
{
return linearSubtract(comparator, keep, 0, keep.length, subtract, 0, subtract.length, buffers);
}

public static <O, I extends O> O[] linearSubtract(Comparator<? super I> comparator, I[] keep, int keepFrom, int keepTo, I[] subtract, int subtractFrom, int subtractTo, ObjectBuffers<O> buffers)
{
O[] result = null;
int resultSize = 0;
int keepFrom = 0, keepTo = keep.length;
int subtractFrom = 0, subtractTo = subtract.length;

while (keepFrom < keepTo && subtractFrom < subtractTo)
{
Expand Down
27 changes: 27 additions & 0 deletions accord-core/src/test/java/accord/utils/SortedArraysTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,33 @@ private static void assertArrayEquals(Object[] expected, Object[] actual)
});
}

@Test
public void testWithoutBasic()
{
Assertions.assertEquals(
SortedArrayList.ofSorted(1),
SortedArrayList.ofSorted(1, 2, 3).without(SortedArrayList.ofSorted(2, 3))
);
}

@Test
public void testWithoutSingleElement()
{
Assertions.assertEquals(
SortedArrayList.ofSorted(1, 2, 4),
SortedArrayList.ofSorted(1, 2, 3, 4).without(SortedArrayList.ofSorted(3))
);
}

@Test
public void testWithoutTrailingElements()
{
Assertions.assertEquals(
SortedArrayList.ofSorted(1, 2),
SortedArrayList.ofSorted(1, 2, 3, 4).without(SortedArrayList.ofSorted(3, 4))
);
}

private static class Pair<T>
{
private final T[] src;
Expand Down