Skip to content
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

ArrayQueue: is it possible to push and pop and the same time? #680

Closed
gootorov opened this issue Apr 6, 2021 · 1 comment · Fixed by #789
Closed

ArrayQueue: is it possible to push and pop and the same time? #680

gootorov opened this issue Apr 6, 2021 · 1 comment · Fixed by #789

Comments

@gootorov
Copy link

gootorov commented Apr 6, 2021

Essentially I'm looking for something like this:

use crossbeam_queue::ArrayQueue;

// allow a maximum of two elements.
let q = ArrayQueue::new(2);

assert_eq!(q.push_displacing(10), None);
assert_eq!(q.push_displacing(20), None);
assert_eq!(q.push_displacing(30), Some(10));

(not sure on the naming)

Is it possible to implement something like this in theory? (I guess it would require writing to two memory locations atomically at the same time, which there is no way to so, not sure)
If, however, it is possible, I'd be happy to open a PR given some hints how to properly implement it!

@brunocodutra
Copy link
Contributor

We could in fact change the RingQueue I propose in #789 to return the oldest element instead of dropping it in place. Seems like a great idea to me in fact, I'll look into that hopefully later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants