/** * Returns the index of the last occurrence of the specified * element. Returns <code>-1</code> if the receiver does not contain this element. * Searches beginning at <code>to</code>, inclusive until <code>from</code>, 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</code> if the element is not found. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public int lastIndexOfFromTo(long element, int from, int to) { // overridden for performance only. if (size==0) return -1; checkRangeFromTo(from, to, size); long[] theElements = elements; for (int i = to ; i >= from; i--) { if (element==theElements[i]) {return i;} //found } return -1; //not found } /**
/** * Returns the index of the first occurrence of the specified * element. Returns <code>-1</code> if the receiver does not contain this element. * Searches between <code>from</code>, inclusive and <code>to</code>, 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</code> if the element is not found. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public int indexOfFromTo(long element, int from, int to) { // overridden for performance only. if (size==0) return -1; checkRangeFromTo(from, to, size); long[] theElements = elements; for (int i = from ; i <= to; i++) { if (element==theElements[i]) {return i;} //found } return -1; //not found } /**
/** * Returns the index of the first occurrence of the specified * element. Returns <code>-1</code> if the receiver does not contain this element. * Searches between <code>from</code>, inclusive and <code>to</code>, 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</code> if the element is not found. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public int indexOfFromTo(long element, int from, int to) { // overridden for performance only. if (size==0) return -1; checkRangeFromTo(from, to, size); long[] theElements = elements; for (int i = from ; i <= to; i++) { if (element==theElements[i]) {return i;} //found } return -1; //not found } /**
/** * Returns the index of the last occurrence of the specified * element. Returns <code>-1</code> if the receiver does not contain this element. * Searches beginning at <code>to</code>, inclusive until <code>from</code>, 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</code> if the element is not found. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public int lastIndexOfFromTo(long element, int from, int to) { // overridden for performance only. if (size==0) return -1; checkRangeFromTo(from, to, size); long[] theElements = elements; for (int i = to ; i >= from; i--) { if (element==theElements[i]) {return i;} //found } return -1; //not found } /**
checkRangeFromTo(from, to, size);
checkRangeFromTo(from, to, size);
checkRangeFromTo(from, to, size);
/** * Returns a new list of the part of the receiver between <code>from</code>, inclusive, and <code>to</code>, 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 (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public AbstractLongList partFromTo(int from, int to) { if (size==0) return new LongArrayList(0); checkRangeFromTo(from, to, size); long[] part = new long[to-from+1]; System.arraycopy(elements, from, part, 0, to-from+1); return new LongArrayList(part); } /**
/** * Returns a new list of the part of the receiver between <code>from</code>, inclusive, and <code>to</code>, 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 (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public AbstractLongList partFromTo(int from, int to) { if (size==0) return new LongArrayList(0); checkRangeFromTo(from, to, size); long[] part = new long[to-from+1]; System.arraycopy(elements, from, part, 0, to-from+1); return new LongArrayList(part); } /**
checkRangeFromTo(from, to, size);
/** * 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</code> (inclusive) and <code>to</code> (inclusive), * with elements of <code>other</code>, starting from <code>otherFrom</code> (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, AbstractLongList other, int otherFrom) { // overridden for performance only. if (! (other instanceof LongArrayList)) { // slower super.replaceFromToWithFrom(from,to,other,otherFrom); return; } int length=to-from+1; if (length>0) { checkRangeFromTo(from, to, size()); checkRangeFromTo(otherFrom,otherFrom+length-1,other.size()); System.arraycopy(((LongArrayList) other).elements, otherFrom, elements, from, length); } } /**
/** * 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</code> (inclusive) and <code>to</code> (inclusive), * with elements of <code>other</code>, starting from <code>otherFrom</code> (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, AbstractLongList other, int otherFrom) { // overridden for performance only. if (! (other instanceof LongArrayList)) { // slower super.replaceFromToWithFrom(from,to,other,otherFrom); return; } int length=to-from+1; if (length>0) { checkRangeFromTo(from, to, size()); checkRangeFromTo(otherFrom,otherFrom+length-1,other.size()); System.arraycopy(((LongArrayList) other).elements, otherFrom, elements, from, length); } } /**
/** * Returns a new list of the part of the receiver between <code>from</code>, * inclusive, and <code>to</code>, 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 ( * <tt>size()>0 && (from<0 || from>to || to>=size())</tt> * ). */ public AbstractLongList partFromTo(int from, int to) { if (size == 0) return new LongArrayList(0); checkRangeFromTo(from, to, size); long[] part = new long[to - from + 1]; System.arraycopy(elements, from, part, 0, to - from + 1); return new LongArrayList(part); }
checkRangeFromTo(from, to, size()); checkRangeFromTo(otherFrom, otherFrom + length - 1, other.size()); System.arraycopy(((LongArrayList) other).elements, otherFrom, elements, from, length);
/** * Randomly permutes the part of the receiver between <code>from</code> (inclusive) and <code>to</code> (inclusive). * @param from the index of the first element (inclusive) to be permuted. * @param to the index of the last element (inclusive) to be permuted. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public void shuffleFromTo(int from, int to) { // overridden for performance only. if (size==0) return; checkRangeFromTo(from, to, size); cern.jet.random.Uniform gen = new cern.jet.random.Uniform(new cern.jet.random.engine.DRand(new java.util.Date())); long tmpElement; long[] theElements = elements; int random; for (int i=from; i<to; i++) { random = gen.nextIntFromTo(i, to); //swap(i, random) tmpElement = theElements[random]; theElements[random]=theElements[i]; theElements[i]=tmpElement; } } /**
checkRangeFromTo(from, to, size);
checkRangeFromTo(from, to, size);
checkRangeFromTo(from, to, size);
/** * Randomly permutes the part of the receiver between <code>from</code> (inclusive) and <code>to</code> (inclusive). * @param from the index of the first element (inclusive) to be permuted. * @param to the index of the last element (inclusive) to be permuted. * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>). */ public void shuffleFromTo(int from, int to) { // overridden for performance only. if (size==0) return; checkRangeFromTo(from, to, size); cern.jet.random.Uniform gen = new cern.jet.random.Uniform(new cern.jet.random.engine.DRand(new java.util.Date())); long tmpElement; long[] theElements = elements; int random; for (int i=from; i<to; i++) { random = gen.nextIntFromTo(i, to); //swap(i, random) tmpElement = theElements[random]; theElements[random]=theElements[i]; theElements[i]=tmpElement; } } /**
checkRangeFromTo(from, to, size);