Class FactorAlgorithm

    • Field Detail

      • DEFAULT

        public static final FactorAlgorithm DEFAULT
        The best available single-threaded factor algorithm. (multi-threading may not always be wanted)
      • NUM_PRIMES_FOR_31_BIT_TDIV

        protected static final int NUM_PRIMES_FOR_31_BIT_TDIV
        the number of primes needed to factor any int <= 2^31 - 1 using trial division
        See Also:
        Constant Field Values
      • tdivLimit

        protected Integer tdivLimit
    • Constructor Detail

      • FactorAlgorithm

        public FactorAlgorithm()
      • FactorAlgorithm

        public FactorAlgorithm​(Integer tdivLimit)
    • Method Detail

      • getName

        public abstract String getName()
        Returns:
        The name of the algorithm, possibly including important parameters.
      • factor

        public SortedMultiset<BigInteger> factor​(BigInteger N)
        Decomposes the argument N into prime factors. The result is a multiset of BigIntegers, sorted bottom-up.
        Parameters:
        N - Number to factor.
        Returns:
        The prime factorization of N
      • factor

        public void factor​(BigInteger N,
                           SortedMultiset<BigInteger> primeFactors)
        Decomposes the argument N into prime factors.
        Parameters:
        N - Number to factor.
        primeFactors - a map to which found factors are added
      • searchFactors

        public void searchFactors​(FactorArguments args,
                                  FactorResult result)
        Try to find at least one factor of the given args.N, which is composite and odd. This is a default implementation for algorithms that will only find a single factor or none at all. For sub-algorithms that may find more factors at once this method should be overwritten appropriately.
        Parameters:
        args -
        result - the result of the factoring attempt. Should be initialized only once by the caller to reduce overhead.
      • findSingleFactor

        public abstract BigInteger findSingleFactor​(BigInteger N)
        Find a single factor of the given N, which is composite and odd.
        Parameters:
        N -
        Returns:
        factor