Java Code Examples for cern.colt.list.IntArrayList#size()

The following examples show how to use cern.colt.list.IntArrayList#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractIntDoubleMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns a string representation of the receiver, containing
 * the String representation of each key-value pair, sorted ascending by value.
 */
public String toStringByValue() {
	IntArrayList theKeys = new IntArrayList();
	keysSortedByValue(theKeys);

	StringBuffer buf = new StringBuffer();
	buf.append("[");
	int maxIndex = theKeys.size() - 1;
	for (int i = 0; i <= maxIndex; i++) {
		int key = theKeys.get(i);
	    buf.append(String.valueOf(key));
		buf.append("->");
	    buf.append(String.valueOf(get(key)));
		if (i < maxIndex) buf.append(", ");
	}
	buf.append("]");
	return buf.toString();
}
 
Example 2
Source File: AbstractIntDoubleMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns a string representation of the receiver, containing
 * the String representation of each key-value pair, sorted ascending by key.
 */
public String toString() {
	IntArrayList theKeys = keys();
	String tmp = theKeys.toString() + "\n";
	theKeys.sort();

	StringBuffer buf = new StringBuffer(tmp);
	//StringBuffer buf = new StringBuffer();
	buf.append("[");
	int maxIndex = theKeys.size() - 1;
	for (int i = 0; i <= maxIndex; i++) {
		int key = theKeys.get(i);
	    buf.append(String.valueOf(key));
		buf.append("->");
	    buf.append(String.valueOf(get(key)));
		if (i < maxIndex) buf.append(", ");
	}
	buf.append("]");
	return buf.toString();
}
 
Example 3
Source File: AbstractIntObjectMap.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a string representation of the receiver, containing
 * the String representation of each key-value pair, sorted ascending by key.
 */
public String toString() {
	IntArrayList theKeys = keys();
	theKeys.sort();

	StringBuffer buf = new StringBuffer();
	buf.append("[");
	int maxIndex = theKeys.size() - 1;
	for (int i = 0; i <= maxIndex; i++) {
		int key = theKeys.get(i);
	    buf.append(String.valueOf(key));
		buf.append("->");
	    buf.append(String.valueOf(get(key)));
		if (i < maxIndex) buf.append(", ");
	}
	buf.append("]");
	return buf.toString();
}
 
Example 4
Source File: AbstractIntObjectMap.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a string representation of the receiver, containing
 * the String representation of each key-value pair, sorted ascending by value, according to natural ordering.
 */
public String toStringByValue() {
	IntArrayList theKeys = new IntArrayList();
	keysSortedByValue(theKeys);

	StringBuffer buf = new StringBuffer();
	buf.append("[");
	int maxIndex = theKeys.size() - 1;
	for (int i = 0; i <= maxIndex; i++) {
		int key = theKeys.get(i);
	    buf.append(String.valueOf(key));
		buf.append("->");
	    buf.append(String.valueOf(get(key)));
		if (i < maxIndex) buf.append(", ");
	}
	buf.append("]");
	return buf.toString();
}
 
Example 5
Source File: AbstractIntIntMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns a string representation of the receiver, containing
 * the String representation of each key-value pair, sorted ascending by key.
 */
public String toString() {
	IntArrayList theKeys = keys();
	//theKeys.sort(); 

	StringBuffer buf = new StringBuffer();
	buf.append("[");
	int maxIndex = theKeys.size() - 1;
	for (int i = 0; i <= maxIndex; i++) {
		int key = theKeys.get(i);
	    buf.append(String.valueOf(key));
		buf.append("->");
	    buf.append(String.valueOf(get(key)));
		if (i < maxIndex) buf.append(", ");
	}
	buf.append("]");
	return buf.toString();
}
 
Example 6
Source File: AbstractIntIntMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns a string representation of the receiver, containing
 * the String representation of each key-value pair, sorted ascending by value.
 */
public String toStringByValue() {
	IntArrayList theKeys = new IntArrayList();
	keysSortedByValue(theKeys);

	StringBuffer buf = new StringBuffer();
	buf.append("[");
	int maxIndex = theKeys.size() - 1;
	for (int i = 0; i <= maxIndex; i++) {
		int key = theKeys.get(i);
	    buf.append(String.valueOf(key));
		buf.append("->");
	    buf.append(String.valueOf(get(key)));
		if (i < maxIndex) buf.append(", ");
	}
	buf.append("]");
	return buf.toString();
}
 
