-
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
Open
TonalidadeHidrica
wants to merge
10
commits into
rust-lang-ja:master
Choose a base branch
from
TonalidadeHidrica:fenwick-add-by-ref
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0f0aa8b
Move Zero and One to public module
TonalidadeHidrica e919319
Use Zero trait in fenwick tree
TonalidadeHidrica ed246d1
FenwickTree no longer needs Clone; it adds refs
TonalidadeHidrica 692957b
Merge branch 'master' into fenwick-zero-trait
TonalidadeHidrica 5c23183
Merge branch 'fenwick-zero-trait' into fenwick-add-by-ref
TonalidadeHidrica 69c3cf2
expand: fenwicktree depends internal_type_traits
mizar 142bd16
Correct dependencies descibed in expand.py
TonalidadeHidrica e65a3fd
Merge branch 'fenwick-zero-trait' into fenwick-add-by-ref
TonalidadeHidrica 3d756db
Merge branch 'master' into fenwick-zero-trait
TonalidadeHidrica 21e8f6c
Merge branch 'fenwick-zero-trait' into fenwick-add-by-ref
TonalidadeHidrica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/// A type that has an additive identity element. | ||
pub trait Zero { | ||
/// The additive identity element. | ||
fn zero() -> Self; | ||
} | ||
|
||
/// A type that has a multiplicative identity element. | ||
pub trait One { | ||
/// The multiplicative identity element. | ||
fn one() -> Self; | ||
} | ||
|
||
macro_rules! impl_zero { | ||
($zero: literal, $one: literal: $($t: ty),*) => { | ||
$( | ||
impl Zero for $t { | ||
fn zero() -> Self { | ||
$zero | ||
} | ||
} | ||
|
||
impl One for $t { | ||
fn one() -> Self { | ||
$one | ||
} | ||
} | ||
)* | ||
}; | ||
} | ||
impl_zero!(0, 1: usize, u8, u16, u32, u64, u128); | ||
impl_zero!(0, 1: isize, i8, i16, i32, i64, i128); | ||
impl_zero!(0.0, 1.0: f32, f64); | ||
|
||
impl<T: Zero> Zero for core::num::Wrapping<T> { | ||
fn zero() -> Self { | ||
Self(T::zero()) | ||
} | ||
} | ||
impl<T: One> One for core::num::Wrapping<T> { | ||
fn one() -> Self { | ||
Self(T::one()) | ||
} | ||
} |
This file contains 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
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.
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.
From<Vec<T>>
andFromIterator
forFenwickTree
#103 : ImplementFrom<Vec<T>>
andFromIterator
forFenwickTree
Clone
inFenwickTree
#104 : AvoidClone
inFenwickTree
These appear to be changes that need not specifically rely on #102. Check out the application examples below.
https://github.com/rust-lang-ja/ac-library-rs/compare/7e99fd2941976764b4e7925898fae7cc77890885...mizar:ac-library-rs:4be604494341a86242b77120e5685740dc41791f?expand=1
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", whileDefault
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 introducingZero
trait would be reasonable.