Share Ancestors API get with contains_key (#27161)

consolidate similar fns
This commit is contained in:
HaoranYi 2022-08-16 12:06:52 -05:00 committed by GitHub
parent 47ca68e51f
commit dbd2423e9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 7 deletions

View File

@ -65,10 +65,6 @@ impl Ancestors {
self.ancestors.get_all()
}
pub fn get(&self, slot: &Slot) -> bool {
self.ancestors.contains(slot)
}
pub fn remove(&mut self, slot: &Slot) {
self.ancestors.remove(slot);
}
@ -182,10 +178,10 @@ pub mod tests {
let key = item.0;
min = std::cmp::min(min, *key);
max = std::cmp::max(max, *key);
assert!(ancestors.get(key));
assert!(ancestors.contains_key(key));
}
for slot in min - 1..max + 2 {
assert_eq!(ancestors.get(&slot), hashset.contains(&slot));
assert_eq!(ancestors.contains_key(&slot), hashset.contains(&slot));
}
}

View File

@ -137,7 +137,7 @@ impl<T: Serialize + Clone> StatusCache<T> {
if let Some(stored_forks) = keymap.get(key_slice) {
let res = stored_forks
.iter()
.find(|(f, _)| ancestors.get(f) || self.roots.get(f).is_some())
.find(|(f, _)| ancestors.contains_key(f) || self.roots.get(f).is_some())
.cloned();
if res.is_some() {
return res;