mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r883973 [8/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/AbstractLongList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractLongList.java?rev=883973&r1=883972&r2=883973&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractLongList.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractLongList.java Wed Nov 25 03:35:59 2009
@@ -19,13 +19,13 @@
  */
 @Deprecated
 public abstract class AbstractLongList extends AbstractList {
-	/**
-	 * The size of the list.
-	 * This is a READ_ONLY variable for all methods but setSizeRaw(int newSize) !!!
-	 * If you violate this principle in subclasses, you should exactly know what you are doing.
-	 * @serial
-	 */
-	protected int size;
+  /**
+   * The size of the list.
+   * This is a READ_ONLY variable for all methods but setSizeRaw(int newSize) !!!
+   * If you violate this principle in subclasses, you should exactly know what you are doing.
+   * @serial
+   */
+  protected int size;
 /**
  * Makes this class non instantiable, but still let's others inherit from it.
  */
@@ -36,7 +36,7 @@
  * @param element element to be appended to this list.
  */
 public void add(long element) {
-	beforeInsert(size,element);
+  beforeInsert(size,element);
 }
 /**
  * Appends the part of the specified list between <code>from</code> (inclusive) and <code>to</code> (inclusive) to the receiver.
@@ -47,7 +47,7 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>other.size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=other.size())</tt>).
  */
 public void addAllOfFromTo(AbstractLongList other, int from, int to) {
-	beforeInsertAllOfFromTo(size,other,from,to);
+  beforeInsertAllOfFromTo(size,other,from,to);
 }
 /**
  * Inserts the specified element before the specified position into the receiver. 
@@ -59,8 +59,8 @@
  * @throws IndexOutOfBoundsException if <tt>index &lt; 0 || index &gt; size()</tt>.
  */
 public void beforeInsert(int index, long element) {
-	beforeInsertDummies(index,1);
-	set(index,element);
+  beforeInsertDummies(index,1);
+  set(index,element);
 }
 /**
  * Inserts the part of the specified list between <code>otherFrom</code> (inclusive) and <code>otherTo</code> (inclusive) before the specified position into the receiver. 
@@ -75,9 +75,9 @@
  * @throws IndexOutOfBoundsException if <tt>index &lt; 0 || index &gt; size()</tt>.
  */
 public void beforeInsertAllOfFromTo(int index, AbstractLongList other, int from, int to) {
-	int length=to-from+1;
-	this.beforeInsertDummies(index, length);
-	this.replaceFromToWithFrom(index, index+length-1, other, from);
+  int length=to-from+1;
+  this.beforeInsertDummies(index, length);
+  this.replaceFromToWithFrom(index, index+length-1, other, from);
 }
 /**
  * Inserts <tt>length</tt> dummy elements before the specified position into the receiver. 
@@ -90,13 +90,13 @@
  * @throws IndexOutOfBoundsException if <tt>index &lt; 0 || index &gt; size()</tt>.
  */
 protected void beforeInsertDummies(int index, int length) {
-	if (index > size || index < 0) 
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	if (length > 0) {
-		ensureCapacity(size + length);
-		setSizeRaw(size + length);
-		replaceFromToWithFrom(index+length,size-1,this,index);
-	}
+  if (index > size || index < 0) 
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  if (length > 0) {
+    ensureCapacity(size + length);
+    setSizeRaw(size + length);
+    replaceFromToWithFrom(index+length,size-1,this,index);
+  }
 }
 /**
  * Searches the receiver for the specified value using
@@ -109,17 +109,17 @@
  *
  * @param key the value to be searched for.
  * @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 java.util.Arrays
  */
 public int binarySearch(long key) {
-	return this.binarySearchFromTo(key, 0, size-1);
+  return this.binarySearchFromTo(key, 0, size-1);
 }
 /**
  * Searches the receiver for the specified value using
@@ -134,27 +134,27 @@
  * @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 java.util.Arrays
  */
 public int binarySearchFromTo(long key, int from, int to) {
-	int low=from;
-	int high=to;
-	while (low <= high) {
-		int mid =(low + high)/2;
-		long midVal = get(mid);
-
-		if (midVal < key) low = mid + 1;
-		else if (midVal > key) high = mid - 1;
-		else return mid; // key found
-	}
-	return -(low + 1);  // key not found.
+  int low=from;
+  int high=to;
+  while (low <= high) {
+    int mid =(low + high)/2;
+    long midVal = get(mid);
+
+    if (midVal < key) low = mid + 1;
+    else if (midVal > key) high = mid - 1;
+    else return mid; // key found
+  }
+  return -(low + 1);  // key not found.
 }
 /**
  * Returns a deep copy of the receiver. 
@@ -162,7 +162,7 @@
  * @return  a deep copy of the receiver.
  */
 public Object clone() {
-	return partFromTo(0,size-1);
+  return partFromTo(0,size-1);
 }
 /**
  * Returns true if the receiver contains the specified element.
@@ -170,7 +170,7 @@
  * @param element element whose presence in the receiver is to be tested.
  */
 public boolean contains(long elem) {
-	return indexOfFromTo(elem,0,size-1) >=0;
+  return indexOfFromTo(elem,0,size-1) >=0;
 }
 /**
  * Deletes the first element from the receiver that is identical to the specified element.
@@ -179,8 +179,8 @@
  * @param element the element to be deleted.
  */
 public void delete(long element) {
-	int index = indexOfFromTo(element, 0, size-1);
-	if (index>=0) remove(index);
+  int index = indexOfFromTo(element, 0, size-1);
+  if (index>=0) remove(index);
 }
 /**
  * Returns the elements currently stored, possibly including invalid elements between size and capacity.
@@ -191,9 +191,9 @@
  * @return the elements currently stored.
  */
 public long[] elements() {
-	long[] myElements = new long[size];
-	for (int i=size; --i >= 0; ) myElements[i]=getQuick(i);
-	return myElements;
+  long[] myElements = new long[size];
+  for (int i=size; --i >= 0; ) myElements[i]=getQuick(i);
+  return myElements;
 }
 /**
  * Sets the receiver's elements to be the specified array.
@@ -205,9 +205,9 @@
  * @return the receiver itself.
  */
 public AbstractLongList elements(long[] elements) {
-	clear();
-	addAllOfFromTo(new LongArrayList(elements),0,elements.length-1);
-	return this;
+  clear();
+  addAllOfFromTo(new LongArrayList(elements),0,elements.length-1);
+  return this;
 }
 /**
  * Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory.
@@ -227,16 +227,16 @@
  * @return true if the specified Object is equal to the receiver.
  */
 public boolean equals(Object otherObj) { //delta
-	if (! (otherObj instanceof AbstractLongList)) {return false;}
-	if (this==otherObj) return true;
-	if (otherObj==null) return false;
-	AbstractLongList other = (AbstractLongList) otherObj;
-	if (size()!=other.size()) return false;
-
-	for (int i=size(); --i >= 0; ) {
-	    if (getQuick(i) != other.getQuick(i)) return false;
-	}
-	return true;
+  if (! (otherObj instanceof AbstractLongList)) {return false;}
+  if (this==otherObj) return true;
+  if (otherObj==null) return false;
+  AbstractLongList other = (AbstractLongList) otherObj;
+  if (size()!=other.size()) return false;
+
+  for (int i=size(); --i >= 0; ) {
+      if (getQuick(i) != other.getQuick(i)) return false;
+  }
+  return true;
 }
 /**
  * Sets the specified range of elements in the specified array to the specified value.
@@ -246,8 +246,8 @@
  * @param val the value to be stored in the specified elements of the receiver.
  */
 public void fillFromToWith(int from, int to, long val) {
-	checkRangeFromTo(from,to,this.size);
-	for (int i=from; i<=to;) setQuick(i++,val); 
+  checkRangeFromTo(from,to,this.size);
+  for (int i=from; i<=to;) setQuick(i++,val); 
 }
 /**
  * Applies a procedure to each element of the receiver, if any.
@@ -256,20 +256,20 @@
  * @return <tt>false</tt> if the procedure stopped before all elements where iterated over, <tt>true</tt> otherwise. 
  */
 public boolean forEach(LongProcedure procedure) {
-	for (int i=0; i<size;) if (! procedure.apply(get(i++))) return false;
-	return true;
+  for (int i=0; i<size;) if (! procedure.apply(get(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) {
-	if (index >= size || index < 0)
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	return getQuick(index);
+  if (index >= size || index < 0)
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  return getQuick(index);
 }
 /**
  * Returns the element at the specified position in the receiver; <b>WARNING:</b> Does not check preconditions. 
@@ -291,7 +291,7 @@
  * @return  the index of the first occurrence of the element in the receiver; returns <code>-1</code> if the element is not found.
  */
 public int indexOf(long element) { //delta
-	return indexOfFromTo(element, 0, size-1);
+  return indexOfFromTo(element, 0, size-1);
 }
 /**
  * Returns the index of the first occurrence of the specified
@@ -306,12 +306,12 @@
  * @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) {
-	checkRangeFromTo(from, to, size);
+  checkRangeFromTo(from, to, size);
 
-	for (int i = from ; i <= to; i++) {
-	    if (element==getQuick(i)) return i; //found
-	}
-	return -1; //not found
+  for (int i = from ; i <= to; i++) {
+      if (element==getQuick(i)) return i; //found
+  }
+  return -1; //not found
 }
 /**
  * Returns the index of the last occurrence of the specified
@@ -321,7 +321,7 @@
  * @return  the index of the last occurrence of the element in the receiver; returns <code>-1</code> if the element is not found.
  */
 public int lastIndexOf(long element) {
-	return lastIndexOfFromTo(element, 0, size-1);
+  return lastIndexOfFromTo(element, 0, size-1);
 }
 /**
  * Returns the index of the last occurrence of the specified
@@ -336,12 +336,12 @@
  * @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) {
-	checkRangeFromTo(from, to, size());
+  checkRangeFromTo(from, to, size());
 
-	for (int i = to ; i >= from; i--) {
-	    if (element==getQuick(i)) return i; //found
-	}
-	return -1; //not found
+  for (int i = to ; i >= from; i--) {
+      if (element==getQuick(i)) return i; //found
+  }
+  return -1; //not found
 }
 /**
  * Sorts the specified range of the receiver into ascending order. 
@@ -360,13 +360,13 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void mergeSortFromTo(int from, int to) {
-	int mySize = size();
-	checkRangeFromTo(from, to, mySize);
-	
-	long[] myElements = elements();
-	org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1);
-	elements(myElements);
-	setSizeRaw(mySize);
+  int mySize = size();
+  checkRangeFromTo(from, to, mySize);
+  
+  long[] myElements = elements();
+  org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1);
+  elements(myElements);
+  setSizeRaw(mySize);
 }
 /**
  * Sorts the receiver according
@@ -390,21 +390,21 @@
  * @param to the index of the last element (inclusive) to be sorted.
  * @param c the comparator to determine the order of the receiver.
  * @throws ClassCastException if the array contains elements that are not
- *	       <i>mutually comparable</i> using the specified comparator.
+ *         <i>mutually comparable</i> using the specified comparator.
  * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
  * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
- *	       <tt>toIndex &gt; a.length</tt>
+ *         <tt>toIndex &gt; a.length</tt>
  * @see Comparator
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void mergeSortFromTo(int from, int to, LongComparator c) {
-	int mySize = size();
-	checkRangeFromTo(from, to, mySize);
-	
-	long[] myElements = elements();
-	org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1, c);
-	elements(myElements);
-	setSizeRaw(mySize);
+  int mySize = size();
+  checkRangeFromTo(from, to, mySize);
+  
+  long[] myElements = elements();
+  org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1, c);
+  elements(myElements);
+  setSizeRaw(mySize);
 }
 /**
  * Returns a new list of the part of the receiver between <code>from</code>, inclusive, and <code>to</code>, inclusive.
@@ -414,12 +414,12 @@
  * @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) {
-	checkRangeFromTo(from, to, size);
+  checkRangeFromTo(from, to, size);
 
-	int length = to-from+1;
-	LongArrayList part = new LongArrayList(length);
-	part.addAllOfFromTo(this,from,to);
-	return part;
+  int length = to-from+1;
+  LongArrayList part = new LongArrayList(length);
+  part.addAllOfFromTo(this,from,to);
+  return part;
 }
 /**
  * Sorts the specified range of the receiver into
@@ -438,13 +438,13 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void quickSortFromTo(int from, int to) {
-	int mySize = size();
-	checkRangeFromTo(from, to, mySize);
-	
-	long[] myElements = elements();
-	java.util.Arrays.sort(myElements, from, to+1);
-	elements(myElements);
-	setSizeRaw(mySize);
+  int mySize = size();
+  checkRangeFromTo(from, to, mySize);
+  
+  long[] myElements = elements();
+  java.util.Arrays.sort(myElements, from, to+1);
+  elements(myElements);
+  setSizeRaw(mySize);
 }
 /**
  * Sorts the receiver according
@@ -466,21 +466,21 @@
  * @param to the index of the last element (inclusive) to be sorted.
  * @param c the comparator to determine the order of the receiver.
  * @throws ClassCastException if the array contains elements that are not
- *	       <i>mutually comparable</i> using the specified comparator.
+ *         <i>mutually comparable</i> using the specified comparator.
  * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
  * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
- *	       <tt>toIndex &gt; a.length</tt>
+ *         <tt>toIndex &gt; a.length</tt>
  * @see Comparator
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void quickSortFromTo(int from, int to, LongComparator c) {
-	int mySize = size();
-	checkRangeFromTo(from, to, mySize);
-	
-	long[] myElements = elements();
-	org.apache.mahout.matrix.Sorting.quickSort(myElements, from, to+1,c);
-	elements(myElements);
-	setSizeRaw(mySize);
+  int mySize = size();
+  checkRangeFromTo(from, to, mySize);
+  
+  long[] myElements = elements();
+  org.apache.mahout.matrix.Sorting.quickSort(myElements, from, to+1,c);
+  elements(myElements);
+  setSizeRaw(mySize);
 }
 /**
 * Removes from the receiver all elements that are contained in the specified list.
@@ -490,17 +490,17 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean removeAll(AbstractLongList other) {
-	if (other.size()==0) return false; //nothing to do
-	int limit = other.size()-1;
-	int j=0;
-
-	for (int i=0; i<size ; i++) {
-		if (other.indexOfFromTo(getQuick(i), 0, limit) < 0) setQuick(j++,getQuick(i));
-	}
-
-	boolean modified = (j!=size);
-	setSize(j);
-	return modified;
+  if (other.size()==0) return false; //nothing to do
+  int limit = other.size()-1;
+  int j=0;
+
+  for (int i=0; i<size ; i++) {
+    if (other.indexOfFromTo(getQuick(i), 0, limit) < 0) setQuick(j++,getQuick(i));
+  }
+
+  boolean modified = (j!=size);
+  setSize(j);
+  return modified;
 }
 /**
  * Removes from the receiver all elements whose index is between
@@ -513,14 +513,14 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void removeFromTo(int from, int to) {
-	checkRangeFromTo(from, to, size);
-	int numMoved = size - to - 1;
-	if (numMoved > 0) {
-		replaceFromToWithFrom(from, from-1+numMoved, this, to+1);
-		//fillFromToWith(from+numMoved, size-1, 0.0f); //delta
-	}
-	int width = to-from+1;
-	if (width>0) setSizeRaw(size-width);
+  checkRangeFromTo(from, to, size);
+  int numMoved = size - to - 1;
+  if (numMoved > 0) {
+    replaceFromToWithFrom(from, from-1+numMoved, this, to+1);
+    //fillFromToWith(from+numMoved, size-1, 0.0f); //delta
+  }
+  int width = to-from+1;
+  if (width>0) setSizeRaw(size-width);
 }
 /**
  * Replaces a number of elements in the receiver with the same number of elements of another list.
@@ -533,22 +533,22 @@
  * @param otherFrom position of first element within other list to be copied.
  */
 public void replaceFromToWithFrom(int from, int to, AbstractLongList other, int otherFrom) {
-	int length=to-from+1;
-	if (length>0) {
-		checkRangeFromTo(from, to, size());
-		checkRangeFromTo(otherFrom,otherFrom+length-1,other.size());
-
-		// unambiguous copy (it may hold other==this)
-		if (from<=otherFrom) {
-			for (; --length >= 0; ) setQuick(from++,other.getQuick(otherFrom++));
-		}
-		else {
-			int otherTo = otherFrom+length-1;
-			for (; --length >= 0; ) setQuick(to--,other.getQuick(otherTo--));
-		}
+  int length=to-from+1;
+  if (length>0) {
+    checkRangeFromTo(from, to, size());
+    checkRangeFromTo(otherFrom,otherFrom+length-1,other.size());
+
+    // unambiguous copy (it may hold other==this)
+    if (from<=otherFrom) {
+      for (; --length >= 0; ) setQuick(from++,other.getQuick(otherFrom++));
+    }
+    else {
+      int otherTo = otherFrom+length-1;
+      for (; --length >= 0; ) setQuick(to--,other.getQuick(otherTo--));
+    }
 
-			
-	}
+      
+  }
 }
 /**
 * Replaces the part between <code>from</code> (inclusive) and <code>to</code> (inclusive) with the other list's
@@ -594,36 +594,36 @@
 * </pre>
 */
 public void replaceFromToWithFromTo(int from, int to, AbstractLongList other, int otherFrom, int otherTo) {
-	if (otherFrom>otherTo) {
-		throw new IndexOutOfBoundsException("otherFrom: "+otherFrom+", otherTo: "+otherTo);
-	}
-
-	if (this==other && to-from!=otherTo-otherFrom) { // avoid stumbling over my own feet
-		replaceFromToWithFromTo(from, to, partFromTo(otherFrom, otherTo), 0, otherTo-otherFrom);
-		return;
-	}
-	
-	int length=otherTo-otherFrom+1;
-	int diff=length;
-	int theLast=from-1;
-
-	if (to>=from) {
-		diff -= (to-from+1);
-		theLast=to;
-	}
-	
-	if (diff>0) {
-		beforeInsertDummies(theLast+1, diff);
-	}
-	else {
-		if (diff<0) {
-			removeFromTo(theLast+diff, theLast-1);
-		}
-	}
-
-	if (length>0) {
-		replaceFromToWithFrom(from,from+length-1,other,otherFrom);
-	}
+  if (otherFrom>otherTo) {
+    throw new IndexOutOfBoundsException("otherFrom: "+otherFrom+", otherTo: "+otherTo);
+  }
+
+  if (this==other && to-from!=otherTo-otherFrom) { // avoid stumbling over my own feet
+    replaceFromToWithFromTo(from, to, partFromTo(otherFrom, otherTo), 0, otherTo-otherFrom);
+    return;
+  }
+  
+  int length=otherTo-otherFrom+1;
+  int diff=length;
+  int theLast=from-1;
+
+  if (to>=from) {
+    diff -= (to-from+1);
+    theLast=to;
+  }
+  
+  if (diff>0) {
+    beforeInsertDummies(theLast+1, diff);
+  }
+  else {
+    if (diff<0) {
+      removeFromTo(theLast+diff, theLast-1);
+    }
+  }
+
+  if (length>0) {
+    replaceFromToWithFrom(from,from+length-1,other,otherFrom);
+  }
 }
 /**
  * Replaces the part of the receiver starting at <code>from</code> (inclusive) with all the elements of the specified collection.
@@ -635,12 +635,12 @@
  * @exception IndexOutOfBoundsException index is out of range (index &lt; 0 || index &gt;= size()).
  */
 public void replaceFromWith(int from, java.util.Collection other) {
-	checkRange(from,size());
-	java.util.Iterator e = other.iterator();
-	int index=from;
-	int limit = Math.min(size()-from, other.size());
-	for (int i=0; i<limit; i++)
-	    set(index++,((Number) e.next()).longValue()); //delta
+  checkRange(from,size());
+  java.util.Iterator e = other.iterator();
+  int index=from;
+  int limit = Math.min(size()-from, other.size());
+  for (int i=0; i<limit; i++)
+      set(index++,((Number) e.next()).longValue()); //delta
 }
 /**
 * Retains (keeps) only the elements in the receiver that are contained in the specified other list.
@@ -650,36 +650,36 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean retainAll(AbstractLongList other) {
-	if (other.size()==0) {
-		if (size==0) return false;
-		setSize(0);
-		return true;
-	}
-	
-	int limit = other.size()-1;
-	int j=0;
-	for (int i=0; i<size ; i++) {
-		if (other.indexOfFromTo(getQuick(i), 0, limit) >= 0) setQuick(j++, getQuick(i));
-	}
-
-	boolean modified = (j!=size);
-	setSize(j);
-	return modified;
+  if (other.size()==0) {
+    if (size==0) return false;
+    setSize(0);
+    return true;
+  }
+  
+  int limit = other.size()-1;
+  int j=0;
+  for (int i=0; i<size ; i++) {
+    if (other.indexOfFromTo(getQuick(i), 0, limit) >= 0) setQuick(j++, getQuick(i));
+  }
+
+  boolean modified = (j!=size);
+  setSize(j);
+  return modified;
 }
 /**
  * Reverses the elements of the receiver.
  * Last becomes first, second last becomes second first, and so on.
  */
 public void reverse() {
-	long tmp;
-	int limit=size()/2;
-	int j=size()-1;
-
-	for (int i=0; i<limit;) { //swap
-		tmp=getQuick(i);
-		setQuick(i++,getQuick(j));
-		setQuick(j--,tmp);
-	}
+  long tmp;
+  int limit=size()/2;
+  int j=size()-1;
+
+  for (int i=0; i<limit;) { //swap
+    tmp=getQuick(i);
+    setQuick(i++,getQuick(j));
+    setQuick(j--,tmp);
+  }
 }
 /**
  * Replaces the element at the specified position in the receiver with the specified element.
@@ -689,9 +689,9 @@
  * @throws IndexOutOfBoundsException if <tt>index &lt; 0 || index &gt;= size()</tt>.
  */
 public void set(int index, long element) {
-	if (index >= size || index < 0)
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	setQuick(index,element);
+  if (index >= size || index < 0)
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  setQuick(index,element);
 }
 /**
  * Replaces the element at the specified position in the receiver with the specified element; <b>WARNING:</b> Does not check preconditions.
@@ -722,7 +722,7 @@
  * }
  */
 protected void setSizeRaw(int newSize) {
-	size = newSize;
+  size = newSize;
 }
 /**
  * Randomly permutes the part of the receiver between <code>from</code> (inclusive) and <code>to</code> (inclusive). 
@@ -731,17 +731,17 @@
  * @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) {
-	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()));
-	for (int i=from; i<to; i++) { 
-		int random = gen.nextIntFromTo(i, to);
-
-		//swap(i, random)
-		long tmpElement = getQuick(random);
-		setQuick(random,getQuick(i)); 
-		setQuick(i,tmpElement); 
-	}  
+  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()));
+  for (int i=from; i<to; i++) { 
+    int random = gen.nextIntFromTo(i, to);
+
+    //swap(i, random)
+    long tmpElement = getQuick(random);
+    setQuick(random,getQuick(i)); 
+    setQuick(i,tmpElement); 
+  }  
 }
 /**
  * Returns the number of elements contained in the receiver.
@@ -749,33 +749,33 @@
  * @returns  the number of elements contained in the receiver.
  */
 public int size() {
-	return size;
+  return size;
 }
 /**
  * Returns a list which is a concatenation of <code>times</code> times the receiver.
  * @param times the number of times the receiver shall be copied.
  */
 public AbstractLongList times(int times) {
-	AbstractLongList newList = new LongArrayList(times*size());
-	for (int i=times; --i >= 0; ) {
-		newList.addAllOfFromTo(this,0,size()-1);
-	}
-	return newList;
+  AbstractLongList newList = new LongArrayList(times*size());
+  for (int i=times; --i >= 0; ) {
+    newList.addAllOfFromTo(this,0,size()-1);
+  }
+  return newList;
 }
 /**
  * Returns a <code>java.util.ArrayList</code> containing all the elements in the receiver.
  */
 public java.util.ArrayList toList() {
-	int mySize = size();
-	java.util.ArrayList list = new java.util.ArrayList(mySize);
-	for (int i=0; i < mySize; i++) list.add(new Long(get(i)));
-	return list;
+  int mySize = size();
+  java.util.ArrayList list = new java.util.ArrayList(mySize);
+  for (int i=0; i < mySize; i++) list.add(new Long(get(i)));
+  return list;
 }
 /**
 * Returns a string representation of the receiver, containing
 * the String representation of each element.
 */
 public String toString() {
-	return org.apache.mahout.matrix.Arrays.toString(partFromTo(0, size()-1).elements());
+  return org.apache.mahout.matrix.Arrays.toString(partFromTo(0, size()-1).elements());
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractShortList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractShortList.java?rev=883973&r1=883972&r2=883973&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractShortList.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractShortList.java Wed Nov 25 03:35:59 2009
@@ -19,13 +19,13 @@
  */
 @Deprecated
 public abstract class AbstractShortList extends AbstractList {
-	/**
-	 * The size of the list.
-	 * This is a READ_ONLY variable for all methods but setSizeRaw(int newSize) !!!
-	 * If you violate this principle in subclasses, you should exactly know what you are doing.
-	 * @serial
-	 */
-	protected int size;
+  /**
+   * The size of the list.
+   * This is a READ_ONLY variable for all methods but setSizeRaw(int newSize) !!!
+   * If you violate this principle in subclasses, you should exactly know what you are doing.
+   * @serial
+   */
+  protected int size;
 /**
  * Makes this class non instantiable, but still let's others inherit from it.
  */
@@ -36,7 +36,7 @@
  * @param element element to be appended to this list.
  */
 public void add(short element) {
-	beforeInsert(size,element);
+  beforeInsert(size,element);
 }
 /**
  * Appends the part of the specified list between <code>from</code> (inclusive) and <code>to</code> (inclusive) to the receiver.
@@ -47,7 +47,7 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>other.size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=other.size())</tt>).
  */
 public void addAllOfFromTo(AbstractShortList other, int from, int to) {
-	beforeInsertAllOfFromTo(size,other,from,to);
+  beforeInsertAllOfFromTo(size,other,from,to);
 }
 /**
  * Inserts the specified element before the specified position into the receiver. 
@@ -59,8 +59,8 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>index &lt; 0 || index &gt; size()</tt>).
  */
 public void beforeInsert(int index, short element) {
-	beforeInsertDummies(index,1);
-	set(index,element);
+  beforeInsertDummies(index,1);
+  set(index,element);
 }
 /**
  * Inserts the part of the specified list between <code>otherFrom</code> (inclusive) and <code>otherTo</code> (inclusive) before the specified position into the receiver. 
@@ -75,9 +75,9 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>index &lt; 0 || index &gt; size()</tt>).
  */
 public void beforeInsertAllOfFromTo(int index, AbstractShortList other, int from, int to) {
-	int length=to-from+1;
-	this.beforeInsertDummies(index, length);
-	this.replaceFromToWithFrom(index, index+length-1, other, from);
+  int length=to-from+1;
+  this.beforeInsertDummies(index, length);
+  this.replaceFromToWithFrom(index, index+length-1, other, from);
 }
 /**
  * Inserts <tt>length</tt> dummy elements before the specified position into the receiver. 
@@ -90,13 +90,13 @@
  * @throws IndexOutOfBoundsException if <tt>index &lt; 0 || index &gt; size()</tt>.
  */
 protected void beforeInsertDummies(int index, int length) {
-	if (index > size || index < 0) 
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	if (length > 0) {
-		ensureCapacity(size + length);
-		setSizeRaw(size + length);
-		replaceFromToWithFrom(index+length,size-1,this,index);
-	}
+  if (index > size || index < 0) 
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  if (length > 0) {
+    ensureCapacity(size + length);
+    setSizeRaw(size + length);
+    replaceFromToWithFrom(index+length,size-1,this,index);
+  }
 }
 /**
  * Searches the receiver for the specified value using
@@ -109,17 +109,17 @@
  *
  * @param key the value to be searched for.
  * @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 java.util.Arrays
  */
 public int binarySearch(short key) {
-	return this.binarySearchFromTo(key, 0, size-1);
+  return this.binarySearchFromTo(key, 0, size-1);
 }
 /**
  * Searches the receiver for the specified value using
@@ -134,27 +134,27 @@
  * @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 java.util.Arrays
  */
 public int binarySearchFromTo(short key, int from, int to) {
-	int low=from;
-	int high=to;
-	while (low <= high) {
-		int mid =(low + high)/2;
-		short midVal = get(mid);
-
-		if (midVal < key) low = mid + 1;
-		else if (midVal > key) high = mid - 1;
-		else return mid; // key found
-	}
-	return -(low + 1);  // key not found.
+  int low=from;
+  int high=to;
+  while (low <= high) {
+    int mid =(low + high)/2;
+    short midVal = get(mid);
+
+    if (midVal < key) low = mid + 1;
+    else if (midVal > key) high = mid - 1;
+    else return mid; // key found
+  }
+  return -(low + 1);  // key not found.
 }
 /**
  * Returns a deep copy of the receiver. 
@@ -162,7 +162,7 @@
  * @return  a deep copy of the receiver.
  */
 public Object clone() {
-	return partFromTo(0,size-1);
+  return partFromTo(0,size-1);
 }
 /**
  * Returns true if the receiver contains the specified element.
@@ -170,7 +170,7 @@
  * @param element element whose presence in the receiver is to be tested.
  */
 public boolean contains(short elem) {
-	return indexOfFromTo(elem,0,size-1) >=0;
+  return indexOfFromTo(elem,0,size-1) >=0;
 }
 /**
  * Deletes the first element from the receiver that is identical to the specified element.
@@ -179,8 +179,8 @@
  * @param element the element to be deleted.
  */
 public void delete(short element) {
-	int index = indexOfFromTo(element, 0, size-1);
-	if (index>=0) remove(index);
+  int index = indexOfFromTo(element, 0, size-1);
+  if (index>=0) remove(index);
 }
 /**
  * Returns the elements currently stored, possibly including invalid elements between size and capacity.
@@ -191,9 +191,9 @@
  * @return the elements currently stored.
  */
 public short[] elements() {
-	short[] myElements = new short[size];
-	for (int i=size; --i >= 0; ) myElements[i]=getQuick(i);
-	return myElements;
+  short[] myElements = new short[size];
+  for (int i=size; --i >= 0; ) myElements[i]=getQuick(i);
+  return myElements;
 }
 /**
  * Sets the receiver's elements to be the specified array.
@@ -205,9 +205,9 @@
  * @return the receiver itself.
  */
 public AbstractShortList elements(short[] elements) {
-	clear();
-	addAllOfFromTo(new ShortArrayList(elements),0,elements.length-1);
-	return this;
+  clear();
+  addAllOfFromTo(new ShortArrayList(elements),0,elements.length-1);
+  return this;
 }
 /**
  * Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory.
@@ -227,16 +227,16 @@
  * @return true if the specified Object is equal to the receiver.
  */
 public boolean equals(Object otherObj) { //delta
-	if (! (otherObj instanceof AbstractShortList)) {return false;}
-	if (this==otherObj) return true;
-	if (otherObj==null) return false;
-	AbstractShortList other = (AbstractShortList) otherObj;
-	if (size()!=other.size()) return false;
-
-	for (int i=size(); --i >= 0; ) {
-	    if (getQuick(i) != other.getQuick(i)) return false;
-	}
-	return true;
+  if (! (otherObj instanceof AbstractShortList)) {return false;}
+  if (this==otherObj) return true;
+  if (otherObj==null) return false;
+  AbstractShortList other = (AbstractShortList) otherObj;
+  if (size()!=other.size()) return false;
+
+  for (int i=size(); --i >= 0; ) {
+      if (getQuick(i) != other.getQuick(i)) return false;
+  }
+  return true;
 }
 /**
  * Sets the specified range of elements in the specified array to the specified value.
@@ -246,8 +246,8 @@
  * @param val the value to be stored in the specified elements of the receiver.
  */
 public void fillFromToWith(int from, int to, short val) {
-	checkRangeFromTo(from,to,this.size);
-	for (int i=from; i<=to;) setQuick(i++,val); 
+  checkRangeFromTo(from,to,this.size);
+  for (int i=from; i<=to;) setQuick(i++,val); 
 }
 /**
  * Applies a procedure to each element of the receiver, if any.
@@ -256,20 +256,20 @@
  * @return <tt>false</tt> if the procedure stopped before all elements where iterated over, <tt>true</tt> otherwise. 
  */
 public boolean forEach(ShortProcedure procedure) {
-	for (int i=0; i<size;) if (! procedure.apply(get(i++))) return false;
-	return true;
+  for (int i=0; i<size;) if (! procedure.apply(get(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 short get(int index) {
-	if (index >= size || index < 0)
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	return getQuick(index);
+  if (index >= size || index < 0)
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  return getQuick(index);
 }
 /**
  * Returns the element at the specified position in the receiver; <b>WARNING:</b> Does not check preconditions. 
@@ -291,7 +291,7 @@
  * @return  the index of the first occurrence of the element in the receiver; returns <code>-1</code> if the element is not found.
  */
 public int indexOf(short element) { //delta
-	return indexOfFromTo(element, 0, size-1);
+  return indexOfFromTo(element, 0, size-1);
 }
 /**
  * Returns the index of the first occurrence of the specified
@@ -306,12 +306,12 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public int indexOfFromTo(short element, int from, int to) {
-	checkRangeFromTo(from, to, size);
+  checkRangeFromTo(from, to, size);
 
-	for (int i = from ; i <= to; i++) {
-	    if (element==getQuick(i)) return i; //found
-	}
-	return -1; //not found
+  for (int i = from ; i <= to; i++) {
+      if (element==getQuick(i)) return i; //found
+  }
+  return -1; //not found
 }
 /**
  * Returns the index of the last occurrence of the specified
@@ -321,7 +321,7 @@
  * @return  the index of the last occurrence of the element in the receiver; returns <code>-1</code> if the element is not found.
  */
 public int lastIndexOf(short element) {
-	return lastIndexOfFromTo(element, 0, size-1);
+  return lastIndexOfFromTo(element, 0, size-1);
 }
 /**
  * Returns the index of the last occurrence of the specified
@@ -336,12 +336,12 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public int lastIndexOfFromTo(short element, int from, int to) {
-	checkRangeFromTo(from, to, size());
+  checkRangeFromTo(from, to, size());
 
-	for (int i = to ; i >= from; i--) {
-	    if (element==getQuick(i)) return i; //found
-	}
-	return -1; //not found
+  for (int i = to ; i >= from; i--) {
+      if (element==getQuick(i)) return i; //found
+  }
+  return -1; //not found
 }
 /**
  * Sorts the specified range of the receiver into ascending order. 
@@ -360,13 +360,13 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void mergeSortFromTo(int from, int to) {
-	int mySize = size();
-	checkRangeFromTo(from, to, mySize);
-	
-	short[] myElements = elements();
-	org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1);
-	elements(myElements);
-	setSizeRaw(mySize);
+  int mySize = size();
+  checkRangeFromTo(from, to, mySize);
+  
+  short[] myElements = elements();
+  org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1);
+  elements(myElements);
+  setSizeRaw(mySize);
 }
 /**
  * Sorts the receiver according
@@ -390,21 +390,21 @@
  * @param to the index of the last element (inclusive) to be sorted.
  * @param c the comparator to determine the order of the receiver.
  * @throws ClassCastException if the array contains elements that are not
- *	       <i>mutually comparable</i> using the specified comparator.
+ *         <i>mutually comparable</i> using the specified comparator.
  * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
  * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
- *	       <tt>toIndex &gt; a.length</tt>
+ *         <tt>toIndex &gt; a.length</tt>
  * @see Comparator
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void mergeSortFromTo(int from, int to, ShortComparator c) {
-	int mySize = size();
-	checkRangeFromTo(from, to, mySize);
-	
-	short[] myElements = elements();
-	org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1, c);
-	elements(myElements);
-	setSizeRaw(mySize);
+  int mySize = size();
+  checkRangeFromTo(from, to, mySize);
+  
+  short[] myElements = elements();
+  org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1, c);
+  elements(myElements);
+  setSizeRaw(mySize);
 }
 /**
  * Returns a new list of the part of the receiver between <code>from</code>, inclusive, and <code>to</code>, inclusive.
@@ -414,12 +414,12 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public AbstractShortList partFromTo(int from, int to) {
-	checkRangeFromTo(from, to, size);
+  checkRangeFromTo(from, to, size);
 
-	int length = to-from+1;
-	ShortArrayList part = new ShortArrayList(length);
-	part.addAllOfFromTo(this,from,to);
-	return part;
+  int length = to-from+1;
+  ShortArrayList part = new ShortArrayList(length);
+  part.addAllOfFromTo(this,from,to);
+  return part;
 }
 /**
  * Sorts the specified range of the receiver into
@@ -438,13 +438,13 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void quickSortFromTo(int from, int to) {
-	int mySize = size();
-	checkRangeFromTo(from, to, mySize);
-	
-	short[] myElements = elements();
-	java.util.Arrays.sort(myElements, from, to+1);
-	elements(myElements);
-	setSizeRaw(mySize);
+  int mySize = size();
+  checkRangeFromTo(from, to, mySize);
+  
+  short[] myElements = elements();
+  java.util.Arrays.sort(myElements, from, to+1);
+  elements(myElements);
+  setSizeRaw(mySize);
 }
 /**
  * Sorts the receiver according
@@ -466,21 +466,21 @@
  * @param to the index of the last element (inclusive) to be sorted.
  * @param c the comparator to determine the order of the receiver.
  * @throws ClassCastException if the array contains elements that are not
- *	       <i>mutually comparable</i> using the specified comparator.
+ *         <i>mutually comparable</i> using the specified comparator.
  * @throws IllegalArgumentException if <tt>fromIndex &gt; toIndex</tt>
  * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex &lt; 0</tt> or
- *	       <tt>toIndex &gt; a.length</tt>
+ *         <tt>toIndex &gt; a.length</tt>
  * @see Comparator
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void quickSortFromTo(int from, int to, ShortComparator c) {
-	int mySize = size();
-	checkRangeFromTo(from, to, mySize);
-	
-	short[] myElements = elements();
-	org.apache.mahout.matrix.Sorting.quickSort(myElements, from, to+1,c);
-	elements(myElements);
-	setSizeRaw(mySize);
+  int mySize = size();
+  checkRangeFromTo(from, to, mySize);
+  
+  short[] myElements = elements();
+  org.apache.mahout.matrix.Sorting.quickSort(myElements, from, to+1,c);
+  elements(myElements);
+  setSizeRaw(mySize);
 }
 /**
 * Removes from the receiver all elements that are contained in the specified list.
@@ -490,17 +490,17 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean removeAll(AbstractShortList other) {
-	if (other.size()==0) return false; //nothing to do
-	int limit = other.size()-1;
-	int j=0;
-
-	for (int i=0; i<size ; i++) {
-		if (other.indexOfFromTo(getQuick(i), 0, limit) < 0) setQuick(j++,getQuick(i));
-	}
-
-	boolean modified = (j!=size);
-	setSize(j);
-	return modified;
+  if (other.size()==0) return false; //nothing to do
+  int limit = other.size()-1;
+  int j=0;
+
+  for (int i=0; i<size ; i++) {
+    if (other.indexOfFromTo(getQuick(i), 0, limit) < 0) setQuick(j++,getQuick(i));
+  }
+
+  boolean modified = (j!=size);
+  setSize(j);
+  return modified;
 }
 /**
  * Removes from the receiver all elements whose index is between
@@ -513,14 +513,14 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void removeFromTo(int from, int to) {
-	checkRangeFromTo(from, to, size);
-	int numMoved = size - to - 1;
-	if (numMoved > 0) {
-		replaceFromToWithFrom(from, from-1+numMoved, this, to+1);
-		//fillFromToWith(from+numMoved, size-1, 0.0f); //delta
-	}
-	int width = to-from+1;
-	if (width>0) setSizeRaw(size-width);
+  checkRangeFromTo(from, to, size);
+  int numMoved = size - to - 1;
+  if (numMoved > 0) {
+    replaceFromToWithFrom(from, from-1+numMoved, this, to+1);
+    //fillFromToWith(from+numMoved, size-1, 0.0f); //delta
+  }
+  int width = to-from+1;
+  if (width>0) setSizeRaw(size-width);
 }
 /**
  * Replaces a number of elements in the receiver with the same number of elements of another list.
@@ -533,22 +533,22 @@
  * @param otherFrom position of first element within other list to be copied.
  */
 public void replaceFromToWithFrom(int from, int to, AbstractShortList other, int otherFrom) {
-	int length=to-from+1;
-	if (length>0) {
-		checkRangeFromTo(from, to, size());
-		checkRangeFromTo(otherFrom,otherFrom+length-1,other.size());
-
-		// unambiguous copy (it may hold other==this)
-		if (from<=otherFrom) {
-			for (; --length >= 0; ) setQuick(from++,other.getQuick(otherFrom++));
-		}
-		else {
-			int otherTo = otherFrom+length-1;
-			for (; --length >= 0; ) setQuick(to--,other.getQuick(otherTo--));
-		}
+  int length=to-from+1;
+  if (length>0) {
+    checkRangeFromTo(from, to, size());
+    checkRangeFromTo(otherFrom,otherFrom+length-1,other.size());
+
+    // unambiguous copy (it may hold other==this)
+    if (from<=otherFrom) {
+      for (; --length >= 0; ) setQuick(from++,other.getQuick(otherFrom++));
+    }
+    else {
+      int otherTo = otherFrom+length-1;
+      for (; --length >= 0; ) setQuick(to--,other.getQuick(otherTo--));
+    }
 
-			
-	}
+      
+  }
 }
 /**
 * Replaces the part between <code>from</code> (inclusive) and <code>to</code> (inclusive) with the other list's
@@ -594,36 +594,36 @@
 * </pre>
 */
 public void replaceFromToWithFromTo(int from, int to, AbstractShortList other, int otherFrom, int otherTo) {
-	if (otherFrom>otherTo) {
-		throw new IndexOutOfBoundsException("otherFrom: "+otherFrom+", otherTo: "+otherTo);
-	}
-
-	if (this==other && to-from!=otherTo-otherFrom) { // avoid stumbling over my own feet
-		replaceFromToWithFromTo(from, to, partFromTo(otherFrom, otherTo), 0, otherTo-otherFrom);
-		return;
-	}
-	
-	int length=otherTo-otherFrom+1;
-	int diff=length;
-	int theLast=from-1;
-
-	if (to>=from) {
-		diff -= (to-from+1);
-		theLast=to;
-	}
-	
-	if (diff>0) {
-		beforeInsertDummies(theLast+1, diff);
-	}
-	else {
-		if (diff<0) {
-			removeFromTo(theLast+diff, theLast-1);
-		}
-	}
-
-	if (length>0) {
-		replaceFromToWithFrom(from,from+length-1,other,otherFrom);
-	}
+  if (otherFrom>otherTo) {
+    throw new IndexOutOfBoundsException("otherFrom: "+otherFrom+", otherTo: "+otherTo);
+  }
+
+  if (this==other && to-from!=otherTo-otherFrom) { // avoid stumbling over my own feet
+    replaceFromToWithFromTo(from, to, partFromTo(otherFrom, otherTo), 0, otherTo-otherFrom);
+    return;
+  }
+  
+  int length=otherTo-otherFrom+1;
+  int diff=length;
+  int theLast=from-1;
+
+  if (to>=from) {
+    diff -= (to-from+1);
+    theLast=to;
+  }
+  
+  if (diff>0) {
+    beforeInsertDummies(theLast+1, diff);
+  }
+  else {
+    if (diff<0) {
+      removeFromTo(theLast+diff, theLast-1);
+    }
+  }
+
+  if (length>0) {
+    replaceFromToWithFrom(from,from+length-1,other,otherFrom);
+  }
 }
 /**
  * Replaces the part of the receiver starting at <code>from</code> (inclusive) with all the elements of the specified collection.
@@ -635,12 +635,12 @@
  * @exception IndexOutOfBoundsException index is out of range (index &lt; 0 || index &gt;= size()).
  */
 public void replaceFromWith(int from, java.util.Collection other) {
-	checkRange(from,size());
-	java.util.Iterator e = other.iterator();
-	int index=from;
-	int limit = Math.min(size()-from, other.size());
-	for (int i=0; i<limit; i++)
-	    set(index++,((Number) e.next()).shortValue()); //delta
+  checkRange(from,size());
+  java.util.Iterator e = other.iterator();
+  int index=from;
+  int limit = Math.min(size()-from, other.size());
+  for (int i=0; i<limit; i++)
+      set(index++,((Number) e.next()).shortValue()); //delta
 }
 /**
 * Retains (keeps) only the elements in the receiver that are contained in the specified other list.
@@ -650,36 +650,36 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean retainAll(AbstractShortList other) {
-	if (other.size()==0) {
-		if (size==0) return false;
-		setSize(0);
-		return true;
-	}
-	
-	int limit = other.size()-1;
-	int j=0;
-	for (int i=0; i<size ; i++) {
-		if (other.indexOfFromTo(getQuick(i), 0, limit) >= 0) setQuick(j++, getQuick(i));
-	}
-
-	boolean modified = (j!=size);
-	setSize(j);
-	return modified;
+  if (other.size()==0) {
+    if (size==0) return false;
+    setSize(0);
+    return true;
+  }
+  
+  int limit = other.size()-1;
+  int j=0;
+  for (int i=0; i<size ; i++) {
+    if (other.indexOfFromTo(getQuick(i), 0, limit) >= 0) setQuick(j++, getQuick(i));
+  }
+
+  boolean modified = (j!=size);
+  setSize(j);
+  return modified;
 }
 /**
  * Reverses the elements of the receiver.
  * Last becomes first, second last becomes second first, and so on.
  */
 public void reverse() {
-	short tmp;
-	int limit=size()/2;
-	int j=size()-1;
-
-	for (int i=0; i<limit;) { //swap
-		tmp=getQuick(i);
-		setQuick(i++,getQuick(j));
-		setQuick(j--,tmp);
-	}
+  short tmp;
+  int limit=size()/2;
+  int j=size()-1;
+
+  for (int i=0; i<limit;) { //swap
+    tmp=getQuick(i);
+    setQuick(i++,getQuick(j));
+    setQuick(j--,tmp);
+  }
 }
 /**
  * Replaces the element at the specified position in the receiver with the specified element.
@@ -689,9 +689,9 @@
  * @throws IndexOutOfBoundsException if <tt>index &lt; 0 || index &gt;= size()</tt>.
  */
 public void set(int index, short element) {
-	if (index >= size || index < 0)
-		throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
-	setQuick(index,element);
+  if (index >= size || index < 0)
+    throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
+  setQuick(index,element);
 }
 /**
  * Replaces the element at the specified position in the receiver with the specified element; <b>WARNING:</b> Does not check preconditions.
@@ -722,7 +722,7 @@
  * }
  */
 protected void setSizeRaw(int newSize) {
-	size = newSize;
+  size = newSize;
 }
 /**
  * Randomly permutes the part of the receiver between <code>from</code> (inclusive) and <code>to</code> (inclusive). 
@@ -731,17 +731,17 @@
  * @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) {
-	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()));
-	for (int i=from; i<to; i++) { 
-		int random = gen.nextIntFromTo(i, to);
-
-		//swap(i, random)
-		short tmpElement = getQuick(random);
-		setQuick(random,getQuick(i)); 
-		setQuick(i,tmpElement); 
-	}  
+  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()));
+  for (int i=from; i<to; i++) { 
+    int random = gen.nextIntFromTo(i, to);
+
+    //swap(i, random)
+    short tmpElement = getQuick(random);
+    setQuick(random,getQuick(i)); 
+    setQuick(i,tmpElement); 
+  }  
 }
 /**
  * Returns the number of elements contained in the receiver.
@@ -749,33 +749,33 @@
  * @returns  the number of elements contained in the receiver.
  */
 public int size() {
-	return size;
+  return size;
 }
 /**
  * Returns a list which is a concatenation of <code>times</code> times the receiver.
  * @param times the number of times the receiver shall be copied.
  */
 public AbstractShortList times(int times) {
-	AbstractShortList newList = new ShortArrayList(times*size());
-	for (int i=times; --i >= 0; ) {
-		newList.addAllOfFromTo(this,0,size()-1);
-	}
-	return newList;
+  AbstractShortList newList = new ShortArrayList(times*size());
+  for (int i=times; --i >= 0; ) {
+    newList.addAllOfFromTo(this,0,size()-1);
+  }
+  return newList;
 }
 /**
  * Returns a <code>java.util.ArrayList</code> containing all the elements in the receiver.
  */
 public java.util.ArrayList toList() {
-	int mySize = size();
-	java.util.ArrayList list = new java.util.ArrayList(mySize);
-	for (int i=0; i < mySize; i++) list.add(new Short(get(i)));
-	return list;
+  int mySize = size();
+  java.util.ArrayList list = new java.util.ArrayList(mySize);
+  for (int i=0; i < mySize; i++) list.add(new Short(get(i)));
+  return list;
 }
 /**
 * Returns a string representation of the receiver, containing
 * the String representation of each element.
 */
 public String toString() {
-	return org.apache.mahout.matrix.Arrays.toString(partFromTo(0, size()-1).elements());
+  return org.apache.mahout.matrix.Arrays.toString(partFromTo(0, size()-1).elements());
 }
 }

Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/BooleanArrayList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/BooleanArrayList.java?rev=883973&r1=883972&r2=883973&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/BooleanArrayList.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/BooleanArrayList.java Wed Nov 25 03:35:59 2009
@@ -18,17 +18,17 @@
  */
 @Deprecated
 public class BooleanArrayList extends AbstractBooleanList {
-	/**
-	 * 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 boolean[] 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 boolean[] elements;
 /**
  * Constructs an empty list.
  */
 public BooleanArrayList() {
-	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 BooleanArrayList(boolean[] 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 BooleanArrayList(int initialCapacity) {
-	this(new boolean[initialCapacity]);
-	setSizeRaw(0);
+  this(new boolean[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(boolean 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,13 +73,13 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>index &lt; 0 || index &gt; size()</tt>).
  */
 public void beforeInsert(int index, boolean 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++;
 }
 /**
  * Returns a deep copy of the receiver. 
@@ -87,10 +87,10 @@
  * @return  a deep copy of the receiver.
  */
 public Object clone() {
-	// overridden for performance only.
-	BooleanArrayList clone = new BooleanArrayList((boolean[]) elements.clone());
-	clone.setSizeRaw(size);
-	return clone;
+  // overridden for performance only.
+  BooleanArrayList clone = new BooleanArrayList((boolean[]) elements.clone());
+  clone.setSizeRaw(size);
+  return clone;
 }
 /**
  * Returns a deep copy of the receiver; uses <code>clone()</code> and casts the result.
@@ -98,7 +98,7 @@
  * @return  a deep copy of the receiver.
  */
 public BooleanArrayList copy() {
-	return (BooleanArrayList) clone();
+  return (BooleanArrayList) clone();
 }
 /**
  * Sorts the specified range of the receiver into ascending numerical order (<tt>false &lt; true</tt>). 
@@ -110,16 +110,16 @@
  * @param to the index of the last element (inclusive) to be sorted.
  */
 public void countSortFromTo(int from, int to) {
-	if (size==0) return;
-	checkRangeFromTo(from, to, size);
-	
-	boolean[] theElements = elements;
-	int trues = 0;
-	for (int i=from; i<=to;) if (theElements[i++]) trues++;
-
-	int falses = to-from+1-trues;
-	if (falses>0) fillFromToWith(from,from+falses-1,false);
-	if (trues>0) fillFromToWith(from+falses,from+falses-1+trues,true);
+  if (size==0) return;
+  checkRangeFromTo(from, to, size);
+  
+  boolean[] theElements = elements;
+  int trues = 0;
+  for (int i=from; i<=to;) if (theElements[i++]) trues++;
+
+  int falses = to-from+1-trues;
+  if (falses>0) fillFromToWith(from,from+falses-1,false);
+  if (trues>0) fillFromToWith(from+falses,from+falses-1+trues,true);
 }
 /**
  * Returns the elements currently stored, including invalid elements between size and capacity, if any.
@@ -130,7 +130,7 @@
  * @return the elements currently stored.
  */
 public boolean[] elements() {
-	return elements;
+  return elements;
 }
 /**
  * Sets the receiver's elements to be the specified array (not a copy of it).
@@ -143,9 +143,9 @@
  * @return the receiver itself.
  */
 public AbstractBooleanList elements(boolean[] 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.
@@ -154,7 +154,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.  
@@ -167,19 +167,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 BooleanArrayList)) return super.equals(otherObj);
-	if (this==otherObj) return true;
-	if (otherObj==null) return false;
-	BooleanArrayList other = (BooleanArrayList) otherObj;
-	if (size()!=other.size()) return false;
-
-	boolean[] theElements = elements();
-	boolean[] 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 BooleanArrayList)) return super.equals(otherObj);
+  if (this==otherObj) return true;
+  if (otherObj==null) return false;
+  BooleanArrayList other = (BooleanArrayList) otherObj;
+  if (size()!=other.size()) return false;
+
+  boolean[] theElements = elements();
+  boolean[] 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.
@@ -188,25 +188,25 @@
  * @return <tt>false</tt> if the procedure stopped before all elements where iterated over, <tt>true</tt> otherwise. 
  */
 public boolean forEach(BooleanProcedure procedure) {
-	// overridden for performance only.
-	boolean[] theElements = elements;
-	int theSize = size;
-	
-	for (int i=0; i<theSize;) if (! procedure.apply(theElements[i++])) return false;
-	return true;
+  // overridden for performance only.
+  boolean[] 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 boolean 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. 
@@ -217,7 +217,7 @@
  * @param index index of element to return.
  */
 public boolean getQuick(int index) {
-	return elements[index];
+  return elements[index];
 }
 /**
  * Returns the index of the first occurrence of the specified
@@ -232,15 +232,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(boolean element, int from, int to) {
-	// overridden for performance only.
-	if (size==0) return -1;
-	checkRangeFromTo(from, to, size);
-
-	boolean[] 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);
+
+  boolean[] 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
@@ -255,15 +255,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(boolean element, int from, int to) {
-	// overridden for performance only.
-	if (size==0) return -1;
-	checkRangeFromTo(from, to, size);
-
-	boolean[] 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);
+
+  boolean[] theElements = elements;
+  for (int i = to ; i >= from; i--) {
+      if (element==theElements[i]) {return i;} //found
+  }
+  return -1; //not found
 }
 /**
  * Sorts the specified range of the receiver into ascending order (<tt>false &lt; true</tt>). 
@@ -276,7 +276,7 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void mergeSortFromTo(int from, int to) {
-	countSortFromTo(from, to);
+  countSortFromTo(from, to);
 }
 /**
  * Returns a new list of the part of the receiver between <code>from</code>, inclusive, and <code>to</code>, inclusive.
@@ -286,13 +286,13 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public AbstractBooleanList partFromTo(int from, int to) {
-	if (size==0) return new BooleanArrayList(0);
+  if (size==0) return new BooleanArrayList(0);
 
-	checkRangeFromTo(from, to, size);
+  checkRangeFromTo(from, to, size);
 
-	boolean[] part = new boolean[to-from+1];
-	System.arraycopy(elements, from, part, 0, to-from+1);
-	return new BooleanArrayList(part);
+  boolean[] part = new boolean[to-from+1];
+  System.arraycopy(elements, from, part, 0, to-from+1);
+  return new BooleanArrayList(part);
 }
 /**
  * Sorts the specified range of the receiver into ascending order (<tt>false &lt; true</tt>). 
@@ -305,7 +305,7 @@
  * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 || from&gt;to || to&gt;=size())</tt>).
  */
 public void quickSortFromTo(int from, int to) {
-	countSortFromTo(from, to);
+  countSortFromTo(from, to);
 }
 /**
 * Removes from the receiver all elements that are contained in the specified list.
@@ -315,46 +315,46 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean removeAll(AbstractBooleanList other) {
-	// overridden for performance only.
-	if (! (other instanceof BooleanArrayList))	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 BooleanArrayList))  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;
-	boolean[] 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
-		BooleanArrayList sortedList = (BooleanArrayList) 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;
+  boolean[] 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
+    BooleanArrayList sortedList = (BooleanArrayList) 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.
@@ -367,18 +367,18 @@
  * @param otherFrom position of first element within other list to be copied.
  */
 public void replaceFromToWithFrom(int from, int to, AbstractBooleanList other, int otherFrom) {
-	// overridden for performance only.
-	if (! (other instanceof BooleanArrayList)) {
-		// 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(((BooleanArrayList) other).elements, otherFrom, elements, from, length);
-	}
+  // overridden for performance only.
+  if (! (other instanceof BooleanArrayList)) {
+    // 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(((BooleanArrayList) other).elements, otherFrom, elements, from, length);
+  }
 }
 /**
 * Retains (keeps) only the elements in the receiver that are contained in the specified other list.
@@ -388,62 +388,62 @@
 * @return <code>true</code> if the receiver changed as a result of the call.
 */
 public boolean retainAll(AbstractBooleanList other) {
-	// overridden for performance only.
-	if (! (other instanceof BooleanArrayList))	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;
-	boolean[] 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
-		BooleanArrayList sortedList = (BooleanArrayList) 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 BooleanArrayList))  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;
+  boolean[] 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
+    BooleanArrayList sortedList = (BooleanArrayList) 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.
-	boolean tmp;
-	int limit=size/2;
-	int j=size-1;
-
-	boolean[] theElements = elements;
-	for (int i=0; i<limit;) { //swap
-		tmp=theElements[i];
-		theElements[i++]=theElements[j];
-		theElements[j--]=tmp;
-	}
+  // overridden for performance only.
+  boolean tmp;
+  int limit=size/2;
+  int j=size-1;
+
+  boolean[] 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.
@@ -451,13 +451,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, boolean 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.
@@ -469,7 +469,7 @@
  * @param element element to be stored at the specified position.
  */
 public void setQuick(int index, boolean element) {
-	elements[index] = element;
+  elements[index] = element;
 }
 /**
  * Randomly permutes the part of the receiver between <code>from</code> (inclusive) and <code>to</code> (inclusive). 
@@ -478,22 +478,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()));
-	boolean tmpElement;
-	boolean[] 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()));
+  boolean tmpElement;
+  boolean[] 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. 
@@ -505,7 +505,7 @@
  * @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) {
-	countSortFromTo(from, to);
+  countSortFromTo(from, to);
 }
 /**
  * Trims the capacity of the receiver to be the receiver's current 
@@ -513,6 +513,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());
 }
 }



Mime
View raw message