Skip to content

Commit

Permalink
Deprecates remove and empty
Browse files Browse the repository at this point in the history
And renames them to `remove_value` and `remove_entry` for clarity.
  • Loading branch information
Mark Lodato committed Jul 7, 2020
1 parent 6cffdc0 commit c69088f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
16 changes: 16 additions & 0 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,30 @@ where
/// Remove the given value from the value-bag of the given key.
///
/// The updated value-bag will only be visible to readers after the next call to `refresh()`.
#[deprecated(since = "11.0.0", note = "Renamed to remove_value")]
pub fn remove(&mut self, k: K, v: V) -> &mut Self {
self.remove_value(k, v)
}

/// Remove the given value from the value-bag of the given key.
///
/// The updated value-bag will only be visible to readers after the next call to `refresh()`.
pub fn remove_value(&mut self, k: K, v: V) -> &mut Self {
self.add_op(Operation::Remove(k, v))
}

/// Remove the value-bag for the given key.
///
/// The value-bag will only disappear from readers after the next call to `refresh()`.
#[deprecated(since = "11.0.0", note = "Renamed to remove_entry")]
pub fn empty(&mut self, k: K) -> &mut Self {
self.remove_entry(k)
}

/// Remove the value-bag for the given key.
///
/// The value-bag will only disappear from readers after the next call to `refresh()`.
pub fn remove_entry(&mut self, k: K) -> &mut Self {
self.add_op(Operation::Empty(k))
}

Expand Down
30 changes: 15 additions & 15 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,14 @@ fn clear_vs_empty() {
w.clear(1);
w.refresh();
assert_eq!(r.get(&1).map(|rs| rs.len()), Some(0));
w.empty(1);
w.remove_entry(1);
w.refresh();
assert_eq!(r.get(&1).map(|rs| rs.len()), None);
// and again to test both apply_first and apply_second
w.clear(1);
w.refresh();
assert_eq!(r.get(&1).map(|rs| rs.len()), Some(0));
w.empty(1);
w.remove_entry(1);
w.refresh();
assert_eq!(r.get(&1).map(|rs| rs.len()), None);
}
Expand Down Expand Up @@ -391,7 +391,7 @@ fn absorb_negative_immediate() {
let (r, mut w) = evmap::new();
w.insert(1, "a");
w.insert(1, "b");
w.remove(1, "a");
w.remove_value(1, "a");
w.refresh();

assert_eq!(r.get(&1).map(|rs| rs.len()), Some(1));
Expand All @@ -404,7 +404,7 @@ fn absorb_negative_later() {
w.insert(1, "a");
w.insert(1, "b");
w.refresh();
w.remove(1, "a");
w.remove_value(1, "a");
w.refresh();

assert_eq!(r.get(&1).map(|rs| rs.len()), Some(1));
Expand All @@ -421,9 +421,9 @@ fn absorb_multi() {
assert!(r.get(&1).map(|rs| rs.iter().any(|r| r == &"a")).unwrap());
assert!(r.get(&1).map(|rs| rs.iter().any(|r| r == &"b")).unwrap());

w.remove(1, "a");
w.remove_value(1, "a");
w.insert(1, "c");
w.remove(1, "c");
w.remove_value(1, "c");
w.refresh();

assert_eq!(r.get(&1).map(|rs| rs.len()), Some(1));
Expand All @@ -436,7 +436,7 @@ fn empty() {
w.insert(1, "a");
w.insert(1, "b");
w.insert(2, "c");
w.empty(1);
w.remove_entry(1);
w.refresh();

assert_eq!(r.get(&1).map(|rs| rs.len()), None);
Expand Down Expand Up @@ -499,7 +499,7 @@ fn empty_post_refresh() {
w.insert(1, "b");
w.insert(2, "c");
w.refresh();
w.empty(1);
w.remove_entry(1);
w.refresh();

assert_eq!(r.get(&1).map(|rs| rs.len()), None);
Expand All @@ -525,7 +525,7 @@ fn clear() {
assert_eq!(r.get(&1).map(|rs| rs.len()), Some(0));
assert_eq!(r.get(&2).map(|rs| rs.len()), Some(0));

w.empty(1);
w.remove_entry(1);
w.refresh();

assert_eq!(r.get(&1).map(|rs| rs.len()), None);
Expand Down Expand Up @@ -668,12 +668,12 @@ fn bigbag() {
}
for i in (1..ndistinct).rev() {
for _ in 0..i {
w.remove(1, vec![i]);
w.remove_value(1, vec![i]);
w.fit(1);
w.refresh();
}
}
w.empty(1);
w.remove_entry(1);
}

drop(w);
Expand Down Expand Up @@ -750,14 +750,14 @@ fn get_one() {
}

#[test]
fn insert_remove() {
fn insert_remove_value() {
let x = 'x';

let (r, mut w) = evmap::new();

w.insert(x, x);

w.remove(x, x);
w.remove_value(x, x);
w.refresh();

// There are no more values associated with this key
Expand All @@ -770,14 +770,14 @@ fn insert_remove() {
}

#[test]
fn insert_empty() {
fn insert_remove_entry() {
let x = 'x';

let (r, mut w) = evmap::new();

w.insert(x, x);

w.empty(x);
w.remove_entry(x);
w.refresh();

assert!(r.is_empty());
Expand Down
6 changes: 3 additions & 3 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn insert_empty(insert: Vec<u8>, remove: Vec<u8>) -> bool {
}
w.refresh();
for &key in &remove {
w.empty(key);
w.remove_entry(key);
}
w.refresh();
let elements = &set(&insert) - &set(&remove);
Expand Down Expand Up @@ -110,11 +110,11 @@ fn do_ops<K, V, S>(
.push(v.clone());
}
Remove(ref k) => {
evmap.empty(k.clone());
evmap.remove_entry(k.clone());
write_ref.remove(k);
}
RemoveValue(ref k, ref v) => {
evmap.remove(k.clone(), v.clone());
evmap.remove_value(k.clone(), v.clone());
write_ref.get_mut(k).and_then(|values| {
values
.iter_mut()
Expand Down

0 comments on commit c69088f

Please sign in to comment.