Example 7
Source File: AbstractIntObjectMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns a string representation of the receiver, containing
 * the String representation of each key-value pair, sorted ascending by key.
 */
public String toString() {
	IntArrayList theKeys = keys();
	theKeys.sort();

	StringBuffer buf = new StringBuffer();
	buf.append("[");
	int maxIndex = theKeys.size() - 1;
	for (int i = 0; i <= maxIndex; i++) {
		int key = theKeys.get(i);
	    buf.append(String.valueOf(key));
		buf.append("->");
	    buf.append(String.valueOf(get(key)));
		if (i < maxIndex) buf.append(", ");
	}
	buf.append("]");
	return buf.toString();
}
 
Example 8
Source File: AbstractIntObjectMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns a string representation of the receiver, containing
 * the String representation of each key-value pair, sorted ascending by value, according to natural ordering.
 */
public String toStringByValue() {
	IntArrayList theKeys = new IntArrayList();
	keysSortedByValue(theKeys);

	StringBuffer buf = new StringBuffer();
	buf.append("[");
	int maxIndex = theKeys.size() - 1;
	for (int i = 0; i <= maxIndex; i++) {
		int key = theKeys.get(i);
	    buf.append(String.valueOf(key));
		buf.append("->");
	    buf.append(String.valueOf(get(key)));
		if (i < maxIndex) buf.append(", ");
	}
	buf.append("]");
	return buf.toString();
}
 
Example 9
Source File: VectorBuilder.java    From first-stories-twitter with MIT License 5 votes vote down vote up
/**
 * Normalization by dividing with Euclid norm.
 * @param vector
 */
public SparseVector normalizeVector(SparseVector vector) {
    //NORMALIZE HERE with norm1 so a unit vector is produced
    IntArrayList indexes = new IntArrayList(vector.cardinality());
    DoubleArrayList dbls = new DoubleArrayList(vector.cardinality());
    double norm = vector.getEuclidNorm();
    vector.getNonZeros(indexes, dbls);
    for (int i = 0; i < indexes.size(); i++) {
        vector.setQuick(indexes.get(i), dbls.getQuick(i) / norm);
    }
    return vector;
}
 
Example 10
Source File: ScanningAlgorithm.java    From CFGScanDroid with GNU General Public License v2.0 5 votes vote down vote up
public static SparseDoubleMatrix2D reduceCandidateList(IntArrayList signatureNonZeros, IntArrayList functionNonZeros, SparseDoubleMatrix2D candidateList) {
	// reduce
	for(int i=0; i<signatureNonZeros.size(); ++i) {
		// find nodes with only one possible candidate
		if(candidateList.viewRow(signatureNonZeros.get(i)).cardinality() == 1) {
			int nonZero = -1;
			for(int j=0; j<functionNonZeros.size(); ++j) {
				if(candidateList.get(signatureNonZeros.get(i), functionNonZeros.get(j)) != 0.0) {
					nonZero = functionNonZeros.get(j);
					break;
				}
			}	

			if(nonZero == -1){
				System.out.println("REDUCE LOOP IS BROKEN - J NOT FOUND");
				System.out.println(signatureNonZeros);
				System.out.println(functionNonZeros);
				System.out.println(candidateList);
				System.out.println();
				break;
			}

			// remove candidacy of other nodes since it /has/ to be that one node
			for(int x=0; x<signatureNonZeros.size(); ++x) {
				if(x != i) {
					candidateList.set(signatureNonZeros.get(x), nonZero, 0.0);
				}
			}
		}
	}

	return candidateList;
}
 
Example 11
Source File: DoubleMatrix1D.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the dot product of two vectors x and y, which is <tt>Sum(x[i]*y[i])</tt>.
 * Where <tt>x == this</tt>.
 * @param y the second vector.
 * @param nonZeroIndexes the indexes of cells in <tt>y</tt>having a non-zero value.
 * @return the sum of products.
 */
public double zDotProduct(DoubleMatrix1D y, int from, int length, IntArrayList nonZeroIndexes) {
	// determine minimum length
	if (from<0 || length<=0) return 0;
	
	int tail = from+length;
	if (size < tail) tail = size;
	if (y.size < tail) tail = y.size;
	length = tail-from;
	if (length<=0) return 0;

	// setup
	int[] nonZeroIndexElements = nonZeroIndexes.elements();
	int index = 0;
	int s = nonZeroIndexes.size();
	
	// skip to start	
	while ((index < s) && nonZeroIndexElements[index]<from) index++; 

	// now the sparse dot product
	int i;
	double sum = 0;
	while ((--length >= 0) && (index < s) && ((i=nonZeroIndexElements[index]) < tail)) {
		sum += getQuick(i) * y.getQuick(i);
		index++;
	}
	
	return sum;
}
 
