1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-04 23:17:46 +00:00

factor::Factors: Generalise invariant check (from prime() to add())

This commit is contained in:
nicoo 2020-07-01 00:17:38 +02:00
parent 2d2b6faab4
commit f1d1cb80e4

View file

@ -23,13 +23,13 @@ impl Factors {
} }
pub fn prime(p: u64) -> Factors { pub fn prime(p: u64) -> Factors {
debug_assert!(miller_rabin::is_prime(p));
let mut f = Factors::one(); let mut f = Factors::one();
f.push(p); f.push(p);
f f
} }
pub fn add(&mut self, prime: u64, exp: u8) { pub fn add(&mut self, prime: u64, exp: u8) {
debug_assert!(miller_rabin::is_prime(prime));
debug_assert!(exp > 0); debug_assert!(exp > 0);
let n = *self.f.get(&prime).unwrap_or(&0); let n = *self.f.get(&prime).unwrap_or(&0);
self.f.insert(prime, exp + n); self.f.insert(prime, exp + n);