pub struct Context<U> { /* private fields */ }Expand description
Storage of parameters for Montgomery multiplication.
Implementations§
Source§impl Context<u64>
impl Context<u64>
Sourcepub const fn new(n: u64) -> Self
pub const fn new(n: u64) -> Self
Calculates some parameters for Montgomery multiplication.
§Panics
- modulus
nshould be an odd number.
pub const fn modulo(&self, x: u64) -> Modulo<'_, u64>
Sourcepub const fn can_divide(&self, x: u64) -> bool
pub const fn can_divide(&self, x: u64) -> bool
Checks whether x is multiple of self.
§Example
use lib_modulo::Context;
for n in (1..1 << 10).step_by(2) {
let ctx = Context::<u64>::new(n);
(0..1 << 10).for_each(|k| assert!(ctx.can_divide(n * k)));
}Source§impl Context<u32>
impl Context<u32>
Sourcepub const fn new(n: u32) -> Self
pub const fn new(n: u32) -> Self
Calculates some parameters for Montgomery multiplication.
§Panics
- modulus
nshould be an odd number.
pub const fn modulo(&self, x: u32) -> Modulo<'_, u32>
Sourcepub const fn can_divide(&self, x: u32) -> bool
pub const fn can_divide(&self, x: u32) -> bool
Checks whether x is multiple of self.
§Example
use lib_modulo::Context;
for n in (1..1 << 10).step_by(2) {
let ctx = Context::<u32>::new(n);
(0..1 << 10).for_each(|k| assert!(ctx.can_divide(n * k)));
}Trait Implementations§
impl<U: Eq> Eq for Context<U>
impl<U> StructuralPartialEq for Context<U>
Auto Trait Implementations§
impl<U> Freeze for Context<U>where
U: Freeze,
impl<U> RefUnwindSafe for Context<U>where
U: RefUnwindSafe,
impl<U> Send for Context<U>where
U: Send,
impl<U> Sync for Context<U>where
U: Sync,
impl<U> Unpin for Context<U>where
U: Unpin,
impl<U> UnsafeUnpin for Context<U>where
U: UnsafeUnpin,
impl<U> UnwindSafe for Context<U>where
U: UnwindSafe,
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