Avoid Clone in FenwickTree - #104
Open
TonalidadeHidrica wants to merge 10 commits into
Open
TonalidadeHidrica wants to merge 10 commits into
TonalidadeHidrica wants to merge 10 commits into
Conversation
mizar
reviewed
Mar 27, 2023
| @@ -1,35 +1,37 @@ | |||
| use std::iter::repeat_with; | |||
|
|
|||
| use crate::num_traits::Zero; | |||
Collaborator
There was a problem hiding this comment.
- Implement
From<Vec<T>>andFromIteratorforFenwickTree#103 : ImplementFrom<Vec<T>>andFromIteratorforFenwickTree - Avoid
CloneinFenwickTree#104 : AvoidCloneinFenwickTree
These appear to be changes that need not specifically rely on #102. Check out the application examples below.
Collaborator
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Clonebound.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.)