Skip to content

Commit

Permalink
Deprecate remove and remove_entry
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Aug 20, 2019
1 parent 12d1950 commit 0c24d10
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand Down Expand Up @@ -977,6 +979,7 @@ impl<K, V, S> IndexMap<K, V, S>
/// NOTE: Same as .swap_remove
///
/// Computes in **O(1)** time (average).
#[deprecated(note = "use `swap_remove`")]
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V>
where Q: Hash + Equivalent<K>,
{
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ impl<T, S> IndexSet<T, S>
/// FIXME Same as .swap_remove
///
/// Computes in **O(1)** time (average).
#[deprecated(note = "use `swap_remove`")]
pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool
where Q: Hash + Equivalent<T>,
{
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/equivalent_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
4 changes: 2 additions & 2 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -166,7 +166,7 @@ fn do_ops<K, V, S>(ops: &[Op<K, V>], a: &mut IndexMap<K, V, S>, 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()) {
Expand Down

0 comments on commit 0c24d10

Please sign in to comment.