diff options
| author | bors <bors@rust-lang.org> | 2014-06-20 12:56:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-06-20 12:56:19 +0000 |
| commit | 6750eb5a05042fe3fb84708909074f33ad86d3ec (patch) | |
| tree | 067aed59405bf41861c54ca6904d7a110b3d3c89 | |
| parent | 311890ccfe08af8b0153510b6cfbc33f9a13d102 (diff) | |
| parent | e1038819c2ab190ace31f2f0ac7f4455e3708cfc (diff) | |
| download | rust-6750eb5a05042fe3fb84708909074f33ad86d3ec.tar.gz rust-6750eb5a05042fe3fb84708909074f33ad86d3ec.zip | |
auto merge of #15050 : kaseyc/rust/impl_eq_for_bitv_bitvset, r=alexcrichton
| -rw-r--r-- | src/libcollections/bitv.rs | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index fb5864745d0..572178bd196 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -376,27 +376,6 @@ impl Bitv { } } - /** - * Compares two bitvectors - * - * Both bitvectors must be the same length. Returns `true` if both - * bitvectors contain identical elements. - */ - #[inline] - pub fn equal(&self, v1: &Bitv) -> bool { - if self.nbits != v1.nbits { return false; } - match self.rep { - Small(ref b) => match v1.rep { - Small(ref b1) => b.equals(b1, self.nbits), - _ => false - }, - Big(ref s) => match v1.rep { - Big(ref s1) => s.equals(s1, self.nbits), - Small(_) => return false - } - } - } - /// Set all bits to 0 #[inline] pub fn clear(&mut self) { @@ -613,6 +592,25 @@ impl<S: hash::Writer> hash::Hash<S> for Bitv { } } +impl cmp::PartialEq for Bitv { + #[inline] + fn eq(&self, other: &Bitv) -> bool { + if self.nbits != other.nbits { return false; } + match self.rep { + Small(ref b) => match other.rep { + Small(ref b1) => b.equals(b1, self.nbits), + _ => false + }, + Big(ref s) => match other.rep { + Big(ref s1) => s.equals(s1, self.nbits), + Small(_) => return false + } + } + } +} + +impl cmp::Eq for Bitv {} + #[inline] fn iterate_bits(base: uint, bits: uint, f: |uint| -> bool) -> bool { if bits == 0 { @@ -841,6 +839,8 @@ impl cmp::PartialEq for BitvSet { fn ne(&self, other: &BitvSet) -> bool { !self.eq(other) } } +impl cmp::Eq for BitvSet {} + impl fmt::Show for BitvSet { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "{{")); @@ -1323,14 +1323,14 @@ mod tests { fn test_equal_differing_sizes() { let v0 = Bitv::new(10u, false); let v1 = Bitv::new(11u, false); - assert!(!v0.equal(&v1)); + assert!(v0 != v1); } #[test] fn test_equal_greatly_differing_sizes() { let v0 = Bitv::new(10u, false); let v1 = Bitv::new(110u, false); - assert!(!v0.equal(&v1)); + assert!(v0 != v1); } #[test] @@ -1341,7 +1341,7 @@ mod tests { let mut b = bitv::Bitv::new(1, true); b.set(0, true); - assert!(a.equal(&b)); + assert_eq!(a, b); } #[test] @@ -1356,7 +1356,7 @@ mod tests { b.set(i, true); } - assert!(a.equal(&b)); + assert_eq!(a, b); } #[test] |
