Skip to content

Commit

Permalink
Merge #82
Browse files Browse the repository at this point in the history
82: overwrite Zero/One default impls for `set_zero` and `set_one` r=cuviper a=lcnr

title

Co-authored-by: lcnr/Bastian Kauschke <bastian_kauschke@hotmail.de>
Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
3 people committed Jun 1, 2019
2 parents 1fc6526 + 7bf4b14 commit b90ed60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ version = "0.1.39"
default-features = false

[dependencies.num-traits]
version = "0.2.4"
version = "0.2.7"
default-features = false

[dependencies.rand]
Expand Down
12 changes: 12 additions & 0 deletions src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,12 @@ impl Zero for BigInt {
BigInt::from_biguint(NoSign, Zero::zero())
}

#[inline]
fn set_zero(&mut self) {
self.data.set_zero();
self.sign = NoSign;
}

#[inline]
fn is_zero(&self) -> bool {
self.sign == NoSign
Expand All @@ -768,6 +774,12 @@ impl One for BigInt {
BigInt::from_biguint(Plus, One::one())
}

#[inline]
fn set_one(&mut self) {
self.data.set_one();
self.sign = Plus;
}

#[inline]
fn is_one(&self) -> bool {
self.sign == Plus && self.data.is_one()
Expand Down
11 changes: 11 additions & 0 deletions src/biguint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ impl Zero for BigUint {
BigUint::new(Vec::new())
}

#[inline]
fn set_zero(&mut self) {
self.data.clear();
}

#[inline]
fn is_zero(&self) -> bool {
self.data.is_empty()
Expand All @@ -429,6 +434,12 @@ impl One for BigUint {
BigUint::new(vec![1])
}

#[inline]
fn set_one(&mut self) {
self.data.clear();
self.data.push(1);
}

#[inline]
fn is_one(&self) -> bool {
self.data[..] == [1]
Expand Down

0 comments on commit b90ed60

Please sign in to comment.