-
Notifications
You must be signed in to change notification settings - Fork 26
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
Avoid Clone
in FenwickTree
#104
base: master
Are you sure you want to change the base?
Avoid Clone
in FenwickTree
#104
Conversation
@@ -1,35 +1,37 @@ | |||
use std::iter::repeat_with; | |||
|
|||
use crate::num_traits::Zero; |
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.
- Implement
From<Vec<T>>
andFromIterator
forFenwickTree
#103 : ImplementFrom<Vec<T>>
andFromIterator
forFenwickTree
- Avoid
Clone
inFenwickTree
#104 : AvoidClone
inFenwickTree
These appear to be changes that need not specifically rely on #102. Check out the application examples below.
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 don't think requiring using Default
is not always a good idea because the semantics are different. Zero
traits is clearly for the "additive identity", while Default
trait is for a general "default" instance. The latter is not guaranteed to be an additive identity, and that restriction shall be stated in the doc instead of as a type restriction. I prefer type restrictions to other document constraints, and thus thought introducing Zero
trait would be reasonable.
Current implementation of FenwickTree clones the values to be added, but in principle, these operations can be done by just passing reference. I changed the trait bound so that it now requires reference values can be added, and removed the
Clone
bound.This PR depends on #102 (this dependency is not actually necessary, but when it comes to combining these two, it will require a certain amount of rollbacks, so I created a new branch from that branch.)