Search in sources :

Example 96 with SortedMap

use of java.util.SortedMap in project symja_android_library by axkr.

the class ExprPolynomial method multiply.

/**
	 * GenPolynomial multiplication. Product with coefficient ring element.
	 * 
	 * @param s
	 *            coefficient.
	 * @return this*s.
	 */
public ExprPolynomial multiply(IExpr s) {
    if (s == null) {
        return ring.getZero();
    }
    if (s.isZero()) {
        return ring.getZero();
    }
    if (this.isZero()) {
        return this;
    }
    // if (this instanceof GenSolvablePolynomial) {
    // // throw new RuntimeException("wrong method dispatch in JRE ");
    // logger.debug("warn: wrong method dispatch in JRE multiply(s) - trying
    // to fix");
    // GenSolvablePolynomial<C> T = (GenSolvablePolynomial<C>) this;
    // return T.multiply(s);
    // }
    ExprPolynomial p = ring.getZero().copy();
    SortedMap<ExpVectorLong, IExpr> pv = p.val;
    for (Map.Entry<ExpVectorLong, IExpr> m1 : val.entrySet()) {
        IExpr c1 = m1.getValue();
        ExpVectorLong e1 = m1.getKey();
        // check non zero if not domain
        IExpr c = c1.multiply(s);
        if (!c.isZero()) {
            // or m1.setValue( c )
            pv.put(e1, c);
        }
    }
    return p;
}
Also used : JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 97 with SortedMap

use of java.util.SortedMap in project symja_android_library by axkr.

the class AbstractIntegerSym method factorize.

/**
	 * Get all prime factors of this integer
	 * 
	 * @param result
	 *            add the prime factors to this result list
	 * @return
	 */
public IAST factorize(IAST result) {
    IInteger b = this;
    if (sign() < 0) {
        b = b.negate();
        result.append(F.CN1);
    } else if (b.isZero()) {
        result.append(F.C0);
        return result;
    } else if (b.isOne()) {
        result.append(F.C1);
        return result;
    }
    if (b instanceof IntegerSym) {
        Map<Long, Integer> map = PrimeInteger.factors(b.longValue());
        for (Map.Entry<Long, Integer> entry : map.entrySet()) {
            long key = entry.getKey();
            IInteger is = valueOf(key);
            for (int i = 0; i < entry.getValue(); i++) {
                result.append(is);
            }
        }
        return result;
    }
    SortedMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
    BigInteger rest = Primality.countPrimes32749(b.toBigNumerator(), map);
    for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
        int key = entry.getKey();
        AbstractIntegerSym is = valueOf(key);
        for (int i = 0; i < entry.getValue(); i++) {
            result.append(is);
        }
    }
    if (rest.equals(BigInteger.ONE)) {
        return result;
    }
    if (rest.isProbablePrime(PRIME_CERTAINTY)) {
        result.append(valueOf(rest));
        return result;
    }
    b = valueOf(rest);
    SortedMap<BigInteger, Integer> bigMap = new TreeMap<BigInteger, Integer>();
    Primality.factorInteger(rest, bigMap);
    for (Map.Entry<BigInteger, Integer> entry : bigMap.entrySet()) {
        BigInteger key = entry.getKey();
        IInteger is = valueOf(key);
        for (int i = 0; i < entry.getValue(); i++) {
            result.append(is);
        }
    }
    return result;
}
Also used : TreeMap(java.util.TreeMap) IInteger(org.matheclipse.core.interfaces.IInteger) BigInteger(java.math.BigInteger) PrimeInteger(edu.jas.arith.PrimeInteger) IInteger(org.matheclipse.core.interfaces.IInteger) IVisitorLong(org.matheclipse.core.visit.IVisitorLong) BigInteger(java.math.BigInteger) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 98 with SortedMap

use of java.util.SortedMap in project cdap by caskdata.

the class HBaseMetricsTable method put.

@Override
public void put(SortedMap<byte[], ? extends SortedMap<byte[], Long>> updates) {
    List<Put> puts = Lists.newArrayList();
    for (Map.Entry<byte[], ? extends SortedMap<byte[], Long>> row : updates.entrySet()) {
        PutBuilder put = tableUtil.buildPut(row.getKey());
        for (Map.Entry<byte[], Long> column : row.getValue().entrySet()) {
            put.add(columnFamily, column.getKey(), Bytes.toBytes(column.getValue()));
        }
        puts.add(put.build());
    }
    try {
        hTable.put(puts);
        hTable.flushCommits();
    } catch (IOException e) {
        throw new DataSetException("Put failed on table " + tableId, e);
    }
}
Also used : PutBuilder(co.cask.cdap.data2.util.hbase.PutBuilder) DataSetException(co.cask.cdap.api.dataset.DataSetException) IOException(java.io.IOException) Map(java.util.Map) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) Put(org.apache.hadoop.hbase.client.Put)

Example 99 with SortedMap

use of java.util.SortedMap in project cdap by caskdata.

the class HBaseMetricsTable method putBytes.

@Override
public void putBytes(SortedMap<byte[], ? extends SortedMap<byte[], byte[]>> updates) {
    List<Put> puts = Lists.newArrayList();
    for (Map.Entry<byte[], ? extends SortedMap<byte[], byte[]>> row : updates.entrySet()) {
        PutBuilder put = tableUtil.buildPut(row.getKey());
        for (Map.Entry<byte[], byte[]> column : row.getValue().entrySet()) {
            put.add(columnFamily, column.getKey(), column.getValue());
        }
        puts.add(put.build());
    }
    try {
        hTable.put(puts);
        hTable.flushCommits();
    } catch (IOException e) {
        throw new DataSetException("Put failed on table " + tableId, e);
    }
}
Also used : PutBuilder(co.cask.cdap.data2.util.hbase.PutBuilder) DataSetException(co.cask.cdap.api.dataset.DataSetException) IOException(java.io.IOException) Map(java.util.Map) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) Put(org.apache.hadoop.hbase.client.Put)

Example 100 with SortedMap

use of java.util.SortedMap in project cdap by caskdata.

the class MetricsTableOnTable method putBytes.

@Override
public void putBytes(SortedMap<byte[], ? extends SortedMap<byte[], byte[]>> updates) {
    for (Map.Entry<byte[], ? extends SortedMap<byte[], byte[]>> rowUpdate : updates.entrySet()) {
        Put put = new Put(rowUpdate.getKey());
        for (Map.Entry<byte[], byte[]> columnUpdate : rowUpdate.getValue().entrySet()) {
            put.add(columnUpdate.getKey(), columnUpdate.getValue());
        }
        table.put(put);
    }
}
Also used : Map(java.util.Map) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) Put(co.cask.cdap.api.dataset.table.Put)

Aggregations

SortedMap (java.util.SortedMap)216 Map (java.util.Map)162 TreeMap (java.util.TreeMap)108 HashMap (java.util.HashMap)59 Iterator (java.util.Iterator)31 NavigableMap (java.util.NavigableMap)31 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)25 IOException (java.io.IOException)20 ImmutableMap (com.google.common.collect.ImmutableMap)19 JASIExpr (org.matheclipse.core.convert.JASIExpr)16 IExpr (org.matheclipse.core.interfaces.IExpr)16 List (java.util.List)15 File (java.io.File)14 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)14 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)12 Entry (java.util.Map.Entry)12 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)12 ConcurrentMap (java.util.concurrent.ConcurrentMap)11 LinkedHashMap (java.util.LinkedHashMap)9