Struct prime_data::Factorization[][src]

pub struct Factorization { /* fields omitted */ }
Expand description

Represents some number into its prime-factorized form

This struct is only available with the factors feature enabled.

Implementations

Converts some factorization into the original number without consuming itself

Examples
use prime_data::Factorization;
 
assert_eq!(1, Factorization::from(1).as_u64());
assert_eq!(12, Factorization::from(12).as_u64());
assert_eq!(29375346, Factorization::from(29375346).as_u64());

Retrieves the factorization as a tuple (prime, amount)

Note that if the vector is empty, it means the original number is 1.

Examples
use prime_data::Factorization;
 
// 43560 = 2^3 * 3^2 * 5 * 11^2
let factorization = Factorization::from(43560);
assert_eq!(
    factorization.as_tuples(),
    vec![(2, 3), (3, 2), (5, 1), (11, 2)]
);

Retrieves all possible factors of the factorized number

It does so by multiplying every possible combination of its prime factors.

Note: Includes 1 and itself. Therefore, the minimal length for this vector is 1, happening when the original numbers is 1, then length 2, if and only if the original number is prime.

Examples
use prime_data::Factorization;
 
let thirty = Factorization::from(30);
assert_eq!(
    thirty.all_factors(),
    vec![1, 2, 3, 5, 6, 10, 15, 30]
);

Trait Implementations

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.