11use crate :: database:: { Database , StringId } ;
22use crate :: extractors:: FeatureExtractor ;
3- use ahash:: { AHashMap , AHashSet } ;
43use lasso:: { Rodeo , Spur } ;
4+ use rustc_hash:: { FxHashMap , FxHashSet } ;
55use std:: fmt;
66use std:: sync:: { Arc , Mutex } ;
77
88pub struct HashDb {
99 feature_extractor : Arc < dyn FeatureExtractor > ,
1010 pub strings : Vec < String > ,
1111 string_features : Vec < Vec < Spur > > ,
12- feature_map : AHashMap < usize , AHashMap < Spur , AHashSet < StringId > > > ,
12+ feature_map : FxHashMap < usize , FxHashMap < Spur , FxHashSet < StringId > > > ,
1313 interner : Arc < Mutex < Rodeo > > ,
1414}
1515
@@ -37,7 +37,7 @@ impl HashDb {
3737 feature_extractor,
3838 strings : Vec :: new ( ) ,
3939 string_features : Vec :: new ( ) ,
40- feature_map : AHashMap :: default ( ) ,
40+ feature_map : FxHashMap :: default ( ) ,
4141 interner : Arc :: new ( Mutex :: new ( Rodeo :: default ( ) ) ) ,
4242 }
4343 }
@@ -75,7 +75,7 @@ impl Database for HashDb {
7575 self . interner . lock ( ) . unwrap ( ) . clear ( ) ;
7676 }
7777
78- fn lookup_strings ( & self , size : usize , feature : Spur ) -> Option < & AHashSet < StringId > > {
78+ fn lookup_strings ( & self , size : usize , feature : Spur ) -> Option < & FxHashSet < StringId > > {
7979 self . feature_map . get ( & size) ?. get ( & feature)
8080 }
8181
@@ -98,4 +98,8 @@ impl Database for HashDb {
9898 fn interner ( & self ) -> Arc < Mutex < Rodeo > > {
9999 Arc :: clone ( & self . interner )
100100 }
101+
102+ fn total_strings ( & self ) -> usize {
103+ self . strings . len ( )
104+ }
101105}
0 commit comments