Port to using the newer graph, which offers iterators instead of the
older `each` method, but is otherwise identical.
This commit is contained in:
parent
52c3462586
commit
7ab0d1ab67
10 changed files with 321 additions and 245 deletions
32
src/librustc_data_structures/bitvec.rs
Normal file
32
src/librustc_data_structures/bitvec.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use std::iter;
|
||||
|
||||
/// A very simple BitVector type.
|
||||
pub struct BitVector {
|
||||
data: Vec<u64>
|
||||
}
|
||||
|
||||
impl BitVector {
|
||||
pub fn new(num_bits: usize) -> BitVector {
|
||||
let num_words = (num_bits + 63) / 64;
|
||||
BitVector { data: iter::repeat(0).take(num_words).collect() }
|
||||
}
|
||||
|
||||
fn word_mask(&self, bit: usize) -> (usize, u64) {
|
||||
let word = bit / 64;
|
||||
let mask = 1 << (bit % 64);
|
||||
(word, mask)
|
||||
}
|
||||
|
||||
pub fn contains(&self, bit: usize) -> bool {
|
||||
let (word, mask) = self.word_mask(bit);
|
||||
(self.data[word] & mask) != 0
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, bit: usize) -> bool {
|
||||
let (word, mask) = self.word_mask(bit);
|
||||
let data = &mut self.data[word];
|
||||
let value = *data;
|
||||
*data = value | mask;
|
||||
(value | mask) != value
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue