Skip to content

Commit 3041d39

Browse files
committed
Fix truncate logic (but it now becomes O(n))
1 parent b0cf290 commit 3041d39

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/index_map.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ where
12451245
///
12461246
/// If `len` is greater than the map's current length, this has no effect.
12471247
///
1248-
/// Computes in *O*(1) time (average).
1248+
/// Computes in *O*(n) time (average).
12491249
///
12501250
/// # Examples
12511251
///
@@ -1267,6 +1267,15 @@ where
12671267
/// ```
12681268
pub fn truncate(&mut self, len: usize) {
12691269
self.core.entries.truncate(len);
1270+
1271+
if self.core.indices.len() > self.core.entries.len() {
1272+
for index in self.core.indices.iter_mut() {
1273+
match index {
1274+
Some(pos) if pos.index() >= len => *index = None,
1275+
_ => (),
1276+
}
1277+
}
1278+
}
12701279
}
12711280

12721281
/* Private API */

0 commit comments

Comments
 (0)