From: Ian Jackson Date: Wed, 24 Mar 2021 12:10:26 +0000 (+0000) Subject: vpid: Track how many pieces are in an occultation X-Git-Tag: otter-0.5.0~474 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=32dccdecc196daead913066db9f8f12db41fc460;p=otter.git vpid: Track how many pieces are in an occultation Signed-off-by: Ian Jackson --- diff --git a/src/vpid.rs b/src/vpid.rs index db335d75..eff21b3c 100644 --- a/src/vpid.rs +++ b/src/vpid.rs @@ -91,6 +91,7 @@ pub struct Notches { freelist: NotchPtr, table: IndexVec, zg: IndexVec, // last time notch was (re)filled + used: NotchNumber, } impl Occultation { @@ -111,7 +112,7 @@ impl Notches { /// correctness: piece must not already be in this `Notches` pub fn insert(&mut self, zg: Generation, piece: PieceId) -> Notch { let new = NR::Piece(piece); - match self.freelist.take() { + let notch = match self.freelist.take() { None => { let a = self.table.push(new); let b = self.zg.push(zg); @@ -125,7 +126,9 @@ impl Notches { self.zg[old_free_head] = zg; old_free_head }, - } + }; + self.used += 1; + notch } #[throws(IE)] @@ -147,6 +150,7 @@ impl Notches { // Now either *insert_here==NULL or notch < insert_here->next let old_next = mem::replace(insert_here, Some(notch)); self.table[notch] = NR::Free(old_next); + self.used -= 1; } } @@ -171,6 +175,10 @@ impl Notches { let pieces = self.table.iter() .filter_map(|nr| if let NR::Piece(p) = nr { Some(p) } else { None }) .collect::>(); + assert_eq!( + self.used as usize, + pieces.len(), + ); assert_eq!( count_free + pieces.len(), self.table.len(),