Skip to content

Commit 3db1a95

Browse files
committed
add/fix various comments to BitMatrix
Notably, the (hitherto unused) `less_than` method was not at all what it purported to be. It in fact computes the opposite.
1 parent de201b4 commit 3db1a95

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/librustc_data_structures/bitvec.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub struct BitMatrix {
145145
}
146146

147147
impl BitMatrix {
148-
// Create a new `rows x columns` matrix, initially empty.
148+
/// Create a new `rows x columns` matrix, initially empty.
149149
pub fn new(rows: usize, columns: usize) -> BitMatrix {
150150
// For every element, we need one bit for every other
151151
// element. Round up to an even number of u64s.
@@ -163,29 +163,33 @@ impl BitMatrix {
163163
(start, start + u64s_per_row)
164164
}
165165

166-
pub fn add(&mut self, source: usize, target: usize) -> bool {
167-
let (start, _) = self.range(source);
168-
let (word, mask) = word_mask(target);
166+
/// Sets the cell at `(row, column)` to true. Put another way, add
167+
/// `column` to the bitset for `row`.
168+
///
169+
/// Returns true if this changed the matrix, and false otherwies.
170+
pub fn add(&mut self, row: usize, column: usize) -> bool {
171+
let (start, _) = self.range(row);
172+
let (word, mask) = word_mask(column);
169173
let vector = &mut self.vector[..];
170174
let v1 = vector[start + word];
171175
let v2 = v1 | mask;
172176
vector[start + word] = v2;
173177
v1 != v2
174178
}
175179

176-
/// Do the bits from `source` contain `target`?
177-
///
178-
/// Put another way, if the matrix represents (transitive)
179-
/// reachability, can `source` reach `target`?
180-
pub fn contains(&self, source: usize, target: usize) -> bool {
181-
let (start, _) = self.range(source);
182-
let (word, mask) = word_mask(target);
180+
/// Do the bits from `row` contain `column`? Put another way, is
181+
/// the matrix cell at `(row, column)` true? Put yet another way,
182+
/// if the matrix represents (transitive) reachability, can
183+
/// `row` reach `column`?
184+
pub fn contains(&self, row: usize, column: usize) -> bool {
185+
let (start, _) = self.range(row);
186+
let (word, mask) = word_mask(column);
183187
(self.vector[start + word] & mask) != 0
184188
}
185189

186-
/// Returns those indices that are reachable from both `a` and
187-
/// `b`. This is an O(n) operation where `n` is the number of
188-
/// elements (somewhat independent from the actual size of the
190+
/// Returns those indices that are true in rows `a` and `b`. This
191+
/// is an O(n) operation where `n` is the number of elements
192+
/// (somewhat independent from the actual size of the
189193
/// intersection, in particular).
190194
pub fn intersection(&self, a: usize, b: usize) -> Vec<usize> {
191195
let (a_start, a_end) = self.range(a);
@@ -206,7 +210,7 @@ impl BitMatrix {
206210
result
207211
}
208212

209-
/// Add the bits from `read` to the bits from `write`,
213+
/// Add the bits from row `read` to the bits from row `write`,
210214
/// return true if anything changed.
211215
///
212216
/// This is used when computing transitive reachability because if
@@ -227,6 +231,8 @@ impl BitMatrix {
227231
changed
228232
}
229233

234+
/// Iterates through all the columns set to true in a given row of
235+
/// the matrix.
230236
pub fn iter<'a>(&'a self, row: usize) -> BitVectorIter<'a> {
231237
let (start, end) = self.range(row);
232238
BitVectorIter {

src/librustc_data_structures/transitive_relation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ impl<T: Clone + Debug + Eq + Hash + Clone> TransitiveRelation<T> {
134134
}
135135
}
136136

137-
/// Returns a vector of all things less than `a`.
137+
/// Returns a vector of all things greater than `a`.
138138
///
139139
/// Really this probably ought to be `impl Iterator<Item=&T>`, but
140140
/// I'm too lazy to make that work, and -- given the caching
141141
/// strategy -- it'd be a touch tricky anyhow.
142-
pub fn less_than(&self, a: &T) -> Vec<&T> {
142+
pub fn greater_than(&self, a: &T) -> Vec<&T> {
143143
match self.index(a) {
144144
Some(a) => self.with_closure(|closure| {
145145
closure.iter(a.0).map(|i| &self.elements[i]).collect()

0 commit comments

Comments
 (0)