Factorization

Struct Factorization 

Source
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

Source

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());
Source

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)]
);
Source

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

Source§

fn from(number: u64) -> Factorization

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.