Example usage for org.apache.mahout.math.list AbstractList checkRangeFromTo

List of usage examples for org.apache.mahout.math.list AbstractList checkRangeFromTo

Introduction

In this page you can find the example usage for org.apache.mahout.math.list AbstractList checkRangeFromTo.

Prototype

protected static void checkRangeFromTo(int from, int to, int theSize) 

Source Link

Document

Checks if the given range is within the contained array's bounds.

Usage

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Sets the specified range of elements in the specified array to the specified value.
 *
 * @param from the index of the first element (inclusive) to be filled with the specified value.
 * @param to the index of the last element (inclusive) to be filled with the specified value.
 * @param val the value to be stored in the specified elements of the receiver.
 *///www.  j a  v a2 s  .  co  m
public void fillFromToWith(int from, int to, long[] val) {
    AbstractList.checkRangeFromTo(from, to, this.size);
    for (int i = from; i <= to;) {
        setQuick(i++, val);
    }
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Returns the index of the first occurrence of the specified element. Returns
 * {@code -1} if the receiver does not contain this element. Searches between
 * {@code from}, inclusive and// w  ww  .  jav  a2  s. c  o m
 * {@code to}, inclusive. Tests for identity.
 *
 * @param element element to search for.
 * @param from the leftmost search position, inclusive.
 * @param to the rightmost search position, inclusive.
 * @return the index of the first occurrence of the element in the receiver; returns {@code -1} if
 * the element is not found.
 * @exception IndexOutOfBoundsException index is out of range ( {@code size()&gt;0 && (from&lt;0 ||
 * from&gt;to || to&gt;=size())} ).
 */
public int indexOfFromTo(long[] element, int from, int to) {
    AbstractList.checkRangeFromTo(from, to, size);

    for (int i = from; i <= to; i++) {
        long[] another = getQuick(i);
        if (element[0] == another[0] && element[1] == another[1]) {
            return i; // found
        }
    }
    return -1; // not found
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Returns the index of the last occurrence of the specified element. Returns
 * {@code -1} if the receiver does not contain this element. Searches beginning at
 * {@code to}, inclusive until/*from w  w w. ja va 2  s.  c  o m*/
 * {@code from}, inclusive. Tests for identity.
 *
 * @param element element to search for.
 * @param from the leftmost search position, inclusive.
 * @param to the rightmost search position, inclusive.
 * @return the index of the last occurrence of the element in the receiver; returns {@code -1} if the
 * element is not found.
 * @exception IndexOutOfBoundsException index is out of range ( {@code size()&gt;0 && (from&lt;0 ||
 * from&gt;to || to&gt;=size())} ).
 */
public int lastIndexOfFromTo(long[] element, int from, int to) {
    AbstractList.checkRangeFromTo(from, to, size());

    for (int i = to; i >= from; i--) {
        if (element.equals(getQuick(i))) {
            return i; // found
        }
    }
    return -1; // not found
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Sorts the specified range of the receiver into ascending order.
 *
 * The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in
 * the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed
 * n*log(n) performance, and can approach linear performance on nearly sorted lists.
 *
 * <p> <b>You should never call this method unless you are sure that this particular sorting algorithm is
 * the right one for your data set.</b> It is generally better to call {@code sort()} or
 * {@code sortFromTo(...)} instead, because those methods automatically choose the best sorting
 * algorithm./*from   w w  w  .  j ava  2 s .c om*/
 *
 * @param from the index of the first element (inclusive) to be sorted.
 * @param to the index of the last element (inclusive) to be sorted.
 * @exception IndexOutOfBoundsException index is out of range ( {@code size()&gt;0 && (from&lt;0 ||
 * from&gt;to || to&gt;=size())} ).
 */
@Override
public void mergeSortFromTo(int from, int to) {
    int mySize = size();
    AbstractList.checkRangeFromTo(from, to, mySize);

    long[] myElements = elements();
    Sorting.mergeSort(myElements, from, to + 1);
    elements(myElements);
    setSizeRaw(mySize);
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Sorts the receiver according to the order induced by the specified comparator. All elements in the
 * range must be <i>mutually comparable</i> by the specified comparator (that is, {@code c.compare(e1,
 * e2)} must not throw a {@code ClassCastException} for any elements {@code e1} and {@code e2} in
 * the range). <p>/*from  w  w w  .ja  va 2  s  . co  m*/
 *
 * This sort is guaranteed to be <i>stable</i>: equal elements will not be reordered as a result of the
 * sort. <p>
 *
 * The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in
 * the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed
 * n*log(n) performance, and can approach linear performance on nearly sorted lists.
 *
 * @param from the index of the first element (inclusive) to be sorted.
 * @param to the index of the last element (inclusive) to be sorted.
 * @param c the comparator to determine the order of the receiver.
 * @throws ClassCastException if the array contains elements that are not <i>mutually comparable</i> using
 * the specified comparator.
 * @throws IllegalArgumentException if {@code fromIndex &gt; toIndex}
 * @throws ArrayIndexOutOfBoundsException if {@code fromIndex &lt; 0} or {@code toIndex &gt; a.length}
 * @see Comparator
 * @exception IndexOutOfBoundsException index is out of range ( {@code size()&gt;0 && (from&lt;0 ||
 * from&gt;to || to&gt;=size())} ).
 */
public void mergeSortFromTo(int from, int to, UuidComparatorBI c) {
    int mySize = size();
    AbstractList.checkRangeFromTo(from, to, mySize);

    long[] myElements = elements();
    UuidSorting.mergeSort(myElements, from, to + 1, c);
    elements(myElements);
    setSizeRaw(mySize);
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Returns a new list of the part of the receiver between
 * {@code from}, inclusive, and/*w  w  w.j  a v  a  2  s .  c o  m*/
 * {@code to}, inclusive.
 *
 * @param from the index of the first element (inclusive).
 * @param to the index of the last element (inclusive).
 * @return a new list
 * @exception IndexOutOfBoundsException index is out of range ( {@code size()&gt;0 && (from&lt;0 ||
 * from&gt;to || to&gt;=size())} ).
 */
public AbstractUuidList partFromTo(int from, int to) {
    AbstractList.checkRangeFromTo(from, to, size);

    int length = to - from + 1;
    UuidArrayList part = new UuidArrayList(length);
    part.addAllOfFromTo(this, from, to);
    return part;
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Sorts the specified range of the receiver into ascending numerical order. The sorting algorithm is a
 * tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function",
 * Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers
 * n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.
 *
 * <p> <b>You should never call this method unless you are sure that this particular sorting algorithm is
 * the right one for your data set.</b> It is generally better to call {@code sort()} or
 * {@code sortFromTo(...)} instead, because those methods automatically choose the best sorting
 * algorithm.//  www . ja  va  2s.  c o  m
 *
 * @param from the index of the first element (inclusive) to be sorted.
 * @param to the index of the last element (inclusive) to be sorted.
 * @exception IndexOutOfBoundsException index is out of range ( {@code size()&gt;0 && (from&lt;0 ||
 * from&gt;to || to&gt;=size())} ).
 */
@Override
public void quickSortFromTo(int from, int to) {
    int mySize = size();
    AbstractList.checkRangeFromTo(from, to, mySize);
    long[] myElements = elements();
    UuidSorting.quickSort(myElements, from, to + 1, c);
    elements(myElements);
    setSizeRaw(mySize);
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Sorts the receiver according to the order induced by the specified comparator. All elements in the
 * range must be <i>mutually comparable</i> by the specified comparator (that is, {@code c.compare(e1,
 * e2)} must not throw a {@code ClassCastException} for any elements {@code e1} and {@code e2} in
 * the range). <p>/*from w ww. j a  v  a  2 s  .  c  o  m*/
 *
 * The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's
 * "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November
 * 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to
 * degrade to quadratic performance.
 *
 * @param from the index of the first element (inclusive) to be sorted.
 * @param to the index of the last element (inclusive) to be sorted.
 * @param c the comparator to determine the order of the receiver.
 * @throws ClassCastException if the array contains elements that are not <i>mutually comparable</i> using
 * the specified comparator.
 * @throws IllegalArgumentException if {@code fromIndex &gt; toIndex}
 * @throws ArrayIndexOutOfBoundsException if {@code fromIndex &lt; 0} or {@code toIndex &gt; a.length}
 * @see Comparator
 * @exception IndexOutOfBoundsException index is out of range ( {@code size()&gt;0 && (from&lt;0 ||
 * from&gt;to || to&gt;=size())} ).
 */
public void quickSortFromTo(int from, int to, UuidComparatorBI c) {
    int mySize = size();
    AbstractList.checkRangeFromTo(from, to, mySize);

    long[] myElements = elements();
    UuidSorting.quickSort(myElements, from, to + 1, c);
    elements(myElements);
    setSizeRaw(mySize);
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Removes from the receiver all elements whose index is between
 * {@code from}, inclusive and//from  ww  w.j  a v a 2s . c  om
 * {@code to}, inclusive. Shifts any succeeding elements to the left (reduces their index). This call
 * shortens the list by {@code (to - from + 1)} elements.
 *
 * @param from index of first element to be removed.
 * @param to index of last element to be removed.
 * @exception IndexOutOfBoundsException index is out of range ( {@code size()&gt;0 && (from&lt;0 ||
 * from&gt;to || to&gt;=size())} ).
 */
@Override
public void removeFromTo(int from, int to) {
    AbstractList.checkRangeFromTo(from, to, size);
    int numMoved = size - to - 1;
    if (numMoved > 0) {
        replaceFromToWithFrom(from, from - 1 + numMoved, this, to + 1);
        // fillFromToWith(from+numMoved, size-1, 0.0f); //delta
    }
    int width = to - from + 1;
    if (width > 0) {
        setSizeRaw(size - width);
    }
}

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Replaces a number of elements in the receiver with the same number of elements of another list.
 * Replaces elements in the receiver, between
 * {@code from} (inclusive) and/*w w  w  . j av a 2s. c o m*/
 * {@code to} (inclusive), with elements of
 * {@code other}, starting from
 * {@code otherFrom} (inclusive).
 *
 * @param from the position of the first element to be replaced in the receiver
 * @param to the position of the last element to be replaced in the receiver
 * @param other list holding elements to be copied into the receiver.
 * @param otherFrom position of first element within other list to be copied.
 */
public void replaceFromToWithFrom(int from, int to, AbstractUuidList other, int otherFrom) {
    int length = to - from + 1;
    if (length > 0) {
        AbstractList.checkRangeFromTo(from, to, size());
        AbstractList.checkRangeFromTo(otherFrom, otherFrom + length - 1, other.size());

        // unambiguous copy (it may hold other==this)
        if (from <= otherFrom) {
            for (; --length >= 0;) {
                setQuick(from++, other.getQuick(otherFrom++));
            }
        } else {
            int otherTo = otherFrom + length - 1;
            for (; --length >= 0;) {
                setQuick(to--, other.getQuick(otherTo--));
            }
        }

    }
}