File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed 
src/data-structures/maps/hash-maps Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 11/* eslint-disable no-bitwise, no-iterator, no-restricted-syntax */ 
2+ const  {  TextEncoder }  =  require ( 'util' ) ; 
23const  LinkedList  =  require ( '../../linked-lists/linked-list' ) ; 
34const  {  nextPrime }  =  require ( './primes' ) ; 
45
@@ -55,14 +56,14 @@ class HashMap {
5556  hashFunction ( key )  { 
5657    const  bytes  =  encoding . encode ( key ) ; 
5758    const  {  length }  =  bytes ; 
58-      
59+ 
5960    let  hash  =  2166136261 ;  // FNV_offset_basis (32 bit) 
60-      
61-     for  ( let  i  =  0 ;  i  <  length ;  )  { 
62-       hash  ^=  bytes [ i ++ ] ;  // XOR 
61+ 
62+     for  ( let  i  =  0 ;  i  <  length ;  i ++ )  { 
63+       hash  ^=  bytes [ i ] ;  // XOR 
6364      hash  *=  16777619 ;  // 32 bit FNV_prime 
6465    } 
65-      
66+ 
6667    return  ( hash  >>>  0 )  %  this . buckets . length ; 
6768  } 
6869  // end::hashFunction[] 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments