Worse than fx (despite me hashing the station names there too) better than vanilla
This commit is contained in:
parent
07a8e7fc69
commit
aaa11c7b94
@ -1,3 +1,4 @@
|
|||||||
|
use crate::models::hasher::CustomBuildHasher;
|
||||||
use crate::models::station_measurements::StationMeasurements;
|
use crate::models::station_measurements::StationMeasurements;
|
||||||
use crate::utils::{hash, parse};
|
use crate::utils::{hash, parse};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -12,8 +13,9 @@ pub fn run() {
|
|||||||
const FILE_PATH: &str = "../../../measurements.txt";
|
const FILE_PATH: &str = "../../../measurements.txt";
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
thread::scope(|s| {
|
thread::scope(|s| {
|
||||||
let mut stations: HashMap<u64, (String, StationMeasurements)> =
|
let hasher = CustomBuildHasher::default();
|
||||||
HashMap::with_capacity(DEFAULT_HASHMAP_LENGTH);
|
let mut stations: HashMap<u64, (String, StationMeasurements), CustomBuildHasher> =
|
||||||
|
HashMap::with_capacity_and_hasher(DEFAULT_HASHMAP_LENGTH, hasher);
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
let cores = thread::available_parallelism().unwrap().into();
|
let cores = thread::available_parallelism().unwrap().into();
|
||||||
let file = File::open(FILE_PATH).expect("File measurements.txt not found");
|
let file = File::open(FILE_PATH).expect("File measurements.txt not found");
|
||||||
@ -44,8 +46,9 @@ pub fn run() {
|
|||||||
let file = File::open(FILE_PATH).expect("File measurements.txt not found");
|
let file = File::open(FILE_PATH).expect("File measurements.txt not found");
|
||||||
let mut reader = BufReader::new(&file);
|
let mut reader = BufReader::new(&file);
|
||||||
reader.seek(SeekFrom::Start(currposition)).unwrap();
|
reader.seek(SeekFrom::Start(currposition)).unwrap();
|
||||||
let mut t_stations: HashMap<u64, (String, StationMeasurements)> =
|
let hasher = CustomBuildHasher::default();
|
||||||
HashMap::with_capacity(DEFAULT_HASHMAP_LENGTH);
|
let mut t_stations: HashMap<u64, (String, StationMeasurements), CustomBuildHasher> =
|
||||||
|
HashMap::with_capacity_and_hasher(DEFAULT_HASHMAP_LENGTH, hasher);
|
||||||
let mut line = Vec::with_capacity(108);
|
let mut line = Vec::with_capacity(108);
|
||||||
loop {
|
loop {
|
||||||
let line_len = reader
|
let line_len = reader
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
pub mod mmap;
|
pub mod mmap;
|
||||||
pub mod station_measurements;
|
pub mod station_measurements;
|
||||||
|
pub mod hasher;
|
||||||
|
33
src/main/rust/src/models/hasher.rs
Normal file
33
src/main/rust/src/models/hasher.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
use std::hash::{BuildHasherDefault, Hasher};
|
||||||
|
use crate::utils::hash;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct CustomHasher(u64);
|
||||||
|
|
||||||
|
impl Default for CustomHasher {
|
||||||
|
#[inline]
|
||||||
|
fn default() -> Self {
|
||||||
|
CustomHasher(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CustomHasher {
|
||||||
|
#[inline]
|
||||||
|
pub fn with_key(key: u64) -> CustomHasher {
|
||||||
|
CustomHasher(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Hasher for CustomHasher {
|
||||||
|
#[inline]
|
||||||
|
fn finish(&self) -> u64 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn write(&mut self, bytes: &[u8]) {
|
||||||
|
*self = CustomHasher(hash::bytes(bytes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type CustomBuildHasher = BuildHasherDefault<CustomHasher>;
|
Loading…
Reference in New Issue
Block a user