Example 12
Source File: DoubleMatrix1D.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the dot product of two vectors x and y, which is <tt>Sum(x[i]*y[i])</tt>.
 * Where <tt>x == this</tt>.
 * @param y the second vector.
 * @param nonZeroIndexes the indexes of cells in <tt>y</tt>having a non-zero value.
 * @return the sum of products.
 */
public double zDotProduct(DoubleMatrix1D y, int from, int length, IntArrayList nonZeroIndexes) {
	// determine minimum length
	if (from<0 || length<=0) return 0;
	
	int tail = from+length;
	if (size < tail) tail = size;
	if (y.size < tail) tail = y.size;
	length = tail-from;
	if (length<=0) return 0;

	// setup
	int[] nonZeroIndexElements = nonZeroIndexes.elements();
	int index = 0;
	int s = nonZeroIndexes.size();
	
	// skip to start	
	while ((index < s) && nonZeroIndexElements[index]<from) index++; 

	// now the sparse dot product
	int i;
	double sum = 0;
	while ((--length >= 0) && (index < s) && ((i=nonZeroIndexElements[index]) < tail)) {
		sum += getQuick(i) * y.getQuick(i);
		index++;
	}
	
	return sum;
}
 
Example 13
Source File: IntBuffer2D.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adds all specified points (x,y) to the receiver.
 * @param x the x-coordinates of the points to add.
 * @param y the y-coordinates of the points to add.
 */
public void addAllOf(IntArrayList x, IntArrayList y) {
	int listSize = x.size();
	if (this.size + listSize >= this.capacity) flush();
	this.target.addAllOf(x, y);
}
 
Example 14
Source File: ScanningAlgorithm.java    From CFGScanDroid with GNU General Public License v2.0 4 votes vote down vote up
public static boolean bipartiteMatchingVector(DoubleMatrix2D candidateList, DoubleMatrix2D signatureNodeVector, DoubleMatrix2D functionNodeVector, int[] signatureDepths, int[] functionDepths) {
	UndirectedGraph<String, DefaultEdge> g = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class);

	IntArrayList signatureNonZeros = new IntArrayList();
	IntArrayList functionNonZeros = new IntArrayList();
	IntArrayList unusedInt = new IntArrayList();
	DoubleArrayList unusedDouble = new DoubleArrayList();

	// get set column indices for signature vector and function vector
	signatureNodeVector.getNonZeros(unusedInt, signatureNonZeros, unusedDouble);
	functionNodeVector.getNonZeros(unusedInt, functionNonZeros, unusedDouble);
	
	List<String> signatureIdcs = new ArrayList<String>();
	List<String> functionIdcs = new ArrayList<String>();
	int signatureNodeCount = 0;
	// add signature nodes graph
	for(int i=0; i<signatureNonZeros.size(); ++i) {
		int signatureIdx = signatureNonZeros.get(i);
		if(signatureDepths[signatureIdx] != -1) {
			signatureIdcs.add("s"+signatureIdx);
			g.addVertex("s"+signatureIdx);
			signatureNodeCount++;
		}
	}

	// add function nodes graph
	for(int j=0; j<functionNonZeros.size(); ++j) {
		int functionIdx = functionNonZeros.get(j);
		if(functionDepths[functionIdx] != -1) {
			functionIdcs.add("f"+functionNonZeros.get(j));
			g.addVertex("f"+functionNonZeros.get(j));
		}
	}

	// add edges
	for(int i=0; i<signatureNonZeros.size(); ++i) {
		for(int j=0; j<functionNonZeros.size(); ++j) {
			if(candidateList.get(signatureNonZeros.get(i), functionNonZeros.get(j)) != 0) {
				g.addEdge("s"+signatureNonZeros.get(i), "f"+functionNonZeros.get(j));
			}
		}
	}

	// define sets
	Set<String> p1 = new HashSet<String>(signatureIdcs);
       Set<String> p2 = new HashSet<String>(functionIdcs);

       // bipartite matching!
	HopcroftKarpBipartiteMatching<String, DefaultEdge> alg = 
		new HopcroftKarpBipartiteMatching<String, DefaultEdge>(g, p1, p2);

	Set<DefaultEdge> match = alg.getMatching();
	// sat || unsat
	if(match.size() == signatureNodeCount) {
		return true;
	} else { 
		return false;
	}

}
 
