Skip to main content

SaturatingUsize

Struct SaturatingUsize 

Source
pub struct SaturatingUsize<const MAX: usize> { /* private fields */ }
Expand description

コンパイル時定数 MAX を上限とし、0..=MAX の範囲で飽和する usize ラッパーです。

構築・加算・乗算は MAX、減算は 0 で飽和します。除算と剰余は通常の usize 演算で、 飽和しません。usize との演算・比較や相互変換もできます。MAX == 0 も有効です。

§Examples

use atcoder::math::saturating_usize::SaturatingUsize;

type Capacity = SaturatingUsize<10>;

assert_eq!(Capacity::new(15), 10_usize);
assert_eq!(Capacity::new(8) + 5, 10_usize);
assert_eq!(Capacity::new(3) - 5, 0_usize);

let capacity: usize = Capacity::new(7).into();
assert_eq!(capacity, 7);

Implementations§

Source§

impl<const MAX: usize> SaturatingUsize<MAX>

Source

pub const ZERO: Self

値 0 を表します。

Source

pub const MAX: Self

この型が保持できる上限 MAX を表します。

Source

pub const fn new(value: usize) -> Self

value を MAX 以下に丸めて作ります(value > MAX なら MAX)。

Source

pub const fn value(self) -> usize

現在の値(常に 0..=MAX)を返します。

Source

pub const fn val(&self) -> usize

現在の値(常に 0..=MAX)を参照経由で返します。

value と同じです。

Source

pub fn pow(self, exponent: u32) -> Self

self の exponent 乗を計算し、各乗算結果を MAX で飽和させて返します。

指数は u32 です。計算量は O(log exponent) です。指数 0 では 1 を返しますが、 MAX == 0 の場合は構築時に 0 へ丸められます。

Methods from Deref<Target = usize>§

1.43.0 · Source

pub const MIN: usize = 0

1.43.0 · Source

pub const MAX: usize

1.53.0 · Source

pub const BITS: u32

Trait Implementations§

Source§

impl<const MAX: usize> Add for SaturatingUsize<MAX>

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<const MAX: usize> Add<SaturatingUsize<MAX>> for usize

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: SaturatingUsize<MAX>) -> Self::Output

Performs the + operation. Read more
Source§

impl<const MAX: usize> Add<usize> for SaturatingUsize<MAX>

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: usize) -> Self::Output

Performs the + operation. Read more
Source§

impl<const MAX: usize> AddAssign for SaturatingUsize<MAX>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<const MAX: usize> AddAssign<usize> for SaturatingUsize<MAX>

Source§

fn add_assign(&mut self, rhs: usize)

Performs the += operation. Read more
Source§

impl<const MAX: usize> AsRef<usize> for SaturatingUsize<MAX>

Source§

fn as_ref(&self) -> &usize

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const MAX: usize> Borrow<usize> for SaturatingUsize<MAX>

Source§

fn borrow(&self) -> &usize

Immutably borrows from an owned value. Read more
Source§

impl<const MAX: usize> Clone for SaturatingUsize<MAX>

Source§

fn clone(&self) -> SaturatingUsize<MAX>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<const MAX: usize> Copy for SaturatingUsize<MAX>

Source§

impl<const MAX: usize> Debug for SaturatingUsize<MAX>

Source§

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

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

impl<const MAX: usize> Default for SaturatingUsize<MAX>

Source§

fn default() -> SaturatingUsize<MAX>

Returns the “default value” for a type. Read more
Source§

impl<const MAX: usize> Deref for SaturatingUsize<MAX>

Source§

type Target = usize

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<const MAX: usize> Display for SaturatingUsize<MAX>

Source§

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

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

impl<const MAX: usize> Div for SaturatingUsize<MAX>

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<const MAX: usize> Div<SaturatingUsize<MAX>> for usize

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: SaturatingUsize<MAX>) -> Self::Output

Performs the / operation. Read more
Source§

impl<const MAX: usize> Div<usize> for SaturatingUsize<MAX>

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<const MAX: usize> DivAssign for SaturatingUsize<MAX>

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl<const MAX: usize> DivAssign<usize> for SaturatingUsize<MAX>

Source§

fn div_assign(&mut self, rhs: usize)

Performs the /= operation. Read more
Source§

impl<const MAX: usize> Eq for SaturatingUsize<MAX>

Source§

impl<const MAX: usize> From<SaturatingUsize<MAX>> for usize

Source§

fn from(value: SaturatingUsize<MAX>) -> Self

Converts to this type from the input type.
Source§

impl<const MAX: usize> From<usize> for SaturatingUsize<MAX>

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl<const MAX: usize> FromStr for SaturatingUsize<MAX>

Source§

type Err = <usize as FromStr>::Err

The associated error which can be returned from parsing.
Source§

