File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
99
100
100
### Fixed
101
101
102
+ - Fixed bug in ` IndexMap::truncate ` that left the map in an inconsistent state.
102
103
- Fixed clippy lints.
103
104
- Fixed ` {arc,box,object}_pool! ` emitting clippy lints.
104
105
- Fixed the list of implemented data structures in the crate docs, by adding ` Deque ` ,
Original file line number Diff line number Diff line change @@ -1245,7 +1245,7 @@ where
1245
1245
///
1246
1246
/// If `len` is greater than the map's current length, this has no effect.
1247
1247
///
1248
- /// Computes in *O*(1 ) time (average).
1248
+ /// Computes in *O*(n ) time (average).
1249
1249
///
1250
1250
/// # Examples
1251
1251
///
@@ -1258,6 +1258,7 @@ where
1258
1258
/// map.insert(1, "c").unwrap();
1259
1259
/// map.truncate(2);
1260
1260
/// assert_eq!(map.len(), 2);
1261
+ /// assert_eq!(map.get(&1), None);
1261
1262
///
1262
1263
/// let mut iter = map.iter();
1263
1264
/// assert_eq!(iter.next(), Some((&3, &"a")));
@@ -1266,6 +1267,15 @@ where
1266
1267
/// ```
1267
1268
pub fn truncate ( & mut self , len : usize ) {
1268
1269
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
+ }
1269
1279
}
1270
1280
1271
1281
/* Private API */
You can’t perform that action at this time.
0 commit comments