Example 15
Source File: IntBuffer.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Adds all elements of the specified list to the receiver.
 * @param list the list of which all elements shall be added.
 */
public void addAllOf(IntArrayList list) {
	int listSize = list.size();
	if (this.size + listSize >= this.capacity) flush();
	this.target.addAllOf(list);
}
 
Example 16
Source File: AbstractIntDoubleMap.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Fills all keys and values <i>sorted ascending by key</i> into the specified lists.
 * Fills into the lists, starting at index 0.
 * After this call returns the specified lists both have a new size that equals <tt>this.size()</tt>.
 * <p>
 * <b>Example:</b>
 * <br>
 * <tt>keys = (8,7,6), values = (1,2,2) --> keyList = (6,7,8), valueList = (2,2,1)</tt>
 *
 * @param keyList the list to be filled with keys, can have any size.
 * @param valueList the list to be filled with values, can have any size.
 */
public void pairsSortedByKey(final IntArrayList keyList, final DoubleArrayList valueList) {
	keys(keyList);
	keyList.sort();
	valueList.setSize(keyList.size());
	for (int i=keyList.size(); --i >= 0; ) {
		valueList.setQuick(i,get(keyList.getQuick(i)));
	}
}
 
Example 17
Source File: AbstractIntIntMap.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Fills all keys and values <i>sorted ascending by key</i> into the specified lists.
 * Fills into the lists, starting at index 0.
 * After this call returns the specified lists both have a new size that equals <tt>this.size()</tt>.
 * <p>
 * <b>Example:</b>
 * <br>
 * <tt>keys = (8,7,6), values = (1,2,2) --> keyList = (6,7,8), valueList = (2,2,1)</tt>
 *
 * @param keyList the list to be filled with keys, can have any size.
 * @param valueList the list to be filled with values, can have any size.
 */
public void pairsSortedByKey(final IntArrayList keyList, final IntArrayList valueList) {
	keys(keyList);
	keyList.sort();
	valueList.setSize(keyList.size());
	for (int i=keyList.size(); --i >= 0; ) {
		valueList.setQuick(i,get(keyList.getQuick(i)));
	}
}
 
Example 18
Source File: AbstractIntObjectMap.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Fills all keys and values <i>sorted ascending by key</i> into the specified lists.
 * Fills into the lists, starting at index 0.
 * After this call returns the specified lists both have a new size that equals <tt>this.size()</tt>.
 * <p>
 * <b>Example:</b>
 * <br>
 * <tt>keys = (8,7,6), values = (1,2,2) --> keyList = (6,7,8), valueList = (2,2,1)</tt>
 *
 * @param keyList the list to be filled with keys, can have any size.
 * @param valueList the list to be filled with values, can have any size.
 */
public void pairsSortedByKey(final IntArrayList keyList, final ObjectArrayList valueList) {
	keys(keyList);
	keyList.sort();
	valueList.setSize(keyList.size());
	for (int i=keyList.size(); --i >= 0; ) {
		valueList.setQuick(i,get(keyList.getQuick(i)));
	}
}
 
Example 19
Source File: AbstractIntDoubleMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Fills all keys and values <i>sorted ascending by key</i> into the specified lists.
 * Fills into the lists, starting at index 0.
 * After this call returns the specified lists both have a new size that equals <tt>this.size()</tt>.
 * <p>
 * <b>Example:</b>
 * <br>
 * <tt>keys = (8,7,6), values = (1,2,2) --> keyList = (6,7,8), valueList = (2,2,1)</tt>
 *
 * @param keyList the list to be filled with keys, can have any size.
 * @param valueList the list to be filled with values, can have any size.
 */
public void pairsSortedByKey(final IntArrayList keyList, final DoubleArrayList valueList) {
	keys(keyList);
	keyList.sort();
	valueList.setSize(keyList.size());
	for (int i=keyList.size(); --i >= 0; ) {
		valueList.setQuick(i,get(keyList.getQuick(i)));
	}
}
 
Example 20
Source File: IntBuffer3D.java    From jAudioGIT with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Adds all specified (x,y,z) points to the receiver.
 * @param xElements the x-coordinates of the points.
 * @param yElements the y-coordinates of the points.
 * @param zElements the y-coordinates of the points.
 */
public void addAllOf(IntArrayList xElements, IntArrayList yElements, IntArrayList zElements) {
	int listSize = xElements.size();
	if (this.size + listSize >= this.capacity) flush();
	this.target.addAllOf(xElements, yElements, zElements);
}