-
Notifications
You must be signed in to change notification settings - Fork 43
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
Use futures::executor::Spawn
with a Notify
impl.
#15
Conversation
Implement a custom `Notify` implementation which in turn notifies waiting tasks. This is similar to what rust-libp2p's mplex implementation does (see libp2p/rust-libp2p#455) for details.
I'm not a fan of having a custom Other than that, ideally there should be documentation in the |
Hashing Some benchmark results:
#![feature(test)]
use std::{self, hash::{BuildHasherDefault, Hasher}, marker::PhantomData};
pub type BuildIntHasher<T> = BuildHasherDefault<Stateless<T>>;
pub type IntMap<K, V> = std::collections::HashMap<K, V, BuildIntHasher<K>>;
#[derive(Copy, Clone, Debug, Default)]
pub struct Stateless<T>(u64, PhantomData<T>);
impl Hasher for Stateless<usize> {
fn finish(&self) -> u64 { self.0 }
fn write(&mut self, _: &[u8]) { unimplemented!() }
fn write_u8(&mut self, _: u8) {unimplemented!() }
fn write_u16(&mut self, _: u16) { unimplemented!() }
fn write_u32(&mut self, _: u32) { unimplemented!() }
fn write_u64(&mut self, _: u64) { unimplemented!() }
fn write_u128(&mut self, _: u128) { unimplemented!() }
fn write_usize(&mut self, n: usize) { self.0 = n as u64 }
fn write_i8(&mut self, _: i8) { unimplemented!() }
fn write_i16(&mut self, _: i16) { unimplemented!() }
fn write_i32(&mut self, _: i32) { unimplemented!() }
fn write_i64(&mut self, _: i64) { unimplemented!() }
fn write_i128(&mut self, _: i128) { unimplemented!() }
fn write_isize(&mut self, _: isize) { unimplemented!() }
}
#[cfg(test)]
mod tests {
extern crate test;
use fnv::FnvBuildHasher;
use self::test::Bencher;
use std::collections::HashMap;
const SIZE: usize = 1000;
#[bench]
fn bench_fnv(b: &mut Bencher) {
let mut m = HashMap::with_capacity_and_hasher(SIZE, FnvBuildHasher::default());
b.iter(|| {
for i in 0_usize .. SIZE {
m.insert(i, i);
}
})
}
#[bench]
fn bench_custom(b: &mut Bencher) {
let mut m = HashMap::with_capacity_and_hasher(SIZE, super::BuildIntHasher::default());
b.iter(|| {
for i in 0_usize .. SIZE {
m.insert(i, i);
}
})
}
} |
I would take the 3 nanoseconds loss 😌 |
@tomaka: This is ready for another review. |
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.
Let's fix the small nit and switch to the crates.io version of the hasher, and then merge.
src/notify.rs
Outdated
/// | ||
/// # Panics | ||
/// | ||
/// If called outside of a tokio task. |
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.
a futures
task, not a tokio task.
Implement a custom
Notify
implementation which in turn notifies waiting tasks. This is similar to what rust-libp2p's mplex implementation does (see libp2p/rust-libp2p#455) for details.