]> git.lizzy.rs Git - rust.git/commitdiff
Implement Eq for Bitv and BitvSet
authorKasey Carrothers <kaseyc.808@gmail.com>
Fri, 20 Jun 2014 04:13:39 +0000 (21:13 -0700)
committerKasey Carrothers <kaseyc.808@gmail.com>
Fri, 20 Jun 2014 04:13:39 +0000 (21:13 -0700)
src/libcollections/bitv.rs

index fb5864745d055b9803549d9d3425096a6212d3e3..572178bd19664d48e2abe15849a509b6312ac68c 100644 (file)
@@ -376,27 +376,6 @@ pub fn set(&mut self, i: uint, x: bool) {
       }
     }
 
-    /**
-     * 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 @@ fn hash(&self, state: &mut S) {
     }
 }
 
+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 @@ fn eq(&self, other: &BitvSet) -> bool {
     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 @@ fn test_33_elements() {
     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 @@ fn test_equal_sneaky_small() {
         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 @@ fn test_equal_sneaky_big() {
             b.set(i, true);
         }
 
-        assert!(a.equal(&b));
+        assert_eq!(a, b);
     }
 
     #[test]