]> git.lizzy.rs Git - rust.git/commitdiff
Reorder bitvec.rs.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 13 Sep 2018 03:27:56 +0000 (13:27 +1000)
committerNicholas Nethercote <nnethercote@mozilla.com>
Thu, 13 Sep 2018 03:27:56 +0000 (13:27 +1000)
So that the `BitArray` code is all together and before the `BitVector`
code, instead of being awkwardly interleaved.

src/librustc_data_structures/bitvec.rs

index 642d24f48313a26cb76f4880863c115f713f8829..acf33697f58b57f34eefb513a7db718ca8db3ad2 100644 (file)
@@ -23,46 +23,6 @@ pub struct BitArray<C: Idx> {
     marker: PhantomData<C>,
 }
 
-#[derive(Clone, Debug, PartialEq)]
-pub struct BitVector<C: Idx> {
-    data: BitArray<C>,
-}
-
-impl<C: Idx> BitVector<C> {
-    pub fn grow(&mut self, num_bits: C) {
-        self.data.grow(num_bits)
-    }
-
-    pub fn new() -> BitVector<C> {
-        BitVector {
-            data: BitArray::new(0),
-        }
-    }
-
-    pub fn with_capacity(bits: usize) -> BitVector<C> {
-        BitVector {
-            data: BitArray::new(bits),
-        }
-    }
-
-    /// Returns true if the bit has changed.
-    #[inline]
-    pub fn insert(&mut self, bit: C) -> bool {
-        self.grow(bit);
-        self.data.insert(bit)
-    }
-
-    #[inline]
-    pub fn contains(&self, bit: C) -> bool {
-        let (word, mask) = word_mask(bit);
-        if let Some(word) = self.data.data.get(word) {
-            (word & mask) != 0
-        } else {
-            false
-        }
-    }
-}
-
 impl<C: Idx> BitArray<C> {
     // Do not make this method public, instead switch your use case to BitVector.
     #[inline]
@@ -206,6 +166,43 @@ fn size_hint(&self) -> (usize, Option<usize>) {
     }
 }
 
+/// A resizable BitVector type.
+#[derive(Clone, Debug, PartialEq)]
+pub struct BitVector<C: Idx> {
+    data: BitArray<C>,
+}
+
+impl<C: Idx> BitVector<C> {
+    pub fn grow(&mut self, num_bits: C) {
+        self.data.grow(num_bits)
+    }
+
+    pub fn new() -> BitVector<C> {
+        BitVector { data: BitArray::new(0) }
+    }
+
+    pub fn with_capacity(bits: usize) -> BitVector<C> {
+        BitVector { data: BitArray::new(bits) }
+    }
+
+    /// Returns true if the bit has changed.
+    #[inline]
+    pub fn insert(&mut self, bit: C) -> bool {
+        self.grow(bit);
+        self.data.insert(bit)
+    }
+
+    #[inline]
+    pub fn contains(&self, bit: C) -> bool {
+        let (word, mask) = word_mask(bit);
+        if let Some(word) = self.data.data.get(word) {
+            (word & mask) != 0
+        } else {
+            false
+        }
+    }
+}
+
 /// A "bit matrix" is basically a matrix of booleans represented as
 /// one gigantic bitvector. In other words, it is as if you have
 /// `rows` bitvectors, each of length `columns`.