add working-set support

This commit is contained in:
Dustin J. Mitchell
2022-02-12 22:19:09 +00:00
parent ad560fdb79
commit 1488355b89
6 changed files with 233 additions and 4 deletions

View File

@@ -38,6 +38,11 @@ impl WorkingSet {
self.by_index.iter().filter(|e| e.is_some()).count()
}
/// Get the largest index in the working set, or zero if the set is empty.
pub fn largest_index(&self) -> usize {
self.by_index.len().saturating_sub(1)
}
/// True if the length is zero
pub fn is_empty(&self) -> bool {
self.by_index.iter().all(|e| e.is_none())
@@ -103,6 +108,21 @@ mod test {
assert_eq!(ws.is_empty(), true);
}
#[test]
fn test_largest_index() {
let (uuid1, uuid2, ws) = make();
assert_eq!(ws.largest_index(), 0);
let ws = WorkingSet::new(vec![None, Some(uuid1)]);
assert_eq!(ws.largest_index(), 1);
let ws = WorkingSet::new(vec![None, Some(uuid1), None, Some(uuid2)]);
assert_eq!(ws.largest_index(), 3);
let ws = WorkingSet::new(vec![None, Some(uuid1), None, Some(uuid2), None]);
assert_eq!(ws.largest_index(), 4);
}
#[test]
fn test_by_index() {
let (uuid1, uuid2, ws) = make();