You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2009/11/25 04:36:02 UTC
svn commit: r883973 [7/14] - in
/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix: ./
bitvector/ buffer/ function/ list/ list/adapter/ map/
Modified: lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractFloatList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractFloatList.java?rev=883973&r1=883972&r2=883973&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractFloatList.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractFloatList.java Wed Nov 25 03:35:59 2009
@@ -19,13 +19,13 @@
*/
@Deprecated
public abstract class AbstractFloatList 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(float 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()>0 && (from<0 || from>to || to>=other.size())</tt>).
*/
public void addAllOfFromTo(AbstractFloatList 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 < 0 || index > size()</tt>).
*/
public void beforeInsert(int index, float 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 < 0 || index > size()</tt>).
*/
public void beforeInsertAllOfFromTo(int index, AbstractFloatList 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 < 0 || index > 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 >= 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 >= 0 if
+ * and only if the key is found.
* @see java.util.Arrays
*/
public int binarySearch(float 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 >= 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 >= 0 if
+ * and only if the key is found.
* @see java.util.Arrays
*/
public int binarySearchFromTo(float key, int from, int to) {
- int low=from;
- int high=to;
- while (low <= high) {
- int mid =(low + high)/2;
- float 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;
+ float 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(float 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(float 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 float[] elements() {
- float[] myElements = new float[size];
- for (int i=size; --i >= 0; ) myElements[i]=getQuick(i);
- return myElements;
+ float[] myElements = new float[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 AbstractFloatList elements(float[] elements) {
- clear();
- addAllOfFromTo(new FloatArrayList(elements),0,elements.length-1);
- return this;
+ clear();
+ addAllOfFromTo(new FloatArrayList(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 AbstractFloatList)) {return false;}
- if (this==otherObj) return true;
- if (otherObj==null) return false;
- AbstractFloatList other = (AbstractFloatList) 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 AbstractFloatList)) {return false;}
+ if (this==otherObj) return true;
+ if (otherObj==null) return false;
+ AbstractFloatList other = (AbstractFloatList) 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, float 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(FloatProcedure 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
- * < 0 || index >= size()).
+ * < 0 || index >= size()).
*/
public float 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(float 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()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public int indexOfFromTo(float 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(float 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()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public int lastIndexOfFromTo(float 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()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public void mergeSortFromTo(int from, int to) {
- int mySize = size();
- checkRangeFromTo(from, to, mySize);
-
- float[] myElements = elements();
- org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1);
- elements(myElements);
- setSizeRaw(mySize);
+ int mySize = size();
+ checkRangeFromTo(from, to, mySize);
+
+ float[] 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 > toIndex</tt>
* @throws ArrayIndexOutOfBoundsException if <tt>fromIndex < 0</tt> or
- * <tt>toIndex > a.length</tt>
+ * <tt>toIndex > a.length</tt>
* @see Comparator
* @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public void mergeSortFromTo(int from, int to, FloatComparator c) {
- int mySize = size();
- checkRangeFromTo(from, to, mySize);
-
- float[] myElements = elements();
- org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1, c);
- elements(myElements);
- setSizeRaw(mySize);
+ int mySize = size();
+ checkRangeFromTo(from, to, mySize);
+
+ float[] 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()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public AbstractFloatList partFromTo(int from, int to) {
- checkRangeFromTo(from, to, size);
+ checkRangeFromTo(from, to, size);
- int length = to-from+1;
- FloatArrayList part = new FloatArrayList(length);
- part.addAllOfFromTo(this,from,to);
- return part;
+ int length = to-from+1;
+ FloatArrayList part = new FloatArrayList(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()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public void quickSortFromTo(int from, int to) {
- int mySize = size();
- checkRangeFromTo(from, to, mySize);
-
- float[] myElements = elements();
- java.util.Arrays.sort(myElements, from, to+1);
- elements(myElements);
- setSizeRaw(mySize);
+ int mySize = size();
+ checkRangeFromTo(from, to, mySize);
+
+ float[] 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 > toIndex</tt>
* @throws ArrayIndexOutOfBoundsException if <tt>fromIndex < 0</tt> or
- * <tt>toIndex > a.length</tt>
+ * <tt>toIndex > a.length</tt>
* @see Comparator
* @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public void quickSortFromTo(int from, int to, FloatComparator c) {
- int mySize = size();
- checkRangeFromTo(from, to, mySize);
-
- float[] myElements = elements();
- org.apache.mahout.matrix.Sorting.quickSort(myElements, from, to+1,c);
- elements(myElements);
- setSizeRaw(mySize);
+ int mySize = size();
+ checkRangeFromTo(from, to, mySize);
+
+ float[] 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(AbstractFloatList 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()>0 && (from<0 || from>to || to>=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, AbstractFloatList 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, AbstractFloatList 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 < 0 || index >= 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()).floatValue()); //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()).floatValue()); //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(AbstractFloatList 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() {
- float 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);
- }
+ float 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 < 0 || index >= size()</tt>.
*/
public void set(int index, float 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()>0 && (from<0 || from>to || to>=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)
- float 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)
+ float 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 AbstractFloatList times(int times) {
- AbstractFloatList newList = new FloatArrayList(times*size());
- for (int i=times; --i >= 0; ) {
- newList.addAllOfFromTo(this,0,size()-1);
- }
- return newList;
+ AbstractFloatList newList = new FloatArrayList(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 Float(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 Float(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/AbstractIntList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractIntList.java?rev=883973&r1=883972&r2=883973&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractIntList.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractIntList.java Wed Nov 25 03:35:59 2009
@@ -19,13 +19,13 @@
*/
@Deprecated
public abstract class AbstractIntList extends AbstractList implements org.apache.mahout.matrix.buffer.IntBufferConsumer {
- /**
- * 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,14 +36,14 @@
* @param element element to be appended to this list.
*/
public void add(int element) {
- beforeInsert(size,element);
+ beforeInsert(size,element);
}
/**
* Appends all elements of the specified list to the receiver.
* @param list the list of which all elements shall be appended.
*/
public void addAllOf(IntArrayList other) {
- addAllOfFromTo(other,0,other.size()-1);
+ addAllOfFromTo(other,0,other.size()-1);
}
/**
* Appends the part of the specified list between <code>from</code> (inclusive) and <code>to</code> (inclusive) to the receiver.
@@ -54,7 +54,7 @@
* @exception IndexOutOfBoundsException index is out of range (<tt>other.size()>0 && (from<0 || from>to || to>=other.size())</tt>).
*/
public void addAllOfFromTo(AbstractIntList 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.
@@ -66,8 +66,8 @@
* @exception IndexOutOfBoundsException index is out of range (<tt>index < 0 || index > size()</tt>).
*/
public void beforeInsert(int index, int 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.
@@ -82,9 +82,9 @@
* @exception IndexOutOfBoundsException index is out of range (<tt>index < 0 || index > size()</tt>).
*/
public void beforeInsertAllOfFromTo(int index, AbstractIntList 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.
@@ -97,13 +97,13 @@
* @throws IndexOutOfBoundsException if <tt>index < 0 || index > 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
@@ -116,17 +116,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 >= 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 >= 0 if
+ * and only if the key is found.
* @see java.util.Arrays
*/
public int binarySearch(int key) {
- return this.binarySearchFromTo(key, 0, size-1);
+ return this.binarySearchFromTo(key, 0, size-1);
}
/**
* Searches the receiver for the specified value using
@@ -141,27 +141,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 >= 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 >= 0 if
+ * and only if the key is found.
* @see java.util.Arrays
*/
public int binarySearchFromTo(int key, int from, int to) {
- int low=from;
- int high=to;
- while (low <= high) {
- int mid =(low + high)/2;
- int 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;
+ int 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.
@@ -169,7 +169,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.
@@ -177,7 +177,7 @@
* @param element element whose presence in the receiver is to be tested.
*/
public boolean contains(int 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.
@@ -186,8 +186,8 @@
* @param element the element to be deleted.
*/
public void delete(int 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.
@@ -198,9 +198,9 @@
* @return the elements currently stored.
*/
public int[] elements() {
- int[] myElements = new int[size];
- for (int i=size; --i >= 0; ) myElements[i]=getQuick(i);
- return myElements;
+ int[] myElements = new int[size];
+ for (int i=size; --i >= 0; ) myElements[i]=getQuick(i);
+ return myElements;
}
/**
* Sets the receiver's elements to be the specified array.
@@ -212,9 +212,9 @@
* @return the receiver itself.
*/
public AbstractIntList elements(int[] elements) {
- clear();
- addAllOfFromTo(new IntArrayList(elements),0,elements.length-1);
- return this;
+ clear();
+ addAllOfFromTo(new IntArrayList(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.
@@ -234,16 +234,16 @@
* @return true if the specified Object is equal to the receiver.
*/
public boolean equals(Object otherObj) { //delta
- if (! (otherObj instanceof AbstractIntList)) {return false;}
- if (this==otherObj) return true;
- if (otherObj==null) return false;
- AbstractIntList other = (AbstractIntList) 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 AbstractIntList)) {return false;}
+ if (this==otherObj) return true;
+ if (otherObj==null) return false;
+ AbstractIntList other = (AbstractIntList) 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.
@@ -253,8 +253,8 @@
* @param val the value to be stored in the specified elements of the receiver.
*/
public void fillFromToWith(int from, int to, int 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.
@@ -263,20 +263,20 @@
* @return <tt>false</tt> if the procedure stopped before all elements where iterated over, <tt>true</tt> otherwise.
*/
public boolean forEach(IntProcedure 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
- * < 0 || index >= size()).
+ * < 0 || index >= size()).
*/
public int 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.
@@ -298,7 +298,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(int element) { //delta
- return indexOfFromTo(element, 0, size-1);
+ return indexOfFromTo(element, 0, size-1);
}
/**
* Returns the index of the first occurrence of the specified
@@ -313,12 +313,12 @@
* @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public int indexOfFromTo(int 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
@@ -328,7 +328,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(int element) {
- return lastIndexOfFromTo(element, 0, size-1);
+ return lastIndexOfFromTo(element, 0, size-1);
}
/**
* Returns the index of the last occurrence of the specified
@@ -343,12 +343,12 @@
* @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public int lastIndexOfFromTo(int 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.
@@ -367,13 +367,13 @@
* @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public void mergeSortFromTo(int from, int to) {
- int mySize = size();
- checkRangeFromTo(from, to, mySize);
-
- int[] myElements = elements();
- org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1);
- elements(myElements);
- setSizeRaw(mySize);
+ int mySize = size();
+ checkRangeFromTo(from, to, mySize);
+
+ int[] myElements = elements();
+ org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1);
+ elements(myElements);
+ setSizeRaw(mySize);
}
/**
* Sorts the receiver according
@@ -397,21 +397,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 > toIndex</tt>
* @throws ArrayIndexOutOfBoundsException if <tt>fromIndex < 0</tt> or
- * <tt>toIndex > a.length</tt>
+ * <tt>toIndex > a.length</tt>
* @see Comparator
* @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public void mergeSortFromTo(int from, int to, IntComparator c) {
- int mySize = size();
- checkRangeFromTo(from, to, mySize);
-
- int[] myElements = elements();
- org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1, c);
- elements(myElements);
- setSizeRaw(mySize);
+ int mySize = size();
+ checkRangeFromTo(from, to, mySize);
+
+ int[] 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.
@@ -421,12 +421,12 @@
* @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public AbstractIntList partFromTo(int from, int to) {
- checkRangeFromTo(from, to, size);
+ checkRangeFromTo(from, to, size);
- int length = to-from+1;
- IntArrayList part = new IntArrayList(length);
- part.addAllOfFromTo(this,from,to);
- return part;
+ int length = to-from+1;
+ IntArrayList part = new IntArrayList(length);
+ part.addAllOfFromTo(this,from,to);
+ return part;
}
/**
* Sorts the specified range of the receiver into
@@ -445,14 +445,14 @@
* @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public void quickSortFromTo(int from, int to) {
- int mySize = size();
- checkRangeFromTo(from, to, mySize);
-
- int[] myElements = elements();
- java.util.Arrays.sort(myElements, from, to+1);
- //org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1); // TODO just for debugging
- elements(myElements);
- setSizeRaw(mySize);
+ int mySize = size();
+ checkRangeFromTo(from, to, mySize);
+
+ int[] myElements = elements();
+ java.util.Arrays.sort(myElements, from, to+1);
+ //org.apache.mahout.matrix.Sorting.mergeSort(myElements, from, to+1); // TODO just for debugging
+ elements(myElements);
+ setSizeRaw(mySize);
}
/**
* Sorts the receiver according
@@ -474,21 +474,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 > toIndex</tt>
* @throws ArrayIndexOutOfBoundsException if <tt>fromIndex < 0</tt> or
- * <tt>toIndex > a.length</tt>
+ * <tt>toIndex > a.length</tt>
* @see Comparator
* @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=size())</tt>).
*/
public void quickSortFromTo(int from, int to, IntComparator c) {
- int mySize = size();
- checkRangeFromTo(from, to, mySize);
-
- int[] myElements = elements();
- org.apache.mahout.matrix.Sorting.quickSort(myElements, from, to+1,c);
- elements(myElements);
- setSizeRaw(mySize);
+ int mySize = size();
+ checkRangeFromTo(from, to, mySize);
+
+ int[] 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.
@@ -498,17 +498,17 @@
* @return <code>true</code> if the receiver changed as a result of the call.
*/
public boolean removeAll(AbstractIntList 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
@@ -521,14 +521,14 @@
* @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=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.
@@ -541,22 +541,22 @@
* @param otherFrom position of first element within other list to be copied.
*/
public void replaceFromToWithFrom(int from, int to, AbstractIntList 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
@@ -602,36 +602,36 @@
* </pre>
*/
public void replaceFromToWithFromTo(int from, int to, AbstractIntList 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.
@@ -643,12 +643,12 @@
* @exception IndexOutOfBoundsException index is out of range (index < 0 || index >= 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()).intValue()); //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()).intValue()); //delta
}
/**
* Retains (keeps) only the elements in the receiver that are contained in the specified other list.
@@ -658,36 +658,36 @@
* @return <code>true</code> if the receiver changed as a result of the call.
*/
public boolean retainAll(AbstractIntList 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() {
- int 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);
- }
+ int 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.
@@ -697,9 +697,9 @@
* @throws IndexOutOfBoundsException if <tt>index < 0 || index >= size()</tt>.
*/
public void set(int index, int 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.
@@ -730,7 +730,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).
@@ -739,17 +739,17 @@
* @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || to>=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)
- int 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)
+ int tmpElement = getQuick(random);
+ setQuick(random,getQuick(i));
+ setQuick(i,tmpElement);
+ }
}
/**
* Returns the number of elements contained in the receiver.
@@ -757,33 +757,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 AbstractIntList times(int times) {
- AbstractIntList newList = new IntArrayList(times*size());
- for (int i=times; --i >= 0; ) {
- newList.addAllOfFromTo(this,0,size()-1);
- }
- return newList;
+ AbstractIntList newList = new IntArrayList(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 Integer(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 Integer(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/AbstractList.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractList.java?rev=883973&r1=883972&r2=883973&view=diff
==============================================================================
--- lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractList.java (original)
+++ lucene/mahout/trunk/matrix/src/main/java/org/apache/mahout/matrix/list/AbstractList.java Wed Nov 25 03:35:59 2009
@@ -17,8 +17,8 @@
@author wolfgang.hoschek@cern.ch
@version 1.0, 09/24/99
@see java.util.ArrayList
-@see java.util.Vector
-@see java.util.Arrays
+@see java.util.Vector
+@see java.util.Arrays
*/
/**
* @deprecated until unit tests are in place. Until this time, this class/interface is unsupported.
@@ -37,7 +37,7 @@
* of the same parameter type of the receiver.
*/
public void addAllOf(java.util.Collection collection) {
- this.beforeInsertAllOf(size(), collection);
+ this.beforeInsertAllOf(size(), collection);
}
/** Inserts all elements of the specified collection before the specified position into the receiver.
* Shifts the element
@@ -51,8 +51,8 @@
* @throws IndexOutOfBoundsException if <tt>index < 0 || index > size()</tt>.
*/
public void beforeInsertAllOf(int index, java.util.Collection collection) {
- this.beforeInsertDummies(index, collection.size());
- this.replaceFromWith(index, collection);
+ this.beforeInsertDummies(index, collection.size());
+ this.replaceFromWith(index, collection);
}
/**
* Inserts <tt>length</tt> dummy elements before the specified position into the receiver.
@@ -69,24 +69,24 @@
* Checks if the given index is in range.
*/
protected static void checkRange(int index, int theSize) {
- if (index >= theSize || index < 0)
- throw new IndexOutOfBoundsException("Index: "+index+", Size: "+theSize);
+ if (index >= theSize || index < 0)
+ throw new IndexOutOfBoundsException("Index: "+index+", Size: "+theSize);
}
/**
* Checks if the given range is within the contained array's bounds.
* @throws IndexOutOfBoundsException if <tt>to!=from-1 || from<0 || from>to || to>=size()</tt>.
*/
protected static void checkRangeFromTo(int from, int to, int theSize) {
- if (to==from-1) return;
- if (from<0 || from>to || to>=theSize)
- throw new IndexOutOfBoundsException("from: "+from+", to: "+to+", size="+theSize);
+ if (to==from-1) return;
+ if (from<0 || from>to || to>=theSize)
+ throw new IndexOutOfBoundsException("from: "+from+", to: "+to+", size="+theSize);
}
/**
* Removes all elements from the receiver. The receiver will
* be empty after this call returns, but keep its current capacity.
*/
public void clear() {
- removeFromTo(0,size()-1);
+ removeFromTo(0,size()-1);
}
/**
* Sorts the receiver into ascending order.
@@ -103,7 +103,7 @@
* It is generally better to call <tt>sort()</tt> or <tt>sortFromTo(...)</tt> instead, because those methods automatically choose the best sorting algorithm.
*/
public final void mergeSort() {
- mergeSortFromTo(0, size()-1);
+ mergeSortFromTo(0, size()-1);
}
/**
* Sorts the receiver into ascending order.
@@ -137,7 +137,7 @@
* It is generally better to call <tt>sort()</tt> or <tt>sortFromTo(...)</tt> instead, because those methods automatically choose the best sorting algorithm.
*/
public final void quickSort() {
- quickSortFromTo(0, size()-1);
+ quickSortFromTo(0, size()-1);
}
/**
* Sorts the specified range of the receiver into
@@ -164,7 +164,7 @@
* @throws IndexOutOfBoundsException if <tt>index < 0 || index >= size()</tt>.
*/
public void remove(int index) {
- removeFromTo(index, index);
+ removeFromTo(index, index);
}
/**
* Removes from the receiver all elements whose index is between
@@ -201,19 +201,19 @@
* @throws IndexOutOfBoundsException if <tt>newSize < 0</tt>.
*/
public void setSize(int newSize) {
- if (newSize<0) throw new IndexOutOfBoundsException("newSize:"+newSize);
+ if (newSize<0) throw new IndexOutOfBoundsException("newSize:"+newSize);
- int currentSize = size();
- if (newSize!=currentSize) {
- if (newSize>currentSize) beforeInsertDummies(currentSize,newSize-currentSize);
- else if (newSize<currentSize) removeFromTo(newSize, currentSize-1);
- }
+ int currentSize = size();
+ if (newSize!=currentSize) {
+ if (newSize>currentSize) beforeInsertDummies(currentSize,newSize-currentSize);
+ else if (newSize<currentSize) removeFromTo(newSize, currentSize-1);
+ }
}
/**
* Randomly permutes the receiver. After invocation, all elements will be at random positions.
*/
public final void shuffle() {
- shuffleFromTo(0, size()-1);
+ shuffleFromTo(0, size()-1);
}
/**
* Randomly permutes the receiver between <code>from</code> (inclusive) and <code>to</code> (inclusive).
@@ -231,7 +231,7 @@
* Override <tt>sortFromTo(...)</tt> if you can determine which sort is most appropriate for the given data set.
*/
public final void sort() {
- sortFromTo(0, size()-1);
+ sortFromTo(0, size()-1);
}
/**
* Sorts the specified range of the receiver into ascending order.
@@ -245,7 +245,7 @@
* @throws IndexOutOfBoundsException if <tt>(from<0 || from>to || to>=size()) && to!=from-1</tt>.
*/
public void sortFromTo(int from, int to) {
- quickSortFromTo(from, to);
+ quickSortFromTo(from, to);
}
/**
* Trims the capacity of the receiver to be the receiver's current