/**
  * Returns the intersection of two sets of non-intersecting ranges
  *
  * @param one a sorted set of non-intersecting ranges in ascending order
  * @param another another sorted set of non-intersecting ranges in ascending order
  * @return the intersection of the two sets, sorted in ascending order
  */
 public static <T extends Comparable<? super T>> Range<T>[] intersectSortedDistinctRanges(
     Range<T>[] one, Range<T>[] another) {
   int ix = 0;
   Vector<Range<T>> result = new Vector<Range<T>>();
   for (Range<T> range : another) {
     while (ix < one.length && one[ix].getUpper().compareTo(range.getLower()) < 0) {
       ++ix;
     }
     while (ix < one.length && one[ix].getUpper().compareTo(range.getUpper()) < 0) {
       result.add(range.intersect(one[ix]));
       ++ix;
     }
     if (ix == one.length) {
       break;
     }
     if (one[ix].getLower().compareTo(range.getUpper()) <= 0) {
       result.add(range.intersect(one[ix]));
     }
   }
   return result.toArray(new Range[result.size()]);
 }
 static Range<Integer> alignRange(Range<Integer> range, int align) {
   return range.intersect(
       divUp(range.getLower(), align) * align, (range.getUpper() / align) * align);
 }