pub struct Factorization { /* private fields */ }Expand description
Represents some number into its prime-factorized form
This struct is only available with the factors feature enabled.
Implementations§
Source§impl Factorization
impl Factorization
Sourcepub fn as_u64(&self) -> u64
pub fn as_u64(&self) -> u64
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());Sourcepub fn as_tuples(&self) -> Vec<(u64, u32)>
pub fn as_tuples(&self) -> Vec<(u64, u32)>
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)]
);Sourcepub fn all_factors(&self) -> Vec<u64>
pub fn all_factors(&self) -> Vec<u64>
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§
Source§impl From<u64> for Factorization
impl From<u64> for Factorization
Source§fn from(number: u64) -> Factorization
fn from(number: u64) -> Factorization
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for Factorization
impl RefUnwindSafe for Factorization
impl Send for Factorization
impl Sync for Factorization
impl Unpin for Factorization
impl UnwindSafe for Factorization
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more