Skip to content

Commit

Permalink
Rename HoleyVec::capacity to index_upper_bound
Browse files Browse the repository at this point in the history
  • Loading branch information
vsbogd committed Jan 25, 2024
1 parent feec8ca commit e399189
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/src/atom/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ impl Bindings {
}

let mut bindings = Bindings::new();
let mut prev_to_new = vec![usize::MAX; self.bindings.capacity()];
let mut prev_to_new = vec![usize::MAX; self.bindings.index_upper_bound()];
let mut copy_var = |var| {
match self.get_binding(var) {
None => {},
Expand Down Expand Up @@ -590,7 +590,7 @@ impl Bindings {
true => Some(self.clone()),
false => None
};
let mut renamed = bitset::BitSet::with_capacity(self.bindings.capacity());
let mut renamed = bitset::BitSet::with_capacity(self.bindings.index_upper_bound());
for var in preferred_vars {
match self.binding_by_var.get(&var) {
Some(&binding_id) => {
Expand Down Expand Up @@ -635,7 +635,7 @@ impl Bindings {

pub fn has_loops(&self) -> bool {
for binding in &self.bindings {
let mut used_bindings = bitset::BitSet::with_capacity(self.bindings.capacity());
let mut used_bindings = bitset::BitSet::with_capacity(self.bindings.index_upper_bound());
used_bindings.set(binding.id, true);
if self.binding_has_loops(&binding, &mut used_bindings) {
return true;
Expand Down Expand Up @@ -733,7 +733,7 @@ impl Bindings {
impl Display for Bindings {

fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut vars_by_binding_id = vec![HashSet::new(); self.bindings.capacity()];
let mut vars_by_binding_id = vec![HashSet::new(); self.bindings.index_upper_bound()];
for (var, &binding_id) in &self.binding_by_var {
if *var != self.bindings[binding_id].var {
vars_by_binding_id[binding_id].insert(var);
Expand Down
6 changes: 5 additions & 1 deletion lib/src/common/holeyvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ impl<T> HoleyVec<T> {
self.first_hole
}

pub fn capacity(&self) -> usize {
pub fn index_upper_bound(&self) -> usize {
self.vec.len()
}

pub fn capacity(&self) -> usize {
self.vec.capacity()
}

pub fn is_hole(&self, index: usize) -> bool {
match &self.vec[index] {
Cell::Value(_) => false,
Expand Down

0 comments on commit e399189

Please sign in to comment.