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
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ public int compareTo(@Nonnull Entry<K, V> that)
{
return this.start.compareTo(that.start);
}

@Override
public String toString()
{
return "e{" +
"start=" + start +
", value=" + value +
", hasValue=" + hasValue +
'}';
}
}

protected static <K extends Comparable<? super K>, V, M extends BTreeReducingIntervalMap<K, V>> M mergeIntervals(
Expand Down
36 changes: 36 additions & 0 deletions accord-core/src/main/java/accord/utils/SortedArrays.java
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,42 @@ else if (c > 0)
return found >= 0 ? found : -1 - to;
}

public static <T1, T2> int binarySearch(List<T2> in, int from, int to, T1 find, AsymmetricComparator<T1, T2> comparator, Search op)
{
int found = -1;
while (from < to)
{
int i = (from + to) >>> 1;
int c = comparator.compare(find, in.get(i));
if (c < 0)
{
to = i;
}
else if (c > 0)
{
from = i + 1;
}
else
{
switch (op)
{
default: throw new IllegalStateException();
case FAST:
return i;

case CEIL:
to = found = i;
break;

case FLOOR:
found = i;
from = i + 1;
}
}
}
return found >= 0 ? found : -1 - to;
}

public interface IndirectComparator<T1, T2>
{
int compare(T1 t1, T2 t2, int t2Index);
Expand Down
Loading