-
Notifications
You must be signed in to change notification settings - Fork 29
Add internal_queue #13
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
Add internal_queue #13
Conversation
Why we use |
src/internal_queue.rs
Outdated
|
||
impl<T> SimpleQueue<T> | ||
where | ||
T: Copy, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we want T
to be Copy
? It seems to me that passing T
itself instead of reference &T
in push
is more natural.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it was what the original code did. But yes, it's so unnatural and complicated to write in Rust, so I'll fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think removing Copy
is better in the normal Rust libraries, but considering this is a internal code and is only used in the implementation of the maxflow algorithm (only for integer and pair of integers), I also think we can restrict the level of abstraction. Original C++ implementation are not using move semantics, either. For more general purposes we should use VecDeque
in my opinion. At least it doesn't have enough interface to use with non-Copy
type, e.g. no way to get the ownership of the queued value back.
As an alternative, we can use T
directly instead of using references &T
if T: Copy
to make it more natural.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for late response....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. At least I changed &T
to T
in push
method. Also it seemed that removing T: Copy
does not do any harm, so I simply removed it for now.
I used |
I changed my mind and use |
But do we need to do this?
I added boundary check in |
No tests, no checks.