fn from_str(value: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<const MAX: usize> Hash for SaturatingUsize<MAX>

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<const MAX: usize> IntegerExt for SaturatingUsize<MAX>

Source§

fn div_rem(self, rhs: Self) -> (Self, Self)
where Self: Div<Output = Self> + Rem<Output = Self>,

商と余りを (self / rhs, self % rhs) の順に返します。 Read more
Source§

fn chmin(&mut self, rhs: Self) -> bool

rhs が self より小さい場合に self を rhs で置き換えます。 Read more
Source§

fn chmax(&mut self, rhs: Self) -> bool

rhs が self より大きい場合に self を rhs で置き換えます。 Read more
Source§

impl<const MAX: usize> Mul for SaturatingUsize<MAX>

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<const MAX: usize> Mul<SaturatingUsize<MAX>> for usize

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: SaturatingUsize<MAX>) -> Self::Output

Performs the * operation. Read more
Source§

impl<const MAX: usize> Mul<usize> for SaturatingUsize<MAX>

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: usize) -> Self::Output

Performs the * operation. Read more
Source§

impl<const MAX: usize> MulAssign for SaturatingUsize<MAX>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<const MAX: usize> MulAssign<usize> for SaturatingUsize<MAX>

Source§

fn mul_assign(&mut self, rhs: usize)

Performs the *= operation. Read more
Source§

impl<const MAX: usize> Ord for SaturatingUsize<MAX>

Source§

fn cmp(&self, other: &SaturatingUsize<MAX>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<const MAX: usize> PartialEq for SaturatingUsize<MAX>

Source§

fn eq(&self, other: &SaturatingUsize<MAX>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<const MAX: usize> PartialEq<SaturatingUsize<MAX>> for usize

Source§

fn eq(&self, rhs: &SaturatingUsize<MAX>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<const MAX: usize> PartialEq<usize> for SaturatingUsize<MAX>

Source§

fn eq(&self, rhs: &usize) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<const MAX: usize> PartialOrd for SaturatingUsize<MAX>

Source§

fn partial_cmp(&self, other: &SaturatingUsize<MAX>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const MAX: usize> PartialOrd<SaturatingUsize<MAX>> for usize

Source§

fn partial_cmp(&self, rhs: &SaturatingUsize<MAX>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const MAX: usize> PartialOrd<usize> for SaturatingUsize<MAX>

Source§

fn partial_cmp(&self, rhs: &usize) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const MAX: usize> Product for SaturatingUsize<MAX>

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<'a, const MAX: usize> Product<&'a SaturatingUsize<MAX>> for SaturatingUsize<MAX>

Source§

fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<const MAX: usize> Rem for SaturatingUsize<MAX>

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl<const MAX: usize> Rem<SaturatingUsize<MAX>> for usize

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: SaturatingUsize<MAX>) -> Self::Output

Performs the % operation. Read more
Source§

impl<const MAX: usize> Rem<usize> for SaturatingUsize<MAX>

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl<const MAX: usize> RemAssign for SaturatingUsize<MAX>

Source§

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
Source§

impl<const MAX: usize> RemAssign<usize> for SaturatingUsize<MAX>

Source§

fn rem_assign(&mut self, rhs: usize)

Performs the %= operation. Read more
Source§

impl<const MAX: usize> StructuralPartialEq for SaturatingUsize<MAX>

Source§

impl<const MAX: usize> Sub for SaturatingUsize<MAX>

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<const MAX: usize> Sub<SaturatingUsize<MAX>> for usize

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: SaturatingUsize<MAX>) -> Self::Output

Performs the - operation. Read more
Source§

impl<const MAX: usize> Sub<usize> for SaturatingUsize<MAX>

Source§

type Output = SaturatingUsize<MAX>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: usize) -> Self::Output

Performs the - operation. Read more
Source§

impl<const MAX: usize> SubAssign for SaturatingUsize<MAX>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<const MAX: usize> SubAssign<usize> for SaturatingUsize<MAX>

Source§

fn sub_assign(&mut self, rhs: usize)

Performs the -= operation. Read more
Source§

impl<const MAX: usize> Sum for SaturatingUsize<MAX>

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<'a, const MAX: usize> Sum<&'a SaturatingUsize<MAX>> for SaturatingUsize<MAX>

Source§

fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.

Auto Trait Implementations§

§

impl<const MAX: usize> Freeze for SaturatingUsize<MAX>

§

impl<const MAX: usize> RefUnwindSafe for SaturatingUsize<MAX>

§

impl<const MAX: usize> Send for SaturatingUsize<MAX>

§

impl<const MAX: usize> Sync for SaturatingUsize<MAX>

§

impl<const MAX: usize> Unpin for SaturatingUsize<MAX>

§

impl<const MAX: usize> UnsafeUnpin for SaturatingUsize<MAX>

§

impl<const MAX: usize> UnwindSafe for SaturatingUsize<MAX>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.