Skip to content

Commit

Permalink
Hash keys directly using FxHash
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarGrootKoerkamp committed Jan 4, 2024
1 parent a1ebbbb commit 99e04a0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![feature(slice_split_once)]
use fxhash::FxHashMap;
use fxhash::{FxHashMap, FxHasher};
use memchr::arch::x86_64::avx2::memchr::One;
use std::{env::args, io::Read};
use std::{env::args, hash::Hasher, io::Read};

struct Record {
count: u32,
Expand Down Expand Up @@ -63,6 +63,11 @@ fn format(v: V) -> String {
format!("{:.1}", v as f64 / 10.0)
}

fn to_key_fx(name: &[u8]) -> u64 {
let mut h = FxHasher::default();
h.write(name);
h.finish()
}
fn to_key(name: &[u8]) -> u64 {
let mut key = [0u8; 8];
let l = name.len().min(8);
Expand Down Expand Up @@ -93,7 +98,7 @@ fn main() {
let end = newline.find(data.get_unchecked(separator..)).unwrap();
let name = data.get_unchecked(..separator);
let value = data.get_unchecked(separator + 1..separator + end);
h.entry(to_key(name))
h.entry(to_key_fx(name))
.or_insert((Record::default(), name))
.0
.add(parse(value));
Expand Down

0 comments on commit 99e04a0

Please sign in to comment.