Browse Source

Fix the `remove` method of `Seek`.

ticki 8 years ago
parent
commit
c1387b6327
2 changed files with 8 additions and 7 deletions
  1. 2 2
      src/bk/node.rs
  2. 6 5
      src/bk/seek.rs

+ 2 - 2
src/bk/node.rs

@@ -114,7 +114,7 @@ impl Node {
     }
 
     /// Calculate the fat value of a non bottom layer (i.e. level is greater than or equal to one).
-    pub fn calculate_fat_value_non_bottom(&self, lv: shotcut::Level) -> block::Size {
+    pub fn calculate_fat_value_non_bottom(&self, lv: lv::Level) -> block::Size {
         // Since `lv != 0` decrementing will not underflow.
         self.calculate_fat_value(lv, self.shortcuts[lv - 1].follow_shortcut(lv - 1))
     }
@@ -122,7 +122,7 @@ impl Node {
     /// Calculate the fat value of the lowest level.
     pub fn calculate_fat_value_bottom(&self) -> block::Size {
         // We base the new fat value of the lowest layer on the block list.
-        self.calculate_fat_value(Level(0), self.iter());
+        self.calculate_fat_value(lv::Level::min(), self.iter());
     }
 
     /// Check that this structure satisfy its invariants.

+ 6 - 5
src/bk/seek.rs

@@ -306,13 +306,14 @@ impl<'a> Seek<'a> {
         }
 
         // Update the fat values to reflect the new state.
-        for i in self.skips() {
-            if i.fat == self.node.size() {
+        // TODO: This can maybe be done without indexes.
+        for lv in lv::Iter::all() {
+            if self.lookback[lv].shortcuts[lv].fat == self.lookback[lv].block.size() {
                 // Recalculate the fat value.
-                let old_fat = i.fat;
-                i.fat = i.calculate_fat_value(b);
+                let old_fat = self.lookback[lv].shortcuts[lv].fat;
+                self.lookback[lv].shortcuts[lv].fat = i.calculate_fat_value_non_bottom(lv);
 
-                if old_fat == i.fat {
+                if old_fat == self.lookback[lv].fat {
                     // The fat value was unchanged (i.e. there are multiple fat nodes), so we
                     // shortcircuit, because these duplicates will exist in higher layers too (due
                     // to the heap property).