Add fn replace_aliased(&self, usize, bool) -> bool to BitSlice<T, O>#284
Add fn replace_aliased(&self, usize, bool) -> bool to BitSlice<T, O>#284regexident wants to merge 2 commits intoferrilab:mainfrom
fn replace_aliased(&self, usize, bool) -> bool to BitSlice<T, O>#284Conversation
…iased_unchecked(…) -> bool` to `BitSlice<T, O>`
|
Just noticed this other PR that sort of aims to achieve the same: #273 |
pczarn
left a comment
There was a problem hiding this comment.
Okay. For consistency with standard Vec we would indeed go with replace_ since for Vec you would do mem::replace, or with swap_ since for atomics you would do fn swap.
| /// Replaces the value of a single bit, using alias-safe operations and | ||
| /// without bounds checking, returning the previous value. | ||
| /// | ||
| /// This is equivalent to [`.replace_unchecked()`], except that it does not |
There was a problem hiding this comment.
You link to fn replace_unchecked, but you do not link to fn replace_aliased. Please do that.
There was a problem hiding this comment.
Hi Peter, would you mind briefly elaborating on what you mean exactly, or providing a code suggestion? I couldn't find any equivalent cross linking from .replace_unchecked() to .replace() to follow suit.
There was a problem hiding this comment.
Vincent, you may update set_aliased_unchecked and replace_unchecked as well
There was a problem hiding this comment.
I've updated all unsafe _unchecked methods I could find, accordingly.
| /// Replaces the value of a single bit, using alias-safe operations and | ||
| /// without bounds checking, returning the previous value. | ||
| /// | ||
| /// This is equivalent to [`.replace_unchecked()`], except that it does not |
There was a problem hiding this comment.
Vincent, you may update set_aliased_unchecked and replace_unchecked as well

This PR adds the following methods to
BitSlice<T, O>:fn replace_aliased(&self, usize, bool) -> boolfn replace_aliased_unchecked(&self, usize, bool) -> boolThey are modeled after the existing
fn set_aliased()/fn set_aliased_unchecked()methods onBitSlice<T, O>.The motivation behind these methods is to be able to use
BitVec<AtomicUsize>for keeping track of "visited" nodes in a parallel graph traversal without the need of locking. As such you often need to atomically add a node to the "visited" set, while also find out if it had already been visited before (e.g. for avoiding performing redundant computations).