mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-28 04:50:34 +00:00
Fix truncate logic (but it now becomes O(n))
This commit is contained in:
parent
b0cf29052c
commit
3041d3937e
@ -1245,7 +1245,7 @@ where
|
||||
///
|
||||
/// If `len` is greater than the map's current length, this has no effect.
|
||||
///
|
||||
/// Computes in *O*(1) time (average).
|
||||
/// Computes in *O*(n) time (average).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -1267,6 +1267,15 @@ where
|
||||
/// ```
|
||||
pub fn truncate(&mut self, len: usize) {
|
||||
self.core.entries.truncate(len);
|
||||
|
||||
if self.core.indices.len() > self.core.entries.len() {
|
||||
for index in self.core.indices.iter_mut() {
|
||||
match index {
|
||||
Some(pos) if pos.index() >= len => *index = None,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Private API */
|
||||
|
Loading…
x
Reference in New Issue
Block a user