divisorsBig {bigIntegerAlgos} | R Documentation |
Quickly generates the complete factorization for many (possibly large) numbers.
divisorsBig(v, namedList = FALSE)
v |
Vector of integers, numerics, string values, or elements of class bigz. |
namedList |
Logical flag. If |
Highly optimized algorithm to generate the complete factorization for many numbers. It is built specifically for the data type that is used in the gmp library (i.e. mpz_t
).
The main part of this algorithm is essentially the same algorithm that is implemented in divisorsRcpp from the RcppAlgos package. A modified merge sort algorithm is implemented to better deal with the mpz_t
data type. This algorithm avoids directly swapping elements of the main factor array of type mpz_t
but instead generates a vector of indexing integers for ordering.
See this stack overflow post for examples and benchmarks : R Function for returning ALL factors.
Returns an unnamed vector of class bigz if length(v) == 1
regardless of the value of namedList
.
If length(v) > 1
, a named/unnamed list of vectors of class bigz will be returned.
Joseph Wood
divisorsRcpp
, divisors
, factorize
## Get the complete factorization of a single number divisorsBig(10^15) ## Or get the complete factorization of many numbers set.seed(29) myVec <- sample(-1000000:1000000, 1000) system.time(myFacs <- divisorsBig(myVec)) ## Return named list myFacsWithNames <- divisorsBig(myVec, namedList = TRUE)