-
Notifications
You must be signed in to change notification settings - Fork 15
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
Support custom key type #69
Support custom key type #69
Conversation
pub trait IntKey: Copy {
type Int: Int;
const PRIME: Self::Int;
fn into_int(self) -> Self::Int;
} |
Benchmarks before:
Benchmarks after:
I also added some new benchmarks for comparing different keys:
|
4a73a7b
to
9a070d1
Compare
I like this one the best so far. Adding direct support for ip addresses were a nice touch :) You have a few I'll wait a few days to let @414owen come with feedback, then I'll merge and create a new major release. Otherwise, great job and thank you for your patience. |
9a070d1
to
176deb7
Compare
:p
This does not work in all cases because the actual key is used afterwards. I renamed
Sounds good. If you don't mind, I'd also want to complete #56 and #70 before the next major release. What do you think about adding |
Sure, I don't mind waiting a bit.
Yeah, that might be useful if someone want to use 256 bit or 7 bit sized key for some reason. |
|
I made some changes:
|
Should I also increase the version number in this PR to indicate the breaking change? |
Co-authored-by: Damian Poddebniak <[email protected]>
This PR is an alternative to:
num-traits
crateThis PR is a combination of both PRs:
To achieve that two new traits are introduced. The first trait is a sealed trait for primitive integers:
It defines the properties of an integer. It's implemented for
u8
,u16
,u32
,u64
,u128
,usize
,i8
,i16
,i32
,i64
,i128
andisize
.The second trait is an open trait for user provided keys:
It defines how the key can be mapped to an integer. It's implemented for:
u8
,u16
,u32
,u64
,u128
,usize
,i8
,i16
,i32
,i64
,i128
andisize
std::num::NonZeroU8
,std::num::NonZeroU16
, ...I removed it because it's not supported by the current MSRVstd::num::Saturating
std::num::Wrapping
std::net::Ipv4Addr
std::net::Ipv6Addr
And it can be implemented by the user.
IntMap
has now a type parameterK
:Other changes worth mentioning:
u64
, see Not the largest prime? #68K
orV
, e.g.V: 'a
&u64
as key instead ofu64
because of type inference, I made it consistentCloses #61
Closes #68