diff --git a/benches/bench.rs b/benches/bench.rs index 95fe8edd..206c44e0 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -583,7 +583,7 @@ fn remove_ordermap_100_000(b: &mut Bencher) { b.iter(|| { let mut map = map.clone(); for key in &keys { - map.remove(key); + map.swap_remove(key); } assert_eq!(map.len(), 0); map diff --git a/src/map.rs b/src/map.rs index d042bbe5..93ef505f 100644 --- a/src/map.rs +++ b/src/map.rs @@ -664,6 +664,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { replace(self.get_mut(), value) } + #[deprecated(note = "use `swap_remove`")] pub fn remove(self) -> V { self.swap_remove() } @@ -680,6 +681,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { } /// Remove and return the key, value pair stored in the map for this entry + #[deprecated(note = "use `swap_remove_entry`")] pub fn remove_entry(self) -> (K, V) { self.swap_remove_entry() } @@ -977,6 +979,7 @@ impl IndexMap /// NOTE: Same as .swap_remove /// /// Computes in **O(1)** time (average). + #[deprecated(note = "use `swap_remove`")] pub fn remove(&mut self, key: &Q) -> Option where Q: Hash + Equivalent, { @@ -2173,7 +2176,7 @@ mod tests { map_a.insert(2, "2"); let mut map_b = map_a.clone(); assert_eq!(map_a, map_b); - map_b.remove(&1); + map_b.swap_remove(&1); assert_ne!(map_a, map_b); let map_c: IndexMap<_, String> = map_b.into_iter().map(|(k, v)| (k, v.to_owned())).collect(); diff --git a/src/set.rs b/src/set.rs index f8912326..d4b541b8 100644 --- a/src/set.rs +++ b/src/set.rs @@ -309,6 +309,7 @@ impl IndexSet /// FIXME Same as .swap_remove /// /// Computes in **O(1)** time (average). + #[deprecated(note = "use `swap_remove`")] pub fn remove(&mut self, value: &Q) -> bool where Q: Hash + Equivalent, { @@ -1193,7 +1194,7 @@ mod tests { set_a.insert(2); let mut set_b = set_a.clone(); assert_eq!(set_a, set_b); - set_b.remove(&1); + set_b.swap_remove(&1); assert_ne!(set_a, set_b); let set_c: IndexSet<_> = set_b.into_iter().collect(); diff --git a/tests/equivalent_trait.rs b/tests/equivalent_trait.rs index 8b79e20a..2c5c73ee 100644 --- a/tests/equivalent_trait.rs +++ b/tests/equivalent_trait.rs @@ -51,5 +51,5 @@ fn test_string_str() { assert!(map.contains_key("a")); assert!(!map.contains_key("z")); - assert_eq!(map.remove("b"), Some(2)); + assert_eq!(map.swap_remove("b"), Some(2)); } diff --git a/tests/quick.rs b/tests/quick.rs index 0c6e8aa4..4045e4cc 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -116,7 +116,7 @@ quickcheck! { let mut clone = map.clone(); let drained = clone.drain(..); for (key, _) in drained { - map.remove(&key); + map.swap_remove(&key); } map.is_empty() } @@ -166,7 +166,7 @@ fn do_ops(ops: &[Op], a: &mut IndexMap, b: &mut HashMap< } RemoveEntry(ref k) => { match a.entry(k.clone()) { - OEntry::Occupied(ent) => { ent.remove_entry(); }, + OEntry::Occupied(ent) => { ent.swap_remove_entry(); }, _ => { } } match b.entry(k.clone()) {