Struct quickdiv::DivisorUsize

source ·
pub struct DivisorUsize { /* private fields */ }
Expand description

Faster divisor for division and modulo operations by pointer-sized unsigned integer values.

Implementations§

source§

impl DivisorUsize

source

pub const fn new(d: usize) -> DivisorUsize

Creates a divisor which can be used for faster computation of division and modulo by d.

Panics

Panics if d equals zero.

Examples
use quickdiv::DivisorUsize;

let d = DivisorUsize::new(42);
source

pub const fn get(&self) -> usize

Returns the value that was used to construct this divisor as a primitive type.

Examples
use quickdiv::DivisorUsize;

let d = DivisorUsize::new(7);
assert_eq!(d.get(), 7);
source

pub const fn divides(&self, n: usize) -> bool

Returns true if n is divisible by self.

We take 0 to be divisible by all non-zero numbers.

Examples
use quickdiv::DivisorUsize;

let d = DivisorUsize::new(17);
assert!(d.divides(34));
source

pub const fn rem_of(&self, n: usize) -> usize

Returns the remainder of dividing n by self.

Examples
use quickdiv::DivisorUsize;

let d = DivisorUsize::new(11);
let rem = d.rem_of(30);
assert_eq!(rem, 8);
source

pub const fn div_of(&self, n: usize) -> usize

Returns the result of dividing n by self.

Examples
use quickdiv::DivisorUsize;

let d = DivisorUsize::new(17);
let div = d.div_of(34);
assert_eq!(div, 2);

Trait Implementations§

source§

impl Clone for DivisorUsize

source§

fn clone(&self) -> DivisorUsize

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for DivisorUsize

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Div<DivisorUsize> for usize

§

type Output = usize

The resulting type after applying the / operator.
source§

fn div(self, rhs: DivisorUsize) -> Self::Output

Performs the / operation. Read more
source§

impl DivAssign<DivisorUsize> for usize

source§

fn div_assign(&mut self, rhs: DivisorUsize)

Performs the /= operation. Read more
source§

impl Hash for DivisorUsize

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for DivisorUsize

source§

fn eq(&self, other: &DivisorUsize) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Rem<DivisorUsize> for usize

§

type Output = usize

The resulting type after applying the % operator.
source§

fn rem(self, rhs: DivisorUsize) -> Self::Output

Performs the % operation. Read more
source§

impl RemAssign<DivisorUsize> for usize

source§

fn rem_assign(&mut self, rhs: DivisorUsize)

Performs the %= operation. Read more
source§

impl Copy for DivisorUsize

source§

impl Eq for DivisorUsize

source§

impl StructuralEq for DivisorUsize

source§

impl StructuralPartialEq for DivisorUsize

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>,

§

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>,

§

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.