diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/numbertheory/Primality.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/numbertheory/Primality.java index fbda6f2573..a14a0405d4 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/numbertheory/Primality.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/numbertheory/Primality.java @@ -27,6 +27,7 @@ import de.tilman_neumann.jml.factor.CombinedFactorAlgorithm; import de.tilman_neumann.util.SortedMultiset; +import de.tilman_neumann.util.SortedMultiset_BottomUp; import it.unimi.dsi.fastutil.ints.Int2IntMap; /** @@ -36,7 +37,7 @@ */ public class Primality { - private static class PrimePowerTreedMap extends TreeMap { + private static class PrimePowerTreedMap extends SortedMultiset_BottomUp { private static final long serialVersionUID = 7802239809732541730L; @Override @@ -50,7 +51,7 @@ public Integer put(BigInteger key, Integer value) { } } - private static class SquareFreeTreedMap extends TreeMap { + private static class SquareFreeTreedMap extends SortedMultiset_BottomUp { private static final long serialVersionUID = -7769218967264615452L; @Override @@ -753,7 +754,7 @@ public static List factorize(final BigInteger val, List * @param n * @param map of all BigInteger primes and their associated exponents */ - public static void factorInteger(final BigInteger n, SortedMap map) { + public static void factorInteger(final BigInteger n, SortedMultiset map) { Map tMap = new TreeMap(); BigInteger N = countPrimes1021(n, tMap); if (tMap.size() > 0) { @@ -769,11 +770,7 @@ public static void factorInteger(final BigInteger n, SortedMap set = factorizer.factor(N); - - for (Map.Entry entry : set.entrySet()) { - map.put(entry.getKey(), entry.getValue()); - } + factorizer.factor(N, map); } return; } @@ -786,17 +783,14 @@ public static void factorInteger(final BigInteger n, SortedMap factorInteger(final BigInteger n) { - SortedMap map = new TreeMap(); - factorInteger(n, map); - return map; - // CombinedFactorAlgorithm factorizer; - // if (Config.JAVA_UNSAFE) { - // final int cores = Runtime.getRuntime().availableProcessors(); - // factorizer = new CombinedFactorAlgorithm(cores / 2 + 1, null, true, false, true); - // } else { - // factorizer = new CombinedFactorAlgorithm(1, null, false, false, true); - // } - // return factorizer.factor(n); + CombinedFactorAlgorithm factorizer; + if (Config.JAVA_UNSAFE) { + final int cores = Runtime.getRuntime().availableProcessors(); + factorizer = new CombinedFactorAlgorithm(cores / 2 + 1, null, true, false, true); + } else { + factorizer = new CombinedFactorAlgorithm(1, null, false, false, true); + } + return factorizer.factor(n); } public static BigInteger rho(final BigInteger val) { @@ -1061,7 +1055,7 @@ public static int moebiusMu(BigInteger value) { if (value.equals(BigInteger.ONE)) { return 1; } - SortedMap map = new SquareFreeTreedMap(); + SortedMultiset map = new SquareFreeTreedMap(); try { factorInteger(value, map); // value is square-free @@ -1147,7 +1141,7 @@ public static boolean isPrimePower(BigInteger value) { return false; } try { - SortedMap map = new PrimePowerTreedMap(); + PrimePowerTreedMap map = new PrimePowerTreedMap(); factorInteger(value, map); if (map.size() == 1) { for (Map.Entry entry : map.entrySet()) { @@ -1200,9 +1194,8 @@ public static boolean isSquareFree(BigInteger val) { if (val.compareTo(BigInteger.ZERO) < 0) { val = val.negate(); } - SortedMap map = new SquareFreeTreedMap(); try { - factorInteger(val, map); + factorInteger(val, new SquareFreeTreedMap()); return true; } catch (ReturnException re) { }