]> git.lizzy.rs Git - rust.git/commitdiff
Fixing bitvset is_disjoint, fixes #16587
authorAlexis Beingessner <a.beingessner@gmail.com>
Mon, 18 Aug 2014 20:59:52 +0000 (16:59 -0400)
committerAlexis Beingessner <a.beingessner@gmail.com>
Mon, 18 Aug 2014 21:05:26 +0000 (17:05 -0400)
src/libcollections/bitv.rs

index 800f9832226fdbfb07e6efe3cbfc28f00ef368df..6f973bb741e84c8d48fb8db986f65b9a8b4821ac 100644 (file)
@@ -1522,7 +1522,7 @@ fn contains(&self, value: &uint) -> bool {
 
     #[inline]
     fn is_disjoint(&self, other: &BitvSet) -> bool {
-        self.intersection(other).count() > 0
+        self.intersection(other).next().is_none()
     }
 
     #[inline]
@@ -2264,6 +2264,24 @@ fn test_bitv_set_subset() {
         assert!(set1.is_subset(&set2)); // { 2 }  { 2, 4 }
     }
 
+    #[test]
+    fn test_bitv_set_is_disjoint() {
+        let a = BitvSet::from_bitv(from_bytes([0b10100010]));
+        let b = BitvSet::from_bitv(from_bytes([0b01000000]));
+        let c = BitvSet::new();
+        let d = BitvSet::from_bitv(from_bytes([0b00110000]));
+
+        assert!(!a.is_disjoint(&d));
+        assert!(!d.is_disjoint(&a));
+
+        assert!(a.is_disjoint(&b))
+        assert!(a.is_disjoint(&c))
+        assert!(b.is_disjoint(&a))
+        assert!(b.is_disjoint(&c))
+        assert!(c.is_disjoint(&a))
+        assert!(c.is_disjoint(&b))
+    }
+
     #[test]
     fn test_bitv_set_intersect_with() {
         // Explicitly 0'ed bits