feat: Improve performances by using a fnv Hasher

This commit is contained in:
Clément Renault
2018-08-23 21:32:31 +02:00
parent 0b02e31ce9
commit 0814418710
4 changed files with 12 additions and 3 deletions

View File

@ -5,6 +5,7 @@ authors = ["Kerollmops <renault.cle@gmail.com>"]
[dependencies]
byteorder = "1.2"
fnv = "1.0"
[dependencies.fst]
git = "https://github.com/Kerollmops/fst.git"

View File

@ -1,4 +1,5 @@
extern crate fst;
extern crate fnv;
extern crate group_by;
extern crate levenshtein_automata;
extern crate byteorder;

View File

@ -6,9 +6,9 @@ mod sum_of_words_position;
mod exact;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::{mem, vec};
use fst;
use fnv::FnvHashMap;
use levenshtein::Levenshtein;
use metadata::{DocIndexes, OpWithStateBuilder, UnionWithState};
use {Match, DocumentId};
@ -59,7 +59,7 @@ impl Pool {
}
// TODO remove the matches HashMap, not proud of it
pub fn extend(&mut self, matches: &mut HashMap<DocumentId, Vec<Match>>) {
pub fn extend(&mut self, matches: &mut FnvHashMap<DocumentId, Vec<Match>>) {
for doc in self.documents.iter_mut() {
if let Some(matches) = matches.remove(&doc.document_id) {
doc.matches.extend(matches);
@ -149,7 +149,7 @@ impl<'m, 'v, 'a> fst::Streamer<'a> for RankedStream<'m, 'v> {
type Item = Document;
fn next(&'a mut self) -> Option<Self::Item> {
let mut matches = HashMap::new();
let mut matches = FnvHashMap::default();
loop {
// TODO remove that when NLL are here !