Example usage for org.apache.commons.math3.util OpenIntToDoubleHashMap containsKey

List of usage examples for org.apache.commons.math3.util OpenIntToDoubleHashMap containsKey

Introduction

In this page you can find the example usage for org.apache.commons.math3.util OpenIntToDoubleHashMap containsKey.

Prototype

public boolean containsKey(final int key) 

Source Link

Document

Check if a value is associated with a key.

Usage

From source file:com.cloudera.oryx.common.math.OpenMapRealVector.java

/**
 * Optimized method to add two OpenMapRealVectors.
 * It copies the larger vector, then iterates over the smaller.
 *
 * @param v Vector to add./*from   ww  w  .j a v a  2 s.c o m*/
 * @return the sum of {@code this} and {@code v}.
 * @throws DimensionMismatchException if the dimensions do not match.
 */
public OpenMapRealVector add(OpenMapRealVector v) {
    checkVectorDimensions(v.getDimension());
    boolean copyThis = entries.size() > v.entries.size();
    OpenMapRealVector res = copyThis ? this.copy() : v.copy();
    OpenIntToDoubleHashMap.Iterator iter = copyThis ? v.entries.iterator() : entries.iterator();
    OpenIntToDoubleHashMap randomAccess = copyThis ? entries : v.entries;
    while (iter.hasNext()) {
        iter.advance();
        int key = iter.key();
        if (randomAccess.containsKey(key)) {
            res.setEntry(key, randomAccess.get(key) + iter.value());
        } else {
            res.setEntry(key, iter.value());
        }
    }
    return res;
}