-
Notifications
You must be signed in to change notification settings - Fork 27
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
Implement From<Vec<T>>
and FromIterator
for FenwickTree
#103
Open
TonalidadeHidrica
wants to merge
10
commits into
rust-lang-ja:master
Choose a base branch
from
TonalidadeHidrica:fenwick-from
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 ca88474
Impl From<Vec> and FromIter for FenwickTree
TonalidadeHidrica 692957b
Merge branch 'master' into fenwick-zero-trait
TonalidadeHidrica 66a2d44
Merge branch 'fenwick-zero-trait' into fenwick-from
TonalidadeHidrica 69c3cf2
expand: fenwicktree depends internal_type_traits
mizar 142bd16
Correct dependencies descibed in expand.py
TonalidadeHidrica badd97d
Merge branch 'fenwick-zero-trait' into fenwick-from
TonalidadeHidrica 3d756db
Merge branch 'master' into fenwick-zero-trait
TonalidadeHidrica 786a334
Merge branch 'fenwick-zero-trait' into fenwick-from
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.
In the previous example, we used the Default trait, but now #55 makes it easier to use the Zero trait in user-defined structures as well, the need for the num crate may be lessened.
https://github.com/rust-lang-ja/ac-library-rs/compare/7e99fd2941976764b4e7925898fae7cc77890885...mizar:ac-library-rs:58bcfa92df9a75803b454771f8cb447a580a9cba?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.
If you rely on internal_type_traits::Zero traits, you will likely need to make this change to check for expand, FYI.
https://github.com/rust-lang-ja/ac-library-rs/compare/7e99fd2941976764b4e7925898fae7cc77890885...mizar:ac-library-rs:fd6bf7f453113c2b1ef5c7dd81c0955de2836cbd?expand=1