-
Notifications
You must be signed in to change notification settings - Fork 51
retain method #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
retain method #36
Conversation
Implemented `retain` tests for empty map, retain all elements, retain none elements and retain arbitrary elements
I used an approach similar to the clone method. I just take the keys that do not pass the filtering function and remove each of them one by one. |
I think we probably do not want to construct a new map (with I would probably avoid the intermediate for (k, v) in self.iter() {
if !f(k, v) {
self.remove(k);
}
} It looks like hashbrown does something special about One thing to note is that the Java code does this: flurry/jsr166/src/ConcurrentHashMap.java Line 1630 in 0c3bfb6
That is, it uses the
|
@jonhoo I'm having issues implementing it that way: let n = unsafe { e.deref() }.as_node().unwrap();
let next = n.next.load(Ordering::SeqCst, guard);
if n.hash == h && n.key.borrow() == key {
let ev = n.value.load(Ordering::SeqCst, guard);
if new_value.is_none() || old_value.unwrap() == unsafe {ev.deref()} {
old_val = Some(ev);
// remove the BinEntry containing the removed key value pair from the bucket
if new_value.is_some() {
n.value.store(Owned::new(new_value.unwrap()), Ordering::SeqCst);
} else if !pred.is_null() {
// either by changing the pointer of the previous BinEntry, if present
// safety: as above
unsafe { pred.deref() }
.as_node()
.unwrap()
.next
.store(next, Ordering::SeqCst);
} else {
// or by setting the next node as the first BinEntry if there is no previous entry
t.store_bin(i, next);
}
// in either case, mark the BinEntry as garbage, since it was just removed
// safety: as for val below / in put
unsafe { guard.defer_destroy(e) };
// since the key was found and only one node exists per key, we can break here
break;
}
} Mostly here |
Ah, the trick there is to not take Also, keep in mind that if |
`remove` now wraps `replace_node` Added tests for `replace_node`
Moved `replace_node` tests into map module (private method) Implemented `retain_force` Added `retain_force` basic tests
I added |
# Conflicts: # tests/basic.rs
Excellent, thank you! |
Thank you for your patience!! |
Now let's see if this change passes the new miri and sanitizer CI tests :o |
Implemented
retain
for HashMapImplemented
retain
tests for empty map, retain all elements, retain none elements and retain arbitrary elements