Skip to content

Commit 6750eb5

Browse files
committed
auto merge of #15050 : kaseyc/rust/impl_eq_for_bitv_bitvset, r=alexcrichton
2 parents 311890c + e103881 commit 6750eb5

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/libcollections/bitv.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -376,27 +376,6 @@ impl Bitv {
376376
}
377377
}
378378

379-
/**
380-
* Compares two bitvectors
381-
*
382-
* Both bitvectors must be the same length. Returns `true` if both
383-
* bitvectors contain identical elements.
384-
*/
385-
#[inline]
386-
pub fn equal(&self, v1: &Bitv) -> bool {
387-
if self.nbits != v1.nbits { return false; }
388-
match self.rep {
389-
Small(ref b) => match v1.rep {
390-
Small(ref b1) => b.equals(b1, self.nbits),
391-
_ => false
392-
},
393-
Big(ref s) => match v1.rep {
394-
Big(ref s1) => s.equals(s1, self.nbits),
395-
Small(_) => return false
396-
}
397-
}
398-
}
399-
400379
/// Set all bits to 0
401380
#[inline]
402381
pub fn clear(&mut self) {
@@ -613,6 +592,25 @@ impl<S: hash::Writer> hash::Hash<S> for Bitv {
613592
}
614593
}
615594

595+
impl cmp::PartialEq for Bitv {
596+
#[inline]
597+
fn eq(&self, other: &Bitv) -> bool {
598+
if self.nbits != other.nbits { return false; }
599+
match self.rep {
600+
Small(ref b) => match other.rep {
601+
Small(ref b1) => b.equals(b1, self.nbits),
602+
_ => false
603+
},
604+
Big(ref s) => match other.rep {
605+
Big(ref s1) => s.equals(s1, self.nbits),
606+
Small(_) => return false
607+
}
608+
}
609+
}
610+
}
611+
612+
impl cmp::Eq for Bitv {}
613+
616614
#[inline]
617615
fn iterate_bits(base: uint, bits: uint, f: |uint| -> bool) -> bool {
618616
if bits == 0 {
@@ -841,6 +839,8 @@ impl cmp::PartialEq for BitvSet {
841839
fn ne(&self, other: &BitvSet) -> bool { !self.eq(other) }
842840
}
843841

842+
impl cmp::Eq for BitvSet {}
843+
844844
impl fmt::Show for BitvSet {
845845
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
846846
try!(write!(fmt, "{{"));
@@ -1323,14 +1323,14 @@ mod tests {
13231323
fn test_equal_differing_sizes() {
13241324
let v0 = Bitv::new(10u, false);
13251325
let v1 = Bitv::new(11u, false);
1326-
assert!(!v0.equal(&v1));
1326+
assert!(v0 != v1);
13271327
}
13281328

13291329
#[test]
13301330
fn test_equal_greatly_differing_sizes() {
13311331
let v0 = Bitv::new(10u, false);
13321332
let v1 = Bitv::new(110u, false);
1333-
assert!(!v0.equal(&v1));
1333+
assert!(v0 != v1);
13341334
}
13351335

13361336
#[test]
@@ -1341,7 +1341,7 @@ mod tests {
13411341
let mut b = bitv::Bitv::new(1, true);
13421342
b.set(0, true);
13431343

1344-
assert!(a.equal(&b));
1344+
assert_eq!(a, b);
13451345
}
13461346

13471347
#[test]
@@ -1356,7 +1356,7 @@ mod tests {
13561356
b.set(i, true);
13571357
}
13581358

1359-
assert!(a.equal(&b));
1359+
assert_eq!(a, b);
13601360
}
13611361

13621362
#[test]

0 commit comments

Comments
 (0)