Skip to content

Commit 755fcae

Browse files
committed
Reorder bitvec.rs.
So that the `BitArray` code is all together and before the `BitVector` code, instead of being awkwardly interleaved.
1 parent d6720cc commit 755fcae

File tree

1 file changed

+37
-40
lines changed

1 file changed

+37
-40
lines changed

src/librustc_data_structures/bitvec.rs

+37-40
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,6 @@ pub struct BitArray<C: Idx> {
2323
marker: PhantomData<C>,
2424
}
2525

26-
#[derive(Clone, Debug, PartialEq)]
27-
pub struct BitVector<C: Idx> {
28-
data: BitArray<C>,
29-
}
30-
31-
impl<C: Idx> BitVector<C> {
32-
pub fn grow(&mut self, num_bits: C) {
33-
self.data.grow(num_bits)
34-
}
35-
36-
pub fn new() -> BitVector<C> {
37-
BitVector {
38-
data: BitArray::new(0),
39-
}
40-
}
41-
42-
pub fn with_capacity(bits: usize) -> BitVector<C> {
43-
BitVector {
44-
data: BitArray::new(bits),
45-
}
46-
}
47-
48-
/// Returns true if the bit has changed.
49-
#[inline]
50-
pub fn insert(&mut self, bit: C) -> bool {
51-
self.grow(bit);
52-
self.data.insert(bit)
53-
}
54-
55-
#[inline]
56-
pub fn contains(&self, bit: C) -> bool {
57-
let (word, mask) = word_mask(bit);
58-
if let Some(word) = self.data.data.get(word) {
59-
(word & mask) != 0
60-
} else {
61-
false
62-
}
63-
}
64-
}
65-
6626
impl<C: Idx> BitArray<C> {
6727
// Do not make this method public, instead switch your use case to BitVector.
6828
#[inline]
@@ -206,6 +166,43 @@ impl<'a, C: Idx> Iterator for BitIter<'a, C> {
206166
}
207167
}
208168

169+
/// A resizable BitVector type.
170+
#[derive(Clone, Debug, PartialEq)]
171+
pub struct BitVector<C: Idx> {
172+
data: BitArray<C>,
173+
}
174+
175+
impl<C: Idx> BitVector<C> {
176+
pub fn grow(&mut self, num_bits: C) {
177+
self.data.grow(num_bits)
178+
}
179+
180+
pub fn new() -> BitVector<C> {
181+
BitVector { data: BitArray::new(0) }
182+
}
183+
184+
pub fn with_capacity(bits: usize) -> BitVector<C> {
185+
BitVector { data: BitArray::new(bits) }
186+
}
187+
188+
/// Returns true if the bit has changed.
189+
#[inline]
190+
pub fn insert(&mut self, bit: C) -> bool {
191+
self.grow(bit);
192+
self.data.insert(bit)
193+
}
194+
195+
#[inline]
196+
pub fn contains(&self, bit: C) -> bool {
197+
let (word, mask) = word_mask(bit);
198+
if let Some(word) = self.data.data.get(word) {
199+
(word & mask) != 0
200+
} else {
201+
false
202+
}
203+
}
204+
}
205+
209206
/// A "bit matrix" is basically a matrix of booleans represented as
210207
/// one gigantic bitvector. In other words, it is as if you have
211208
/// `rows` bitvectors, each of length `columns`.

0 commit comments

Comments
 (0)