mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r883973 [10/14] - in /lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix: ./ bitvector/ buffer/ function/ list/ list/adapter/ map/
Date Wed, 25 Nov 2009 03:36:02 GMT
Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/FloatArrayList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/FloatArrayList.java?rev=883973&r1=883972&r2=883973&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/FloatArrayList.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/FloatArrayList.java Wed Nov 25 03:35:59 2009
@@ -18,17 +18,17 @@
  */
 @Deprecated
 public class FloatArrayList extends AbstractFloatList {
-	/**
-	 * The array buffer into which the elements of the list are stored.
-	 * The capacity of the list is the length of this array buffer.
-	 * @serial
-	 */
-	protected float[] elements;
+  /**
+   * The array buffer into which the elements of the list are stored.
+   * The capacity of the list is the length of this array buffer.
+   * @serial
+   */
+  protected float[] elements;
 /**
  * Constructs an empty list.
  */
 public FloatArrayList() {
-	this(10);
+  this(10);
 }
 /**
  * Constructs a list containing the specified elements. 
@@ -40,7 +40,7 @@
  * @param elements the array to be backed by the the constructed list
  */
 public FloatArrayList(float[] elements) {
-	elements(elements);
+  elements(elements);
 }
 /**
  * Constructs an empty list with the specified initial capacity.
@@ -48,8 +48,8 @@
  * @param   initialCapacity   the number of elements the receiver can hold without auto-expanding itself by allocating new internal memory.
  */
 public FloatArrayList(int initialCapacity) {
-	this(new float[initialCapacity]);
-	setSizeRaw(0);
+  this(new float[initialCapacity]);
+  setSizeRaw(0);
 }
 /**
  * Appends the specified element to the end of this list.
@@ -57,9 +57,9 @@
  * @param element element to be appended to this list.
  */
 public void add(float element) {
-	// overridden for performance only.
-	if (size == elements.length) ensureCapacity(size + 1); 
-	elements[size++] = element;
+  // overridden for performance only.
+  if (size == elements.length) ensureCapacity(size + 1); 
+  elements[size++] = element;
 }
 /**
  * Inserts the specified element before the specified position into the receiver. 
@@ -71,13 +71,13 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>index &lt; 0 || index &gt; size()</tt>).
  */
 public void beforeInsert(int index, float element) {
-	// overridden for performance only.
-	if (index > size || index < 0) 
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	ensureCapacity(size + 1);
-	System.arraycopy(elements, index, elements, index+1, size-index);
-	elements[index] = element;
-	size++;
+  // overridden for performance only.
+  if (index > size || index < 0) 
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  ensureCapacity(size + 1);
+  System.arraycopy(elements, index, elements, index+1, size-index);
+  elements[index] = element;
+  size++;
 }
 /**
  * Searches the receiver for the specified value using
@@ -92,18 +92,18 @@
  * @param from the leftmost search position, inclusive.
  * @param to the rightmost search position, inclusive.
  * @return index of the search key, if it is contained in the receiver;
- *	       otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The <i>insertion
- *	       point</i> is defined as the the point at which the value would
- * 	       be inserted into the receiver: the index of the first
- *	       element greater than the key, or <tt>receiver.size()</tt>, if all
- *	       elements in the receiver are less than the specified key.  Note
- *	       that this guarantees that the return value will be &gt;= 0 if
- *	       and only if the key is found.
+ *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The <i>insertion
+ *         point</i> is defined as the the point at which the value would
+ *          be inserted into the receiver: the index of the first
+ *         element greater than the key, or <tt>receiver.size()</tt>, if all
+ *         elements in the receiver are less than the specified key.  Note
+ *         that this guarantees that the return value will be &gt;= 0 if
+ *         and only if the key is found.
  * @see org.apache.mahout.matrix.Sorting
  * @see java.util.Arrays
  */
 public int binarySearchFromTo(float key, int from, int to) {
-	return org.apache.mahout.matrix.Sorting.binarySearchFromTo(this.elements,key,from,to);
+  return org.apache.mahout.matrix.Sorting.binarySearchFromTo(this.elements,key,from,to);
 }
 /**
  * Returns a deep copy of the receiver. 
@@ -111,10 +111,10 @@
  * @return  a deep copy of the receiver.
  */
 public Object clone() {
-	// overridden for performance only.
-	FloatArrayList clone = new FloatArrayList((float[]) elements.clone());
-	clone.setSizeRaw(size);
-	return clone;
+  // overridden for performance only.
+  FloatArrayList clone = new FloatArrayList((float[]) elements.clone());
+  clone.setSizeRaw(size);
+  return clone;
 }
 /**
  * Returns a deep copy of the receiver; uses <code>clone()</code> and casts the result.
@@ -122,7 +122,7 @@
  * @return  a deep copy of the receiver.
  */
 public FloatArrayList copy() {
-	return (FloatArrayList) clone();
+  return (FloatArrayList) clone();
 }
 /**
  * Returns the elements currently stored, including invalid elements between size and capacity, if any.
@@ -133,7 +133,7 @@
  * @return the elements currently stored.
  */
 public float[] elements() {
-	return elements;
+  return elements;
 }
 /**
  * Sets the receiver's elements to be the specified array (not a copy of it).
@@ -146,9 +146,9 @@
  * @return the receiver itself.
  */
 public AbstractFloatList elements(float[] elements) {
-	this.elements=elements;
-	this.size=elements.length;
-	return this;
+  this.elements=elements;
+  this.size=elements.length;
+  return this;
 }
 /**
  * Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory.
@@ -157,7 +157,7 @@
  * @param   minCapacity   the desired minimum capacity.
  */
 public void ensureCapacity(int minCapacity) {
-	elements = org.apache.mahout.matrix.Arrays.ensureCapacity(elements,minCapacity);
+  elements = org.apache.mahout.matrix.Arrays.ensureCapacity(elements,minCapacity);
 }
 /**
  * Compares the specified Object with the receiver.  
@@ -170,19 +170,19 @@
  * @return true if the specified Object is equal to the receiver.
  */
 public boolean equals(Object otherObj) { //delta
-	// overridden for performance only.
-	if (! (otherObj instanceof FloatArrayList)) return super.equals(otherObj);
-	if (this==otherObj) return true;
-	if (otherObj==null) return false;
-	FloatArrayList other = (FloatArrayList) otherObj;
-	if (size()!=other.size()) return false;
-
-	float[] theElements = elements();
-	float[] otherElements = other.elements();
-	for (int i=size(); --i >= 0; ) {
-	    if (theElements[i] != otherElements[i]) return false;
-	}
-	return true;
+  // overridden for performance only.
+  if (! (otherObj instanceof FloatArrayList)) return super.equals(otherObj);
+  if (this==otherObj) return true;
+  if (otherObj==null) return false;
+  FloatArrayList other = (FloatArrayList) otherObj;
+  if (size()!=other.size()) return false;
+
+  float[] theElements = elements();
+  float[] otherElements = other.elements();
+  for (int i=size(); --i >= 0; ) {
+      if (theElements[i] != otherElements[i]) return false;
+  }
+  return true;
 }
 /**
  * Applies a procedure to each element of the receiver, if any.
@@ -191,25 +191,25 @@
  * @return <tt>false</tt> if the procedure stopped before all elements where iterated over, <tt>true</tt> otherwise. 
  */
 public boolean forEach(FloatProcedure procedure) {
-	// overridden for performance only.
-	float[] theElements = elements;
-	int theSize = size;
-	
-	for (int i=0; i<theSize;) if (! procedure.apply(theElements[i++])) return false;
-	return true;
+  // overridden for performance only.
+  float[] theElements = elements;
+  int theSize = size;
+  
+  for (int i=0; i<theSize;) if (! procedure.apply(theElements[i++])) return false;
+  return true;
 }
 /**
  * Returns the element at the specified position in the receiver.
  *
  * @param index index of element to return.
  * @exception IndexOutOfBoundsException index is out of range (index
- * 		  &lt; 0 || index &gt;= size()).
+ *       &lt; 0 || index &gt;= size()).
  */
 public float get(int index) {
-	// overridden for performance only.
-	if (index >= size || index < 0)
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	return elements[index];
+  // overridden for performance only.
+  if (index >= size || index < 0)
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  return elements[index];
 }
 /**
  * Returns the element at the specified position in the receiver; <b>WARNING:</b> Does not check preconditions. 
@@ -220,7 +220,7 @@
  * @param index index of element to return.
  */
 public float getQuick(int index) {
-	return elements[index];
+  return elements[index];
 }
 /**
  * Returns the index of the first occurrence of the specified
@@ -235,15 +235,15 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public int indexOfFromTo(float element, int from, int to) {
-	// overridden for performance only.
-	if (size==0) return -1;
-	checkRangeFromTo(from, to, size);
-
-	float[] theElements = elements;
-	for (int i = from ; i <= to; i++) {
-	    if (element==theElements[i]) {return i;} //found
-	}
-	return -1; //not found
+  // overridden for performance only.
+  if (size==0) return -1;
+  checkRangeFromTo(from, to, size);
+
+  float[] 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
@@ -258,15 +258,15 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public int lastIndexOfFromTo(float element, int from, int to) {
-	// overridden for performance only.
-	if (size==0) return -1;
-	checkRangeFromTo(from, to, size);
-
-	float[] theElements = elements;
-	for (int i = to ; i >= from; i--) {
-	    if (element==theElements[i]) {return i;} //found
-	}
-	return -1; //not found
+  // overridden for performance only.
+  if (size==0) return -1;
+  checkRangeFromTo(from, to, size);
+
+  float[] theElements = elements;
+  for (int i = to ; i >= from; i--) {
+      if (element==theElements[i]) {return i;} //found
+  }
+  return -1; //not found
 }
 /**
  * Returns a new list of the part of the receiver between <code>from</code>, inclusive, and <code>to</code>, inclusive.
@@ -276,13 +276,13 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public AbstractFloatList partFromTo(int from, int to) {
-	if (size==0) return new FloatArrayList(0);
+  if (size==0) return new FloatArrayList(0);
 
-	checkRangeFromTo(from, to, size);
+  checkRangeFromTo(from, to, size);
 
-	float[] part = new float[to-from+1];
-	System.arraycopy(elements, from, part, 0, to-from+1);
-	return new FloatArrayList(part);
+  float[] part = new float[to-from+1];
+  System.arraycopy(elements, from, part, 0, to-from+1);
+  return new FloatArrayList(part);
 }
 /**
 * Removes from the receiver all elements that are contained in the specified list.
@@ -292,46 +292,46 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean removeAll(AbstractFloatList other) {
-	// overridden for performance only.
-	if (! (other instanceof FloatArrayList))	return super.removeAll(other);
-	
-	/* There are two possibilities to do the thing
-	   a) use other.indexOf(...)
-	   b) sort other, then use other.binarySearch(...)
-	   
-	   Let's try to figure out which one is faster. Let M=size, N=other.size, then
-	   a) takes O(M*N) steps
-	   b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
+  // overridden for performance only.
+  if (! (other instanceof FloatArrayList))  return super.removeAll(other);
+  
+  /* There are two possibilities to do the thing
+     a) use other.indexOf(...)
+     b) sort other, then use other.binarySearch(...)
+     
+     Let's try to figure out which one is faster. Let M=size, N=other.size, then
+     a) takes O(M*N) steps
+     b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
  
-	   Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
-	*/
-	if (other.size()==0) {return false;} //nothing to do
-	int limit = other.size()-1;
-	int j=0;
-	float[] theElements = elements;
-	int mySize = size();
-
-	double N=(double) other.size();
-	double M=(double) mySize;
-	if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
-		// it is faster to sort other before searching in it
-		FloatArrayList sortedList = (FloatArrayList) other.clone();
-		sortedList.quickSort();
-
-		for (int i=0; i<mySize ; i++) {
-			if (sortedList.binarySearchFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
-		}
-	}
-	else {
-		// it is faster to search in other without sorting
-		for (int i=0; i<mySize ; i++) {
-			if (other.indexOfFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
-		}
-	}
-
-	boolean modified = (j!=mySize);
-	setSize(j);
-	return modified;
+     Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
+  */
+  if (other.size()==0) {return false;} //nothing to do
+  int limit = other.size()-1;
+  int j=0;
+  float[] theElements = elements;
+  int mySize = size();
+
+  double N=(double) other.size();
+  double M=(double) mySize;
+  if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
+    // it is faster to sort other before searching in it
+    FloatArrayList sortedList = (FloatArrayList) other.clone();
+    sortedList.quickSort();
+
+    for (int i=0; i<mySize ; i++) {
+      if (sortedList.binarySearchFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
+    }
+  }
+  else {
+    // it is faster to search in other without sorting
+    for (int i=0; i<mySize ; i++) {
+      if (other.indexOfFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
+    }
+  }
+
+  boolean modified = (j!=mySize);
+  setSize(j);
+  return modified;
 }
 /**
  * Replaces a number of elements in the receiver with the same number of elements of another list.
@@ -344,18 +344,18 @@
  * @param otherFrom position of first element within other list to be copied.
  */
 public void replaceFromToWithFrom(int from, int to, AbstractFloatList other, int otherFrom) {
-	// overridden for performance only.
-	if (! (other instanceof FloatArrayList)) {
-		// 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(((FloatArrayList) other).elements, otherFrom, elements, from, length);
-	}
+  // overridden for performance only.
+  if (! (other instanceof FloatArrayList)) {
+    // 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(((FloatArrayList) other).elements, otherFrom, elements, from, length);
+  }
 }
 /**
 * Retains (keeps) only the elements in the receiver that are contained in the specified other list.
@@ -365,62 +365,62 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean retainAll(AbstractFloatList other) {
-	// overridden for performance only.
-	if (! (other instanceof FloatArrayList))	return super.retainAll(other);
-	
-	/* There are two possibilities to do the thing
-	   a) use other.indexOf(...)
-	   b) sort other, then use other.binarySearch(...)
-	   
-	   Let's try to figure out which one is faster. Let M=size, N=other.size, then
-	   a) takes O(M*N) steps
-	   b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
-
-	   Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
-	*/
-	int limit = other.size()-1;
-	int j=0;
-	float[] theElements = elements;
-	int mySize = size();
-
-	double N=(double) other.size();
-	double M=(double) mySize;
-	if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
-		// it is faster to sort other before searching in it
-		FloatArrayList sortedList = (FloatArrayList) other.clone();
-		sortedList.quickSort();
-
-		for (int i=0; i<mySize ; i++) {
-			if (sortedList.binarySearchFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
-		}
-	}
-	else {
-		// it is faster to search in other without sorting
-		for (int i=0; i<mySize ; i++) {
-			if (other.indexOfFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
-		}
-	}
-
-	boolean modified = (j!=mySize);
-	setSize(j);
-	return modified;
+  // overridden for performance only.
+  if (! (other instanceof FloatArrayList))  return super.retainAll(other);
+  
+  /* There are two possibilities to do the thing
+     a) use other.indexOf(...)
+     b) sort other, then use other.binarySearch(...)
+     
+     Let's try to figure out which one is faster. Let M=size, N=other.size, then
+     a) takes O(M*N) steps
+     b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
+
+     Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
+  */
+  int limit = other.size()-1;
+  int j=0;
+  float[] theElements = elements;
+  int mySize = size();
+
+  double N=(double) other.size();
+  double M=(double) mySize;
+  if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
+    // it is faster to sort other before searching in it
+    FloatArrayList sortedList = (FloatArrayList) other.clone();
+    sortedList.quickSort();
+
+    for (int i=0; i<mySize ; i++) {
+      if (sortedList.binarySearchFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
+    }
+  }
+  else {
+    // it is faster to search in other without sorting
+    for (int i=0; i<mySize ; i++) {
+      if (other.indexOfFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
+    }
+  }
+
+  boolean modified = (j!=mySize);
+  setSize(j);
+  return modified;
 }
 /**
  * Reverses the elements of the receiver.
  * Last becomes first, second last becomes second first, and so on.
  */
 public void reverse() {
-	// overridden for performance only.
-	float tmp;
-	int limit=size/2;
-	int j=size-1;
-
-	float[] theElements = elements;
-	for (int i=0; i<limit;) { //swap
-		tmp=theElements[i];
-		theElements[i++]=theElements[j];
-		theElements[j--]=tmp;
-	}
+  // overridden for performance only.
+  float tmp;
+  int limit=size/2;
+  int j=size-1;
+
+  float[] theElements = elements;
+  for (int i=0; i<limit;) { //swap
+    tmp=theElements[i];
+    theElements[i++]=theElements[j];
+    theElements[j--]=tmp;
+  }
 }
 /**
  * Replaces the element at the specified position in the receiver with the specified element.
@@ -428,13 +428,13 @@
  * @param index index of element to replace.
  * @param element element to be stored at the specified position.
  * @exception IndexOutOfBoundsException index is out of range (index
- * 		  &lt; 0 || index &gt;= size()).
+ *       &lt; 0 || index &gt;= size()).
  */
 public void set(int index, float element) {
-	// overridden for performance only.
-	if (index >= size || index < 0)
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	elements[index] = element;
+  // overridden for performance only.
+  if (index >= size || index < 0)
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  elements[index] = element;
 }
 /**
  * Replaces the element at the specified position in the receiver with the specified element; <b>WARNING:</b> Does not check preconditions.
@@ -446,7 +446,7 @@
  * @param element element to be stored at the specified position.
  */
 public void setQuick(int index, float element) {
-	elements[index] = element;
+  elements[index] = element;
 }
 /**
  * Randomly permutes the part of the receiver between <code>from</code> (inclusive) and <code>to</code> (inclusive). 
@@ -455,22 +455,22 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void shuffleFromTo(int from, int to) {
-	// overridden for performance only.
-	if (size==0) {return;}
-	checkRangeFromTo(from, to, size);
-	
-	org.apache.mahout.jet.random.Uniform gen = new org.apache.mahout.jet.random.Uniform(new org.apache.mahout.jet.random.engine.DRand(new java.util.Date()));
-	float tmpElement;
-	float[] 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; 
-	}  
+  // overridden for performance only.
+  if (size==0) {return;}
+  checkRangeFromTo(from, to, size);
+  
+  org.apache.mahout.jet.random.Uniform gen = new org.apache.mahout.jet.random.Uniform(new org.apache.mahout.jet.random.engine.DRand(new java.util.Date()));
+  float tmpElement;
+  float[] 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; 
+  }  
 }
 /**
  * Trims the capacity of the receiver to be the receiver's current 
@@ -478,6 +478,6 @@
  * storage of the receiver.
  */
 public void trimToSize() {
-	elements = org.apache.mahout.matrix.Arrays.trimToCapacity(elements,size());
+  elements = org.apache.mahout.matrix.Arrays.trimToCapacity(elements,size());
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/IntArrayList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/IntArrayList.java?rev=883973&r1=883972&r2=883973&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/IntArrayList.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/IntArrayList.java Wed Nov 25 03:35:59 2009
@@ -18,17 +18,17 @@
  */
 @Deprecated
 public class IntArrayList extends AbstractIntList {
-	/**
-	 * The array buffer into which the elements of the list are stored.
-	 * The capacity of the list is the length of this array buffer.
-	 * @serial
-	 */
-	protected int[] elements;
+  /**
+   * The array buffer into which the elements of the list are stored.
+   * The capacity of the list is the length of this array buffer.
+   * @serial
+   */
+  protected int[] elements;
 /**
  * Constructs an empty list.
  */
 public IntArrayList() {
-	this(10);
+  this(10);
 }
 /**
  * Constructs a list containing the specified elements. 
@@ -40,7 +40,7 @@
  * @param elements the array to be backed by the the constructed list
  */
 public IntArrayList(int[] elements) {
-	elements(elements);
+  elements(elements);
 }
 /**
  * Constructs an empty list with the specified initial capacity.
@@ -48,8 +48,8 @@
  * @param   initialCapacity   the number of elements the receiver can hold without auto-expanding itself by allocating new internal memory.
  */
 public IntArrayList(int initialCapacity) {
-	this(new int[initialCapacity]);
-	setSizeRaw(0);
+  this(new int[initialCapacity]);
+  setSizeRaw(0);
 }
 /**
  * Appends the specified element to the end of this list.
@@ -57,11 +57,11 @@
  * @param element element to be appended to this list.
  */
 public void add(int element) {
-	// overridden for performance only.
-	if (size == elements.length) {
-		ensureCapacity(size + 1); 
-	}
-	elements[size++] = element;
+  // overridden for performance only.
+  if (size == elements.length) {
+    ensureCapacity(size + 1); 
+  }
+  elements[size++] = element;
 }
 /**
  * Inserts the specified element before the specified position into the receiver. 
@@ -73,17 +73,17 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>index &lt; 0 || index &gt; size()</tt>).
  */
 public void beforeInsert(int index, int element) {
-	// overridden for performance only.
-	if (size == index) {
-		add(element);
-		return;
-	}
-	if (index > size || index < 0) 
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	ensureCapacity(size + 1);
-	System.arraycopy(elements, index, elements, index+1, size-index);
-	elements[index] = element;
-	size++;
+  // overridden for performance only.
+  if (size == index) {
+    add(element);
+    return;
+  }
+  if (index > size || index < 0) 
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  ensureCapacity(size + 1);
+  System.arraycopy(elements, index, elements, index+1, size-index);
+  elements[index] = element;
+  size++;
 }
 /**
  * Searches the receiver for the specified value using
@@ -98,18 +98,18 @@
  * @param from the leftmost search position, inclusive.
  * @param to the rightmost search position, inclusive.
  * @return index of the search key, if it is contained in the receiver;
- *	       otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The <i>insertion
- *	       point</i> is defined as the the point at which the value would
- * 	       be inserted into the receiver: the index of the first
- *	       element greater than the key, or <tt>receiver.size()</tt>, if all
- *	       elements in the receiver are less than the specified key.  Note
- *	       that this guarantees that the return value will be &gt;= 0 if
- *	       and only if the key is found.
+ *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The <i>insertion
+ *         point</i> is defined as the the point at which the value would
+ *          be inserted into the receiver: the index of the first
+ *         element greater than the key, or <tt>receiver.size()</tt>, if all
+ *         elements in the receiver are less than the specified key.  Note
+ *         that this guarantees that the return value will be &gt;= 0 if
+ *         and only if the key is found.
  * @see org.apache.mahout.matrix.Sorting
  * @see java.util.Arrays
  */
 public int binarySearchFromTo(int key, int from, int to) {
-	return org.apache.mahout.matrix.Sorting.binarySearchFromTo(this.elements,key,from,to);
+  return org.apache.mahout.matrix.Sorting.binarySearchFromTo(this.elements,key,from,to);
 }
 /**
  * Returns a deep copy of the receiver. 
@@ -117,10 +117,10 @@
  * @return  a deep copy of the receiver.
  */
 public Object clone() {
-	// overridden for performance only.
-	IntArrayList clone = new IntArrayList((int[]) elements.clone());
-	clone.setSizeRaw(size);
-	return clone;
+  // overridden for performance only.
+  IntArrayList clone = new IntArrayList((int[]) elements.clone());
+  clone.setSizeRaw(size);
+  return clone;
 }
 /**
  * Returns a deep copy of the receiver; uses <code>clone()</code> and casts the result.
@@ -128,7 +128,7 @@
  * @return  a deep copy of the receiver.
  */
 public IntArrayList copy() {
-	return (IntArrayList) clone();
+  return (IntArrayList) clone();
 }
  /**
  * Sorts the specified range of the receiver into ascending numerical order. 
@@ -145,28 +145,28 @@
  * @param max the largest element contained in the range.
  */
 protected void countSortFromTo(int from, int to, int min, int max) {
-	if (size==0) return;
-	checkRangeFromTo(from, to, size);
+  if (size==0) return;
+  checkRangeFromTo(from, to, size);
 
-	final int width = (int) (max-min+1);
-	
-	int[] counts = new int[width];
-	int[] theElements = elements;	
-	for (int i=from; i<=to; ) counts[(int)(theElements[i++]-min)]++;
-
-	int fromIndex = from;
-	int val = min;
-	for (int i=0; i<width; i++, val++) {
-		int c = counts[i];
-		if (c>0) {
-			if (c==1) theElements[fromIndex++]=val;
-			else {
-				int toIndex = fromIndex + c - 1;
-				fillFromToWith(fromIndex,toIndex,val);
-				fromIndex = toIndex + 1;
-			}
-		}
-	}
+  final int width = (int) (max-min+1);
+  
+  int[] counts = new int[width];
+  int[] theElements = elements;  
+  for (int i=from; i<=to; ) counts[(int)(theElements[i++]-min)]++;
+
+  int fromIndex = from;
+  int val = min;
+  for (int i=0; i<width; i++, val++) {
+    int c = counts[i];
+    if (c>0) {
+      if (c==1) theElements[fromIndex++]=val;
+      else {
+        int toIndex = fromIndex + c - 1;
+        fillFromToWith(fromIndex,toIndex,val);
+        fromIndex = toIndex + 1;
+      }
+    }
+  }
 }
 /**
  * Returns the elements currently stored, including invalid elements between size and capacity, if any.
@@ -177,7 +177,7 @@
  * @return the elements currently stored.
  */
 public int[] elements() {
-	return elements;
+  return elements;
 }
 /**
  * Sets the receiver's elements to be the specified array (not a copy of it).
@@ -190,9 +190,9 @@
  * @return the receiver itself.
  */
 public AbstractIntList elements(int[] elements) {
-	this.elements=elements;
-	this.size=elements.length;
-	return this;
+  this.elements=elements;
+  this.size=elements.length;
+  return this;
 }
 /**
  * Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory.
@@ -201,7 +201,7 @@
  * @param   minCapacity   the desired minimum capacity.
  */
 public void ensureCapacity(int minCapacity) {
-	elements = org.apache.mahout.matrix.Arrays.ensureCapacity(elements,minCapacity);
+  elements = org.apache.mahout.matrix.Arrays.ensureCapacity(elements,minCapacity);
 }
 /**
  * Compares the specified Object with the receiver.  
@@ -214,19 +214,19 @@
  * @return true if the specified Object is equal to the receiver.
  */
 public boolean equals(Object otherObj) { //delta
-	// overridden for performance only.
-	if (! (otherObj instanceof IntArrayList)) return super.equals(otherObj);
-	if (this==otherObj) return true;
-	if (otherObj==null) return false;
-	IntArrayList other = (IntArrayList) otherObj;
-	if (size()!=other.size()) return false;
-
-	int[] theElements = elements();
-	int[] otherElements = other.elements();
-	for (int i=size(); --i >= 0; ) {
-	    if (theElements[i] != otherElements[i]) return false;
-	}
-	return true;
+  // overridden for performance only.
+  if (! (otherObj instanceof IntArrayList)) return super.equals(otherObj);
+  if (this==otherObj) return true;
+  if (otherObj==null) return false;
+  IntArrayList other = (IntArrayList) otherObj;
+  if (size()!=other.size()) return false;
+
+  int[] theElements = elements();
+  int[] otherElements = other.elements();
+  for (int i=size(); --i >= 0; ) {
+      if (theElements[i] != otherElements[i]) return false;
+  }
+  return true;
 }
 /**
  * Applies a procedure to each element of the receiver, if any.
@@ -235,25 +235,25 @@
  * @return <tt>false</tt> if the procedure stopped before all elements where iterated over, <tt>true</tt> otherwise. 
  */
 public boolean forEach(IntProcedure procedure) {
-	// overridden for performance only.
-	int[] theElements = elements;
-	int theSize = size;
-	
-	for (int i=0; i<theSize;) if (! procedure.apply(theElements[i++])) return false;
-	return true;
+  // overridden for performance only.
+  int[] theElements = elements;
+  int theSize = size;
+  
+  for (int i=0; i<theSize;) if (! procedure.apply(theElements[i++])) return false;
+  return true;
 }
 /**
  * Returns the element at the specified position in the receiver.
  *
  * @param index index of element to return.
  * @exception IndexOutOfBoundsException index is out of range (index
- * 		  &lt; 0 || index &gt;= size()).
+ *       &lt; 0 || index &gt;= size()).
  */
 public int get(int index) {
-	// overridden for performance only.
-	if (index >= size || index < 0)
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	return elements[index];
+  // overridden for performance only.
+  if (index >= size || index < 0)
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  return elements[index];
 }
 /**
  * Returns the element at the specified position in the receiver; <b>WARNING:</b> Does not check preconditions. 
@@ -264,7 +264,7 @@
  * @param index index of element to return.
  */
 public int getQuick(int index) {
-	return elements[index];
+  return elements[index];
 }
 /**
  * Returns the index of the first occurrence of the specified
@@ -279,15 +279,15 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public int indexOfFromTo(int element, int from, int to) {
-	// overridden for performance only.
-	if (size==0) return -1;
-	checkRangeFromTo(from, to, size);
-
-	int[] theElements = elements;
-	for (int i = from ; i <= to; i++) {
-	    if (element==theElements[i]) {return i;} //found
-	}
-	return -1; //not found
+  // overridden for performance only.
+  if (size==0) return -1;
+  checkRangeFromTo(from, to, size);
+
+  int[] 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
@@ -302,15 +302,15 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public int lastIndexOfFromTo(int element, int from, int to) {
-	// overridden for performance only.
-	if (size==0) return -1;
-	checkRangeFromTo(from, to, size);
-
-	int[] theElements = elements;
-	for (int i = to ; i >= from; i--) {
-	    if (element==theElements[i]) {return i;} //found
-	}
-	return -1; //not found
+  // overridden for performance only.
+  if (size==0) return -1;
+  checkRangeFromTo(from, to, size);
+
+  int[] theElements = elements;
+  for (int i = to ; i >= from; i--) {
+      if (element==theElements[i]) {return i;} //found
+  }
+  return -1; //not found
 }
 /**
  * Returns a new list of the part of the receiver between <code>from</code>, inclusive, and <code>to</code>, inclusive.
@@ -320,13 +320,13 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public AbstractIntList partFromTo(int from, int to) {
-	if (size==0) return new IntArrayList(0);
+  if (size==0) return new IntArrayList(0);
 
-	checkRangeFromTo(from, to, size);
+  checkRangeFromTo(from, to, size);
 
-	int[] part = new int[to-from+1];
-	System.arraycopy(elements, from, part, 0, to-from+1);
-	return new IntArrayList(part);
+  int[] part = new int[to-from+1];
+  System.arraycopy(elements, from, part, 0, to-from+1);
+  return new IntArrayList(part);
 }
 /**
 * Removes from the receiver all elements that are contained in the specified list.
@@ -336,46 +336,46 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean removeAll(AbstractIntList other) {
-	// overridden for performance only.
-	if (! (other instanceof IntArrayList))	return super.removeAll(other);
-	
-	/* There are two possibilities to do the thing
-	   a) use other.indexOf(...)
-	   b) sort other, then use other.binarySearch(...)
-	   
-	   Let's try to figure out which one is faster. Let M=size, N=other.size, then
-	   a) takes O(M*N) steps
-	   b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
+  // overridden for performance only.
+  if (! (other instanceof IntArrayList))  return super.removeAll(other);
+  
+  /* There are two possibilities to do the thing
+     a) use other.indexOf(...)
+     b) sort other, then use other.binarySearch(...)
+     
+     Let's try to figure out which one is faster. Let M=size, N=other.size, then
+     a) takes O(M*N) steps
+     b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
  
-	   Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
-	*/
-	if (other.size()==0) {return false;} //nothing to do
-	int limit = other.size()-1;
-	int j=0;
-	int[] theElements = elements;
-	int mySize = size();
-
-	double N=(double) other.size();
-	double M=(double) mySize;
-	if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
-		// it is faster to sort other before searching in it
-		IntArrayList sortedList = (IntArrayList) other.clone();
-		sortedList.quickSort();
-
-		for (int i=0; i<mySize ; i++) {
-			if (sortedList.binarySearchFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
-		}
-	}
-	else {
-		// it is faster to search in other without sorting
-		for (int i=0; i<mySize ; i++) {
-			if (other.indexOfFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
-		}
-	}
-
-	boolean modified = (j!=mySize);
-	setSize(j);
-	return modified;
+     Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
+  */
+  if (other.size()==0) {return false;} //nothing to do
+  int limit = other.size()-1;
+  int j=0;
+  int[] theElements = elements;
+  int mySize = size();
+
+  double N=(double) other.size();
+  double M=(double) mySize;
+  if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
+    // it is faster to sort other before searching in it
+    IntArrayList sortedList = (IntArrayList) other.clone();
+    sortedList.quickSort();
+
+    for (int i=0; i<mySize ; i++) {
+      if (sortedList.binarySearchFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
+    }
+  }
+  else {
+    // it is faster to search in other without sorting
+    for (int i=0; i<mySize ; i++) {
+      if (other.indexOfFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
+    }
+  }
+
+  boolean modified = (j!=mySize);
+  setSize(j);
+  return modified;
 }
 /**
  * Replaces a number of elements in the receiver with the same number of elements of another list.
@@ -388,18 +388,18 @@
  * @param otherFrom position of first element within other list to be copied.
  */
 public void replaceFromToWithFrom(int from, int to, AbstractIntList other, int otherFrom) {
-	// overridden for performance only.
-	if (! (other instanceof IntArrayList)) {
-		// 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(((IntArrayList) other).elements, otherFrom, elements, from, length);
-	}
+  // overridden for performance only.
+  if (! (other instanceof IntArrayList)) {
+    // 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(((IntArrayList) other).elements, otherFrom, elements, from, length);
+  }
 }
 /**
 * Retains (keeps) only the elements in the receiver that are contained in the specified other list.
@@ -409,62 +409,62 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean retainAll(AbstractIntList other) {
-	// overridden for performance only.
-	if (! (other instanceof IntArrayList))	return super.retainAll(other);
-	
-	/* There are two possibilities to do the thing
-	   a) use other.indexOf(...)
-	   b) sort other, then use other.binarySearch(...)
-	   
-	   Let's try to figure out which one is faster. Let M=size, N=other.size, then
-	   a) takes O(M*N) steps
-	   b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
-
-	   Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
-	*/
-	int limit = other.size()-1;
-	int j=0;
-	int[] theElements = elements;
-	int mySize = size();
-
-	double N=(double) other.size();
-	double M=(double) mySize;
-	if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
-		// it is faster to sort other before searching in it
-		IntArrayList sortedList = (IntArrayList) other.clone();
-		sortedList.quickSort();
-
-		for (int i=0; i<mySize ; i++) {
-			if (sortedList.binarySearchFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
-		}
-	}
-	else {
-		// it is faster to search in other without sorting
-		for (int i=0; i<mySize ; i++) {
-			if (other.indexOfFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
-		}
-	}
-
-	boolean modified = (j!=mySize);
-	setSize(j);
-	return modified;
+  // overridden for performance only.
+  if (! (other instanceof IntArrayList))  return super.retainAll(other);
+  
+  /* There are two possibilities to do the thing
+     a) use other.indexOf(...)
+     b) sort other, then use other.binarySearch(...)
+     
+     Let's try to figure out which one is faster. Let M=size, N=other.size, then
+     a) takes O(M*N) steps
+     b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
+
+     Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
+  */
+  int limit = other.size()-1;
+  int j=0;
+  int[] theElements = elements;
+  int mySize = size();
+
+  double N=(double) other.size();
+  double M=(double) mySize;
+  if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
+    // it is faster to sort other before searching in it
+    IntArrayList sortedList = (IntArrayList) other.clone();
+    sortedList.quickSort();
+
+    for (int i=0; i<mySize ; i++) {
+      if (sortedList.binarySearchFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
+    }
+  }
+  else {
+    // it is faster to search in other without sorting
+    for (int i=0; i<mySize ; i++) {
+      if (other.indexOfFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
+    }
+  }
+
+  boolean modified = (j!=mySize);
+  setSize(j);
+  return modified;
 }
 /**
  * Reverses the elements of the receiver.
  * Last becomes first, second last becomes second first, and so on.
  */
 public void reverse() {
-	// overridden for performance only.
-	int tmp;
-	int limit=size/2;
-	int j=size-1;
-
-	int[] theElements = elements;
-	for (int i=0; i<limit;) { //swap
-		tmp=theElements[i];
-		theElements[i++]=theElements[j];
-		theElements[j--]=tmp;
-	}
+  // overridden for performance only.
+  int tmp;
+  int limit=size/2;
+  int j=size-1;
+
+  int[] theElements = elements;
+  for (int i=0; i<limit;) { //swap
+    tmp=theElements[i];
+    theElements[i++]=theElements[j];
+    theElements[j--]=tmp;
+  }
 }
 /**
  * Replaces the element at the specified position in the receiver with the specified element.
@@ -472,13 +472,13 @@
  * @param index index of element to replace.
  * @param element element to be stored at the specified position.
  * @exception IndexOutOfBoundsException index is out of range (index
- * 		  &lt; 0 || index &gt;= size()).
+ *       &lt; 0 || index &gt;= size()).
  */
 public void set(int index, int element) {
-	// overridden for performance only.
-	if (index >= size || index < 0)
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	elements[index] = element;
+  // overridden for performance only.
+  if (index >= size || index < 0)
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  elements[index] = element;
 }
 /**
  * Replaces the element at the specified position in the receiver with the specified element; <b>WARNING:</b> Does not check preconditions.
@@ -490,7 +490,7 @@
  * @param element element to be stored at the specified position.
  */
 public void setQuick(int index, int element) {
-	elements[index] = element;
+  elements[index] = element;
 }
 /**
  * Randomly permutes the part of the receiver between <code>from</code> (inclusive) and <code>to</code> (inclusive). 
@@ -499,22 +499,22 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void shuffleFromTo(int from, int to) {
-	// overridden for performance only.
-	if (size==0) {return;}
-	checkRangeFromTo(from, to, size);
-	
-	org.apache.mahout.jet.random.Uniform gen = new org.apache.mahout.jet.random.Uniform(new org.apache.mahout.jet.random.engine.DRand(new java.util.Date()));
-	int tmpElement;
-	int[] 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; 
-	}  
+  // overridden for performance only.
+  if (size==0) {return;}
+  checkRangeFromTo(from, to, size);
+  
+  org.apache.mahout.jet.random.Uniform gen = new org.apache.mahout.jet.random.Uniform(new org.apache.mahout.jet.random.engine.DRand(new java.util.Date()));
+  int tmpElement;
+  int[] 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; 
+  }  
 }
 /**
  * Sorts the specified range of the receiver into ascending order. 
@@ -533,39 +533,39 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void sortFromTo(int from, int to) {
-	/* 
-	 * Computes min and max and decides on this basis.
-	 * In practice the additional overhead is very small compared to the potential gains.
-	 */
-	final int widthThreshold = 10000; // never consider options resulting in outrageous memory allocations.
-	
-	if (size==0) return;
-	checkRangeFromTo(from, to, size);
-
-	// determine minimum and maximum.
-	int min=elements[from];
-	int max=elements[from];
-
-	int[] theElements = elements;
-	for (int i=from+1; i<=to; ) {
-		int elem = theElements[i++];
-		if (elem>max) max=elem;
-		else if (elem<min) min=elem;
-	}
-
-	// try to figure out which option is fastest.
-	double N = (double)to - (double)from + 1.0;
-	double quickSortEstimate = 	N * Math.log(N)/0.6931471805599453; // O(N*log(N,base=2)) ; ln(2)=0.6931471805599453
-
-	double width = (double)max - (double)min + 1.0;
-	double countSortEstimate = 	Math.max(width,N); // O(Max(width,N))
-	
-	if (width < widthThreshold && countSortEstimate < quickSortEstimate) {
-		countSortFromTo(from, to, min, max);
-	}
-	else {
-		quickSortFromTo(from, to);
-	}
+  /* 
+   * Computes min and max and decides on this basis.
+   * In practice the additional overhead is very small compared to the potential gains.
+   */
+  final int widthThreshold = 10000; // never consider options resulting in outrageous memory allocations.
+  
+  if (size==0) return;
+  checkRangeFromTo(from, to, size);
+
+  // determine minimum and maximum.
+  int min=elements[from];
+  int max=elements[from];
+
+  int[] theElements = elements;
+  for (int i=from+1; i<=to; ) {
+    int elem = theElements[i++];
+    if (elem>max) max=elem;
+    else if (elem<min) min=elem;
+  }
+
+  // try to figure out which option is fastest.
+  double N = (double)to - (double)from + 1.0;
+  double quickSortEstimate =   N * Math.log(N)/0.6931471805599453; // O(N*log(N,base=2)) ; ln(2)=0.6931471805599453
+
+  double width = (double)max - (double)min + 1.0;
+  double countSortEstimate =   Math.max(width,N); // O(Max(width,N))
+  
+  if (width < widthThreshold && countSortEstimate < quickSortEstimate) {
+    countSortFromTo(from, to, min, max);
+  }
+  else {
+    quickSortFromTo(from, to);
+  }
 }
 /**
  * Trims the capacity of the receiver to be the receiver's current 
@@ -573,6 +573,6 @@
  * storage of the receiver.
  */
 public void trimToSize() {
-	elements = org.apache.mahout.matrix.Arrays.trimToCapacity(elements,size());
+  elements = org.apache.mahout.matrix.Arrays.trimToCapacity(elements,size());
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/LongArrayList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/LongArrayList.java?rev=883973&r1=883972&r2=883973&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/LongArrayList.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/LongArrayList.java Wed Nov 25 03:35:59 2009
@@ -18,17 +18,17 @@
  */
 @Deprecated
 public class LongArrayList extends AbstractLongList {
-	/**
-	 * The array buffer into which the elements of the list are stored.
-	 * The capacity of the list is the length of this array buffer.
-	 * @serial
-	 */
-	protected long[] elements;
+  /**
+   * The array buffer into which the elements of the list are stored.
+   * The capacity of the list is the length of this array buffer.
+   * @serial
+   */
+  protected long[] elements;
 /**
  * Constructs an empty list.
  */
 public LongArrayList() {
-	this(10);
+  this(10);
 }
 /**
  * Constructs a list containing the specified elements. 
@@ -40,7 +40,7 @@
  * @param elements the array to be backed by the the constructed list
  */
 public LongArrayList(long[] elements) {
-	elements(elements);
+  elements(elements);
 }
 /**
  * Constructs an empty list with the specified initial capacity.
@@ -48,8 +48,8 @@
  * @param   initialCapacity   the number of elements the receiver can hold without auto-expanding itself by allocating new internal memory.
  */
 public LongArrayList(int initialCapacity) {
-	this(new long[initialCapacity]);
-	setSizeRaw(0);
+  this(new long[initialCapacity]);
+  setSizeRaw(0);
 }
 /**
  * Appends the specified element to the end of this list.
@@ -57,9 +57,9 @@
  * @param element element to be appended to this list.
  */
 public void add(long element) {
-	// overridden for performance only.
-	if (size == elements.length) ensureCapacity(size + 1); 
-	elements[size++] = element;
+  // overridden for performance only.
+  if (size == elements.length) ensureCapacity(size + 1); 
+  elements[size++] = element;
 }
 /**
  * Inserts the specified element before the specified position into the receiver. 
@@ -71,13 +71,13 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>index &lt; 0 || index &gt; size()</tt>).
  */
 public void beforeInsert(int index, long element) {
-	// overridden for performance only.
-	if (index > size || index < 0) 
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	ensureCapacity(size + 1);
-	System.arraycopy(elements, index, elements, index+1, size-index);
-	elements[index] = element;
-	size++;
+  // overridden for performance only.
+  if (index > size || index < 0) 
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  ensureCapacity(size + 1);
+  System.arraycopy(elements, index, elements, index+1, size-index);
+  elements[index] = element;
+  size++;
 }
 /**
  * Searches the receiver for the specified value using
@@ -92,18 +92,18 @@
  * @param from the leftmost search position, inclusive.
  * @param to the rightmost search position, inclusive.
  * @return index of the search key, if it is contained in the receiver;
- *	       otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The <i>insertion
- *	       point</i> is defined as the the point at which the value would
- * 	       be inserted into the receiver: the index of the first
- *	       element greater than the key, or <tt>receiver.size()</tt>, if all
- *	       elements in the receiver are less than the specified key.  Note
- *	       that this guarantees that the return value will be &gt;= 0 if
- *	       and only if the key is found.
+ *         otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>.  The <i>insertion
+ *         point</i> is defined as the the point at which the value would
+ *          be inserted into the receiver: the index of the first
+ *         element greater than the key, or <tt>receiver.size()</tt>, if all
+ *         elements in the receiver are less than the specified key.  Note
+ *         that this guarantees that the return value will be &gt;= 0 if
+ *         and only if the key is found.
  * @see org.apache.mahout.matrix.Sorting
  * @see java.util.Arrays
  */
 public int binarySearchFromTo(long key, int from, int to) {
-	return org.apache.mahout.matrix.Sorting.binarySearchFromTo(this.elements,key,from,to);
+  return org.apache.mahout.matrix.Sorting.binarySearchFromTo(this.elements,key,from,to);
 }
 /**
  * Returns a deep copy of the receiver. 
@@ -111,10 +111,10 @@
  * @return  a deep copy of the receiver.
  */
 public Object clone() {
-	// overridden for performance only.
-	LongArrayList clone = new LongArrayList((long[]) elements.clone());
-	clone.setSizeRaw(size);
-	return clone;
+  // overridden for performance only.
+  LongArrayList clone = new LongArrayList((long[]) elements.clone());
+  clone.setSizeRaw(size);
+  return clone;
 }
 /**
  * Returns a deep copy of the receiver; uses <code>clone()</code> and casts the result.
@@ -122,7 +122,7 @@
  * @return  a deep copy of the receiver.
  */
 public LongArrayList copy() {
-	return (LongArrayList) clone();
+  return (LongArrayList) clone();
 }
  /**
  * Sorts the specified range of the receiver into ascending numerical order. 
@@ -139,28 +139,28 @@
  * @param max the largest element contained in the range.
  */
 protected void countSortFromTo(int from, int to, long min, long max) {
-	if (size==0) return;
-	checkRangeFromTo(from, to, size);
+  if (size==0) return;
+  checkRangeFromTo(from, to, size);
 
-	final int width = (int) (max-min+1);
-	
-	int[] counts = new int[width];
-	long[] theElements = elements;	
-	for (int i=from; i<=to; ) counts[(int)(theElements[i++]-min)]++;
-
-	int fromIndex = from;
-	long val = min;
-	for (int i=0; i<width; i++, val++) {
-		int c = counts[i];
-		if (c>0) {
-			if (c==1) theElements[fromIndex++]=val;
-			else {
-				int toIndex = fromIndex + c - 1;
-				fillFromToWith(fromIndex,toIndex,val);
-				fromIndex = toIndex + 1;
-			}
-		}
-	}
+  final int width = (int) (max-min+1);
+  
+  int[] counts = new int[width];
+  long[] theElements = elements;  
+  for (int i=from; i<=to; ) counts[(int)(theElements[i++]-min)]++;
+
+  int fromIndex = from;
+  long val = min;
+  for (int i=0; i<width; i++, val++) {
+    int c = counts[i];
+    if (c>0) {
+      if (c==1) theElements[fromIndex++]=val;
+      else {
+        int toIndex = fromIndex + c - 1;
+        fillFromToWith(fromIndex,toIndex,val);
+        fromIndex = toIndex + 1;
+      }
+    }
+  }
 }
 /**
  * Returns the elements currently stored, including invalid elements between size and capacity, if any.
@@ -171,7 +171,7 @@
  * @return the elements currently stored.
  */
 public long[] elements() {
-	return elements;
+  return elements;
 }
 /**
  * Sets the receiver's elements to be the specified array (not a copy of it).
@@ -184,9 +184,9 @@
  * @return the receiver itself.
  */
 public AbstractLongList elements(long[] elements) {
-	this.elements=elements;
-	this.size=elements.length;
-	return this;
+  this.elements=elements;
+  this.size=elements.length;
+  return this;
 }
 /**
  * Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory.
@@ -195,7 +195,7 @@
  * @param   minCapacity   the desired minimum capacity.
  */
 public void ensureCapacity(int minCapacity) {
-	elements = org.apache.mahout.matrix.Arrays.ensureCapacity(elements,minCapacity);
+  elements = org.apache.mahout.matrix.Arrays.ensureCapacity(elements,minCapacity);
 }
 /**
  * Compares the specified Object with the receiver.  
@@ -208,19 +208,19 @@
  * @return true if the specified Object is equal to the receiver.
  */
 public boolean equals(Object otherObj) { //delta
-	// overridden for performance only.
-	if (! (otherObj instanceof LongArrayList)) return super.equals(otherObj);
-	if (this==otherObj) return true;
-	if (otherObj==null) return false;
-	LongArrayList other = (LongArrayList) otherObj;
-	if (size()!=other.size()) return false;
-
-	long[] theElements = elements();
-	long[] otherElements = other.elements();
-	for (int i=size(); --i >= 0; ) {
-	    if (theElements[i] != otherElements[i]) return false;
-	}
-	return true;
+  // overridden for performance only.
+  if (! (otherObj instanceof LongArrayList)) return super.equals(otherObj);
+  if (this==otherObj) return true;
+  if (otherObj==null) return false;
+  LongArrayList other = (LongArrayList) otherObj;
+  if (size()!=other.size()) return false;
+
+  long[] theElements = elements();
+  long[] otherElements = other.elements();
+  for (int i=size(); --i >= 0; ) {
+      if (theElements[i] != otherElements[i]) return false;
+  }
+  return true;
 }
 /**
  * Applies a procedure to each element of the receiver, if any.
@@ -229,25 +229,25 @@
  * @return <tt>false</tt> if the procedure stopped before all elements where iterated over, <tt>true</tt> otherwise. 
  */
 public boolean forEach(LongProcedure procedure) {
-	// overridden for performance only.
-	long[] theElements = elements;
-	int theSize = size;
-	
-	for (int i=0; i<theSize;) if (! procedure.apply(theElements[i++])) return false;
-	return true;
+  // overridden for performance only.
+  long[] theElements = elements;
+  int theSize = size;
+  
+  for (int i=0; i<theSize;) if (! procedure.apply(theElements[i++])) return false;
+  return true;
 }
 /**
  * Returns the element at the specified position in the receiver.
  *
  * @param index index of element to return.
  * @exception IndexOutOfBoundsException index is out of range (index
- * 		  &lt; 0 || index &gt;= size()).
+ *       &lt; 0 || index &gt;= size()).
  */
 public long get(int index) {
-	// overridden for performance only.
-	if (index >= size || index < 0)
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	return elements[index];
+  // overridden for performance only.
+  if (index >= size || index < 0)
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  return elements[index];
 }
 /**
  * Returns the element at the specified position in the receiver; <b>WARNING:</b> Does not check preconditions. 
@@ -258,7 +258,7 @@
  * @param index index of element to return.
  */
 public long getQuick(int index) {
-	return elements[index];
+  return elements[index];
 }
 /**
  * Returns the index of the first occurrence of the specified
@@ -273,15 +273,15 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=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
+  // 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
@@ -296,15 +296,15 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=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
+  // 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 a new list of the part of the receiver between <code>from</code>, inclusive, and <code>to</code>, inclusive.
@@ -314,13 +314,13 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public AbstractLongList partFromTo(int from, int to) {
-	if (size==0) return new LongArrayList(0);
+  if (size==0) return new LongArrayList(0);
 
-	checkRangeFromTo(from, to, size);
+  checkRangeFromTo(from, to, size);
 
-	long[] part = new long[to-from+1];
-	System.arraycopy(elements, from, part, 0, to-from+1);
-	return new LongArrayList(part);
+  long[] part = new long[to-from+1];
+  System.arraycopy(elements, from, part, 0, to-from+1);
+  return new LongArrayList(part);
 }
 /**
 * Removes from the receiver all elements that are contained in the specified list.
@@ -330,46 +330,46 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean removeAll(AbstractLongList other) {
-	// overridden for performance only.
-	if (! (other instanceof LongArrayList))	return super.removeAll(other);
-	
-	/* There are two possibilities to do the thing
-	   a) use other.indexOf(...)
-	   b) sort other, then use other.binarySearch(...)
-	   
-	   Let's try to figure out which one is faster. Let M=size, N=other.size, then
-	   a) takes O(M*N) steps
-	   b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
+  // overridden for performance only.
+  if (! (other instanceof LongArrayList))  return super.removeAll(other);
+  
+  /* There are two possibilities to do the thing
+     a) use other.indexOf(...)
+     b) sort other, then use other.binarySearch(...)
+     
+     Let's try to figure out which one is faster. Let M=size, N=other.size, then
+     a) takes O(M*N) steps
+     b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
  
-	   Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
-	*/
-	if (other.size()==0) {return false;} //nothing to do
-	int limit = other.size()-1;
-	int j=0;
-	long[] theElements = elements;
-	int mySize = size();
-
-	double N=(double) other.size();
-	double M=(double) mySize;
-	if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
-		// it is faster to sort other before searching in it
-		LongArrayList sortedList = (LongArrayList) other.clone();
-		sortedList.quickSort();
-
-		for (int i=0; i<mySize ; i++) {
-			if (sortedList.binarySearchFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
-		}
-	}
-	else {
-		// it is faster to search in other without sorting
-		for (int i=0; i<mySize ; i++) {
-			if (other.indexOfFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
-		}
-	}
-
-	boolean modified = (j!=mySize);
-	setSize(j);
-	return modified;
+     Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
+  */
+  if (other.size()==0) {return false;} //nothing to do
+  int limit = other.size()-1;
+  int j=0;
+  long[] theElements = elements;
+  int mySize = size();
+
+  double N=(double) other.size();
+  double M=(double) mySize;
+  if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
+    // it is faster to sort other before searching in it
+    LongArrayList sortedList = (LongArrayList) other.clone();
+    sortedList.quickSort();
+
+    for (int i=0; i<mySize ; i++) {
+      if (sortedList.binarySearchFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
+    }
+  }
+  else {
+    // it is faster to search in other without sorting
+    for (int i=0; i<mySize ; i++) {
+      if (other.indexOfFromTo(theElements[i], 0, limit) < 0) theElements[j++]=theElements[i];
+    }
+  }
+
+  boolean modified = (j!=mySize);
+  setSize(j);
+  return modified;
 }
 /**
  * Replaces a number of elements in the receiver with the same number of elements of another list.
@@ -382,18 +382,18 @@
  * @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);
-	}
+  // 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);
+  }
 }
 /**
 * Retains (keeps) only the elements in the receiver that are contained in the specified other list.
@@ -403,62 +403,62 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean retainAll(AbstractLongList other) {
-	// overridden for performance only.
-	if (! (other instanceof LongArrayList))	return super.retainAll(other);
-	
-	/* There are two possibilities to do the thing
-	   a) use other.indexOf(...)
-	   b) sort other, then use other.binarySearch(...)
-	   
-	   Let's try to figure out which one is faster. Let M=size, N=other.size, then
-	   a) takes O(M*N) steps
-	   b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
-
-	   Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
-	*/
-	int limit = other.size()-1;
-	int j=0;
-	long[] theElements = elements;
-	int mySize = size();
-
-	double N=(double) other.size();
-	double M=(double) mySize;
-	if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
-		// it is faster to sort other before searching in it
-		LongArrayList sortedList = (LongArrayList) other.clone();
-		sortedList.quickSort();
-
-		for (int i=0; i<mySize ; i++) {
-			if (sortedList.binarySearchFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
-		}
-	}
-	else {
-		// it is faster to search in other without sorting
-		for (int i=0; i<mySize ; i++) {
-			if (other.indexOfFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
-		}
-	}
-
-	boolean modified = (j!=mySize);
-	setSize(j);
-	return modified;
+  // overridden for performance only.
+  if (! (other instanceof LongArrayList))  return super.retainAll(other);
+  
+  /* There are two possibilities to do the thing
+     a) use other.indexOf(...)
+     b) sort other, then use other.binarySearch(...)
+     
+     Let's try to figure out which one is faster. Let M=size, N=other.size, then
+     a) takes O(M*N) steps
+     b) takes O(N*logN + M*logN) steps (sorting is O(N*logN) and binarySearch is O(logN))
+
+     Hence, if N*logN + M*logN < M*N, we use b) otherwise we use a).
+  */
+  int limit = other.size()-1;
+  int j=0;
+  long[] theElements = elements;
+  int mySize = size();
+
+  double N=(double) other.size();
+  double M=(double) mySize;
+  if ( (N+M)* org.apache.mahout.jet.math.Arithmetic.log2(N) < M*N ) {
+    // it is faster to sort other before searching in it
+    LongArrayList sortedList = (LongArrayList) other.clone();
+    sortedList.quickSort();
+
+    for (int i=0; i<mySize ; i++) {
+      if (sortedList.binarySearchFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
+    }
+  }
+  else {
+    // it is faster to search in other without sorting
+    for (int i=0; i<mySize ; i++) {
+      if (other.indexOfFromTo(theElements[i], 0, limit) >= 0) theElements[j++]=theElements[i];
+    }
+  }
+
+  boolean modified = (j!=mySize);
+  setSize(j);
+  return modified;
 }
 /**
  * Reverses the elements of the receiver.
  * Last becomes first, second last becomes second first, and so on.
  */
 public void reverse() {
-	// overridden for performance only.
-	long tmp;
-	int limit=size/2;
-	int j=size-1;
-
-	long[] theElements = elements;
-	for (int i=0; i<limit;) { //swap
-		tmp=theElements[i];
-		theElements[i++]=theElements[j];
-		theElements[j--]=tmp;
-	}
+  // overridden for performance only.
+  long tmp;
+  int limit=size/2;
+  int j=size-1;
+
+  long[] theElements = elements;
+  for (int i=0; i<limit;) { //swap
+    tmp=theElements[i];
+    theElements[i++]=theElements[j];
+    theElements[j--]=tmp;
+  }
 }
 /**
  * Replaces the element at the specified position in the receiver with the specified element.
@@ -466,13 +466,13 @@
  * @param index index of element to replace.
  * @param element element to be stored at the specified position.
  * @exception IndexOutOfBoundsException index is out of range (index
- * 		  &lt; 0 || index &gt;= size()).
+ *       &lt; 0 || index &gt;= size()).
  */
 public void set(int index, long element) {
-	// overridden for performance only.
-	if (index >= size || index < 0)
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	elements[index] = element;
+  // overridden for performance only.
+  if (index >= size || index < 0)
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  elements[index] = element;
 }
 /**
  * Replaces the element at the specified position in the receiver with the specified element; <b>WARNING:</b> Does not check preconditions.
@@ -484,7 +484,7 @@
  * @param element element to be stored at the specified position.
  */
 public void setQuick(int index, long element) {
-	elements[index] = element;
+  elements[index] = element;
 }
 /**
  * Randomly permutes the part of the receiver between <code>from</code> (inclusive) and <code>to</code> (inclusive). 
@@ -493,22 +493,22 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void shuffleFromTo(int from, int to) {
-	// overridden for performance only.
-	if (size==0) return;
-	checkRangeFromTo(from, to, size);
-	
-	org.apache.mahout.jet.random.Uniform gen = new org.apache.mahout.jet.random.Uniform(new org.apache.mahout.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; 
-	}  
+  // overridden for performance only.
+  if (size==0) return;
+  checkRangeFromTo(from, to, size);
+  
+  org.apache.mahout.jet.random.Uniform gen = new org.apache.mahout.jet.random.Uniform(new org.apache.mahout.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; 
+  }  
 }
 /**
  * Sorts the specified range of the receiver into ascending order. 
@@ -527,39 +527,39 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void sortFromTo(int from, int to) {
-	/* 
-	 * Computes min and max and decides on this basis.
-	 * In practice the additional overhead is very small compared to the potential gains.
-	 */
-	final int widthThreshold = 10000; // never consider options resulting in outrageous memory allocations.
-	
-	if (size==0) return;
-	checkRangeFromTo(from, to, size);
-
-	// determine minimum and maximum.
-	long min=elements[from];
-	long max=elements[from];
-
-	long[] theElements = elements;
-	for (int i=from+1; i<=to; ) {
-		long elem = theElements[i++];
-		if (elem>max) max=elem;
-		else if (elem<min) min=elem;
-	}
-
-	// try to figure out which option is fastest.
-	double N = (double)to - (double)from + 1.0;
-	double quickSortEstimate = 	N * Math.log(N)/0.6931471805599453; // O(N*log(N,base=2)) ; ln(2)=0.6931471805599453
-
-	double width = (double)max - (double)min + 1.0;
-	double countSortEstimate = 	Math.max(width,N); // O(Max(width,N))
-	
-	if (width < widthThreshold && countSortEstimate < quickSortEstimate) {
-		countSortFromTo(from, to, min, max);
-	}
-	else {
-		quickSortFromTo(from, to);
-	}
+  /* 
+   * Computes min and max and decides on this basis.
+   * In practice the additional overhead is very small compared to the potential gains.
+   */
+  final int widthThreshold = 10000; // never consider options resulting in outrageous memory allocations.
+  
+  if (size==0) return;
+  checkRangeFromTo(from, to, size);
+
+  // determine minimum and maximum.
+  long min=elements[from];
+  long max=elements[from];
+
+  long[] theElements = elements;
+  for (int i=from+1; i<=to; ) {
+    long elem = theElements[i++];
+    if (elem>max) max=elem;
+    else if (elem<min) min=elem;
+  }
+
+  // try to figure out which option is fastest.
+  double N = (double)to - (double)from + 1.0;
+  double quickSortEstimate =   N * Math.log(N)/0.6931471805599453; // O(N*log(N,base=2)) ; ln(2)=0.6931471805599453
+
+  double width = (double)max - (double)min + 1.0;
+  double countSortEstimate =   Math.max(width,N); // O(Max(width,N))
+  
+  if (width < widthThreshold && countSortEstimate < quickSortEstimate) {
+    countSortFromTo(from, to, min, max);
+  }
+  else {
+    quickSortFromTo(from, to);
+  }
 }
 /**
  * Trims the capacity of the receiver to be the receiver's current 
@@ -567,6 +567,6 @@
  * storage of the receiver.
  */
 public void trimToSize() {
-	elements = org.apache.mahout.matrix.Arrays.trimToCapacity(elements,size());
+  elements = org.apache.mahout.matrix.Arrays.trimToCapacity(elements,size());
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/MinMaxNumberList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/MinMaxNumberList.java?rev=883973&r1=883972&r2=883973&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/MinMaxNumberList.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/MinMaxNumberList.java Wed Nov 25 03:35:59 2009
@@ -62,18 +62,16 @@
  * @see DistinctNumberList
  * @see java.lang.Float
  * @see java.lang.Double
- * @author wolfgang.hoschek@cern.ch
- * @version 1.0, 09/24/99
  */
 /** 
  * @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported.
  */
 @Deprecated
 public class MinMaxNumberList extends org.apache.mahout.matrix.list.AbstractLongList {
-	protected long minValue;
-	protected int bitsPerElement;
-	protected long[] bits;
-	protected int capacity;
+  protected long minValue;
+  protected int bitsPerElement;
+  protected long[] bits;
+  protected int capacity;
 /**
  * Constructs an empty list with the specified initial capacity and the specified range of values allowed to be hold in this list.
  * Legal values are in the range [minimum,maximum], all inclusive.
@@ -82,7 +80,7 @@
  * @param   initialCapacity   the number of elements the receiver can hold without auto-expanding itself by allocating new internal memory.
  */
 public MinMaxNumberList(long minimum, long maximum, int initialCapacity) {
-	this.setUp(minimum, maximum, initialCapacity);
+  this.setUp(minimum, maximum, initialCapacity);
 }
 /**
  * Appends the specified element to the end of this list.
@@ -90,13 +88,13 @@
  * @param element element to be appended to this list.
  */
 public void add(long element) {
-	// overridden for performance only.
-	if (size == capacity) {
-		ensureCapacity(size + 1); 
-	}
-	int i=size*this.bitsPerElement;
-	QuickBitVector.putLongFromTo(this.bits, element-this.minValue,i,i+this.bitsPerElement-1);
-	size++;
+  // overridden for performance only.
+  if (size == capacity) {
+    ensureCapacity(size + 1); 
+  }
+  int i=size*this.bitsPerElement;
+  QuickBitVector.putLongFromTo(this.bits, element-this.minValue,i,i+this.bitsPerElement-1);
+  size++;
 }
 /**
  * Appends the elements <tt>elements[from]</tt> (inclusive), ..., <tt>elements[to]</tt> (inclusive) to the receiver.
@@ -105,44 +103,44 @@
  * @param to the index of the last element to be appended (inclusive)
  */
 public void addAllOfFromTo(long[] elements, int from, int to) {
-	// cache some vars for speed.
-	int bitsPerElem = this.bitsPerElement;
-	int bitsPerElemMinusOne = bitsPerElem-1;
-	long min = this.minValue;
-	long[] theBits = this.bits;
+  // cache some vars for speed.
+  int bitsPerElem = this.bitsPerElement;
+  int bitsPerElemMinusOne = bitsPerElem-1;
+  long min = this.minValue;
+  long[] theBits = this.bits;
 
-	// now let's go.
-	ensureCapacity(this.size+to-from+1);
-	int firstBit = this.size*bitsPerElem;
-	int i=from;
-	for (int times=to-from+1; --times >=0; ) {
-		QuickBitVector.putLongFromTo(theBits, elements[i++]-min, firstBit, firstBit+bitsPerElemMinusOne);
-		firstBit += bitsPerElem;
-	}
-	this.size += (to-from+1); //*bitsPerElem;
+  // now let's go.
+  ensureCapacity(this.size+to-from+1);
+  int firstBit = this.size*bitsPerElem;
+  int i=from;
+  for (int times=to-from+1; --times >=0; ) {
+    QuickBitVector.putLongFromTo(theBits, elements[i++]-min, firstBit, firstBit+bitsPerElemMinusOne);
+    firstBit += bitsPerElem;
+  }
+  this.size += (to-from+1); //*bitsPerElem;
 }
 /**
  * Returns the number of bits necessary to store a single element.
  */
 public int bitsPerElement() {
-	return this.bitsPerElement;
+  return this.bitsPerElement;
 }
 /**
  * Returns the number of bits necessary to store values in the range <tt>[minimum,maximum]</tt>.
  */
 public static int bitsPerElement(long minimum, long maximum) {
-	int bits;
-	if (1+maximum-minimum > 0) {
-		bits=(int) Math.round(Math.ceil(org.apache.mahout.jet.math.Arithmetic.log(2,1+maximum-minimum)));
-	}
-	else {	
-		// overflow or underflow in calculating "1+maximum-minimum"
-		// happens if signed long representation is too short for doing unsigned calculations
-		// e.g. if minimum==LONG.MIN_VALUE, maximum==LONG.MAX_VALUE
-		// --> in such cases store all bits of values without any compression.
-		bits=64;
-	}
-	return bits;
+  int bits;
+  if (1+maximum-minimum > 0) {
+    bits=(int) Math.round(Math.ceil(org.apache.mahout.jet.math.Arithmetic.log(2,1+maximum-minimum)));
+  }
+  else {  
+    // overflow or underflow in calculating "1+maximum-minimum"
+    // happens if signed long representation is too short for doing unsigned calculations
+    // e.g. if minimum==LONG.MIN_VALUE, maximum==LONG.MAX_VALUE
+    // --> in such cases store all bits of values without any compression.
+    bits=64;
+  }
+  return bits;
 }
 /**
  * Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory.
@@ -151,15 +149,15 @@
  * @param   minCapacity   the desired minimum capacity.
  */
 public void ensureCapacity(int minCapacity) {
-	int oldCapacity = capacity;
-	if (minCapacity > oldCapacity) {
-	    int newCapacity = (oldCapacity * 3)/2 + 1;
-		if (newCapacity < minCapacity)	newCapacity = minCapacity;
-		BitVector vector = toBitVector();
-		vector.setSize(newCapacity*bitsPerElement);
-		this.bits = vector.elements();
-		this.capacity = newCapacity;
-	}
+  int oldCapacity = capacity;
+  if (minCapacity > oldCapacity) {
+      int newCapacity = (oldCapacity * 3)/2 + 1;
+    if (newCapacity < minCapacity)  newCapacity = minCapacity;
+    BitVector vector = toBitVector();
+    vector.setSize(newCapacity*bitsPerElement);
+    this.bits = vector.elements();
+    this.capacity = newCapacity;
+  }
 }
 /**
  * Returns the element at the specified position in the receiver; <b>WARNING:</b> Does not check preconditions. 
@@ -170,8 +168,8 @@
  * @param index index of element to return.
  */
 public long getQuick(int index) {
-	int i=index*this.bitsPerElement;
-	return this.minValue + QuickBitVector.getLongFromTo(this.bits, i,i+this.bitsPerElement-1);
+  int i=index*this.bitsPerElement;
+  return this.minValue + QuickBitVector.getLongFromTo(this.bits, i,i+this.bitsPerElement-1);
 }
 /**
  * Copies all elements between index <tt>from</tt> (inclusive) and <tt>to</tt> (inclusive) into <tt>part</tt>, starting at index <tt>partFrom</tt> within <tt>part</tt>.
@@ -185,29 +183,29 @@
  * </pre>
  */
 public void partFromTo(final int from, final int to, final BitVector qualificants, final int qualificantsFrom, long[] part, final int partFrom) {
-	int width = to-from+1;
-	if (from<0 || from>to || to>=size || qualificantsFrom<0 || (qualificants!=null && qualificantsFrom+width>qualificants.size())) {
-		throw new IndexOutOfBoundsException();
-	}
-	if (partFrom<0 || partFrom+width>part.length) {
-		throw new IndexOutOfBoundsException();
-	}
-	
-	long minVal = this.minValue;
-	int bitsPerElem = this.bitsPerElement;
-	long[] theBits = this.bits;
-	
-	int q = qualificantsFrom;
-	int p = partFrom;
-	int j=from*bitsPerElem;
+  int width = to-from+1;
+  if (from<0 || from>to || to>=size || qualificantsFrom<0 || (qualificants!=null && qualificantsFrom+width>qualificants.size())) {
+    throw new IndexOutOfBoundsException();
+  }
+  if (partFrom<0 || partFrom+width>part.length) {
+    throw new IndexOutOfBoundsException();
+  }
+  
+  long minVal = this.minValue;
+  int bitsPerElem = this.bitsPerElement;
+  long[] theBits = this.bits;
+  
+  int q = qualificantsFrom;
+  int p = partFrom;
+  int j=from*bitsPerElem;
 
-	//BitVector tmpBitVector = new BitVector(this.bits, this.size*bitsPerElem);
-	for (int i=from; i<=to; i++, q++, p++, j += bitsPerElem) {
-		if (qualificants==null || qualificants.get(q)) {
-			//part[p] = minVal + tmpBitVector.getLongFromTo(j, j+bitsPerElem-1);
-			part[p] = minVal + QuickBitVector.getLongFromTo(theBits, j, j+bitsPerElem-1);
-		}
-	}
+  //BitVector tmpBitVector = new BitVector(this.bits, this.size*bitsPerElem);
+  for (int i=from; i<=to; i++, q++, p++, j += bitsPerElem) {
+    if (qualificants==null || qualificants.get(q)) {
+      //part[p] = minVal + tmpBitVector.getLongFromTo(j, j+bitsPerElem-1);
+      part[p] = minVal + QuickBitVector.getLongFromTo(theBits, j, j+bitsPerElem-1);
+    }
+  }
 }
 /**
  * Replaces the element at the specified position in the receiver with the specified element; <b>WARNING:</b> Does not check preconditions. 
@@ -219,15 +217,15 @@
  * @param element element to be stored at the specified position.
  */
 public void setQuick(int index, long element) {
-	int i=index*this.bitsPerElement;
-	QuickBitVector.putLongFromTo(this.bits, element-this.minValue,i,i+this.bitsPerElement-1);
+  int i=index*this.bitsPerElement;
+  QuickBitVector.putLongFromTo(this.bits, element-this.minValue,i,i+this.bitsPerElement-1);
 }
 /**
  * Sets the size of the receiver without modifying it otherwise.
  * This method should not release or allocate new memory but simply set some instance variable like <tt>size</tt>.
  */
 protected void setSizeRaw(int newSize) {
-	super.setSizeRaw(newSize);
+  super.setSizeRaw(newSize);
 }
 /**
  * Sets the receiver to an empty list with the specified initial capacity and the specified range of values allowed to be hold in this list.
@@ -237,12 +235,12 @@
  * @param   initialCapacity   the number of elements the receiver can hold without auto-expanding itself by allocating new internal memory.
  */
 protected void setUp(long minimum, long maximum, int initialCapacity) {
-	setUpBitsPerEntry(minimum, maximum);
+  setUpBitsPerEntry(minimum, maximum);
 
-	//this.capacity=initialCapacity;
-	this.bits = QuickBitVector.makeBitVector(initialCapacity,this.bitsPerElement);
-	this.capacity = initialCapacity;
-	this.size=0;	
+  //this.capacity=initialCapacity;
+  this.bits = QuickBitVector.makeBitVector(initialCapacity,this.bitsPerElement);
+  this.capacity = initialCapacity;
+  this.size=0;  
 }
 /**
  * This method was created in VisualAge.
@@ -251,24 +249,24 @@
  * @param initialCapacity int
  */
 protected void setUpBitsPerEntry(long minimum, long maximum) {
-	this.bitsPerElement=this.bitsPerElement(minimum, maximum);
-	if (this.bitsPerElement!=64) { 
-		this.minValue=minimum;	
-			// overflow or underflow in calculating "1+maxValue-minValue"
-			// happens if signed long representation is too short for doing unsigned calculations
-			// e.g. if minValue==LONG.MIN_VALUE, maxValue=LONG.MAX_VALUE
-			// --> in such cases store all bits of values without any en/decoding
-	}
-	else {
-		this.minValue=0;
-	};
+  this.bitsPerElement=this.bitsPerElement(minimum, maximum);
+  if (this.bitsPerElement!=64) { 
+    this.minValue=minimum;  
+      // overflow or underflow in calculating "1+maxValue-minValue"
+      // happens if signed long representation is too short for doing unsigned calculations
+      // e.g. if minValue==LONG.MIN_VALUE, maxValue=LONG.MAX_VALUE
+      // --> in such cases store all bits of values without any en/decoding
+  }
+  else {
+    this.minValue=0;
+  };
 }
 /**
  * Returns the receiver seen as bitvector.
  * WARNING: The bitvector and the receiver share the backing bits. Modifying one of them will affect the other.
  */
 public BitVector toBitVector() {
-	return new BitVector(this.bits, this.capacity*bitsPerElement);
+  return new BitVector(this.bits, this.capacity*bitsPerElement);
 }
 /**
  * Trims the capacity of the receiver to be the receiver's current 
@@ -276,13 +274,13 @@
  * storage of the receiver. 
  */
 public void trimToSize() {
-	int oldCapacity = capacity;
-	if (size < oldCapacity) {
-		BitVector vector = toBitVector();
-		vector.setSize(size);
-		this.bits = vector.elements();
-		this.capacity = size;
-	}
+  int oldCapacity = capacity;
+  if (size < oldCapacity) {
+    BitVector vector = toBitVector();
+    vector.setSize(size);
+    this.bits = vector.elements();
+    this.capacity = size;
+  }
 }
 /**
  * deprecated
@@ -291,6 +289,6 @@
  * @deprecated
  */
 public long xminimum() {
-	return this.minValue;
+  return this.minValue;
 }
 }



Mime
View raw message