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;
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations