public static <T extends HasInterval<E>, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items) { Function<T,Interval<E>> toIntervalFunc = in -> in.getInterval(); return getNonOverlapping(items, toIntervalFunc); }
@Override public boolean test(T in) { if (exact) { return in.getInterval().equals(target); } else { return in.getInterval().contains(target); } } }
public static <T extends HasInterval<E>, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items, Comparator<? super T> compareFunc) { Function<T,Interval<E>> toIntervalFunc = in -> in.getInterval(); return getNonOverlapping(items, toIntervalFunc, compareFunc); }
public static <T extends HasInterval<E>, E extends Comparable<E>> List<T> getNonOverlappingMaxScore( List<? extends T> items, ToDoubleFunction<? super T> scoreFunc) { Function<T,Interval<E>> toIntervalFunc = in -> in.getInterval(); return getNonOverlappingMaxScore(items, toIntervalFunc, scoreFunc); }
public boolean overlaps(T target) { return overlaps(root, target.getInterval()); }
public List<T> getOverlapping(T target) { return getOverlapping(root, target.getInterval()); }
public boolean containsInterval(T target, boolean exact) { return containsInterval(this, target.getInterval(), exact); }
public static <T> List<T> mergeListWithSortedMatched(List<? extends T> list, List<? extends HasInterval<Integer>> matched, Function<List<? extends T>, T> aggregator) { List<T> merged = new ArrayList<>(list.size()); // Approximate size int last = 0; for (HasInterval<Integer> m : matched) { Interval<Integer> interval = m.getInterval(); int start = interval.getBegin(); int end = interval.getEnd(); if (start >= last) { merged.addAll(list.subList(last, start)); T t = aggregator.apply(list.subList(start, end)); merged.add(t); last = end; } } // Add rest of elements if (last < list.size()) { merged.addAll(list.subList(last, list.size())); } return merged; }
public static <E extends Comparable<E>, T extends HasInterval<E>> boolean containsValue(IntervalTree<E,T> node, T target) { Predicate<T> containsTargetFunction = new ContainsValueFunction(target); return contains(node, target.getInterval(), containsTargetFunction); }
if (target.second.compareTo(n.value.getInterval().first()) <= 0) { continue;
public static <E extends Comparable<E>, T extends HasInterval<E>> boolean overlaps(TreeNode<E,T> node, Interval<E> target) { Stack<TreeNode<E,T>> todo = new Stack<>(); todo.push(node); while (!todo.isEmpty()) { TreeNode<E,T> n = todo.pop(); // Don't search nodes that don't exist if (n == null || n.isEmpty()) continue; // If target is to the right of the rightmost point of any interval // in this node and all children, there won't be any matches. if (target.first.compareTo(n.maxEnd) > 0) continue; // Check this node if (n.value.getInterval().overlaps(target)) { return true; } // Search left children if (n.left != null) { todo.add(n.left); } // If target is to the left of the start of this interval, // then it can't be in any child to the right. if (target.second.compareTo(n.value.getInterval().first()) < 0) { continue; } if (n.right != null) { todo.add(n.right); } } return false; }
if (n.value.getInterval().overlaps(target)) { result.add(n.value); if (target.second.compareTo(n.value.getInterval().first()) < 0) { continue;
E leftMax = (node.left != null)? node.left.maxEnd:null; E rightMax = (node.right != null)? node.right.maxEnd:null; E maxEnd = node.value.getInterval().getEnd(); if (leftMax != null && leftMax.compareTo(maxEnd) > 0) { maxEnd = leftMax; if (node.value.getInterval().compareTo(n.parent.value.getInterval()) > 0) { throw new IllegalStateException("node is not on the correct side!!!"); if (node.value.getInterval().compareTo(n.parent.value.getInterval()) <= 0) { throw new IllegalStateException("node is not on the correct side!!!");
private void adjustUpwards(TreeNode<E,T> node, TreeNode<E,T> stopAt) { TreeNode<E,T> n = node; while (n != null && n != stopAt) { int leftSize = (n.left != null)? n.left.size:0; int rightSize = (n.right != null)? n.right.size:0; n.maxEnd = n.value.getInterval().getEnd(); if (n.left != null) { n.maxEnd = Interval.max(n.maxEnd, n.left.maxEnd); } if (n.right != null) { n.maxEnd = Interval.max(n.maxEnd, n.right.maxEnd); } n.size = leftSize + 1 + rightSize; if (n == n.parent) { throw new IllegalStateException("node is same as parent!!!"); } n = n.parent; } }
if (n.value == null) { n.value = target; n.maxEnd = target.getInterval().getEnd(); n.size = 1; if (depth > thresholdDepth) { } else { depth++; n.maxEnd = Interval.max(n.maxEnd, target.getInterval().getEnd()); n.size++; if (target.getInterval().compareTo(n.value.getInterval()) <= 0) {
if (target.getInterval().compareTo(node.value.getInterval()) <= 0) {
if (interval.getInterval().getEnd()-1 <= cur) { matchedStates.addStates(bid2, next); } else { if (matchedInterval.getInterval().getEnd()-1 <= cur) { matchedStates.addStates(bid, next); } else {
@Override public Interval<E> apply(T in) { return in.getInterval(); } };
@Override public boolean test(T in) { if (exact) { return in.getInterval().equals(target); } else { return in.getInterval().contains(target); } } }
public static <T extends HasInterval<E>, E extends Comparable<E>> List<T> getNonOverlapping( List<? extends T> items) { Function<T,Interval<E>> toIntervalFunc = in -> in.getInterval(); return getNonOverlapping(items, toIntervalFunc); }