77//! Non-alpha-numeric characters are relegated to the end of the encoded value,
88//! rendering them indistinguishable from one another in this context.
99
10- use std:: collections:: HashMap ;
11-
12- // TODO: Use lazy cell instead of lazy static.
13- use lazy_static:: lazy_static;
10+ use std:: { collections:: HashMap , sync:: LazyLock } ;
1411
1512// The alphanumerical ordering.
1613const ALPHANUMERIC_ORDER : [ char ; 95 ] = [
@@ -23,16 +20,14 @@ const ALPHANUMERIC_ORDER: [char; 95] = [
2320
2421const PMF : f64 = 1.0 / ( ALPHANUMERIC_ORDER . len ( ) as f64 ) ;
2522
26- lazy_static ! {
27- static ref CDF : HashMap <char , f64 > = {
28- let length = ALPHANUMERIC_ORDER . len( ) + 1 ; // To account for non-alpha-numeric characters.
29- let mut cdf = HashMap :: with_capacity( length) ;
30- for ( index, & char ) in ALPHANUMERIC_ORDER . iter( ) . enumerate( ) {
31- cdf. insert( char , ( index as f64 ) / ( length as f64 ) ) ;
32- }
33- cdf
34- } ;
35- }
23+ static CDF : LazyLock < HashMap < char , f64 > > = LazyLock :: new ( || {
24+ let length = ALPHANUMERIC_ORDER . len ( ) + 1 ; // To account for non-alpha-numeric characters.
25+ let mut cdf = HashMap :: with_capacity ( length) ;
26+ for ( index, & char) in ALPHANUMERIC_ORDER . iter ( ) . enumerate ( ) {
27+ cdf. insert ( char, ( index as f64 ) / ( length as f64 ) ) ;
28+ }
29+ cdf
30+ } ) ;
3631
3732pub fn encode ( string : & str ) -> f64 {
3833 let mut left = 0.0 ;
0 commit comments