I am supposed to build a dictionary Trie and use Nodes. I need to store them in a hashtable. I need to create a Hash Function to place the nodes in the correct location. How can i convert the String to an integer in the Hash Function?
            Asked
            
        
        
            Active
            
        
            Viewed 118 times
        
    -1
            
            
        - 
                    http://stackoverflow.com/questions/5585779/converting-string-to-int-in-java. You should search before you ask... – Bence Kaulics Nov 22 '14 at 21:18
- 
                    What's wrong with the hash function String already has? – Alan Stokes Nov 22 '14 at 22:33
2 Answers
0
            
            
        A common hash example, while not necessarily a good one, is to take sum of the ascii values of each character in the string, modulo the size of the hash table.
 
    
    
        user2008934
        
- 321
- 2
- 9
0
            
            
        You can try a kart-trie. It uses a clever key-alternating algorithm to hide a trie-data structure in a binary tree:http://code.dogmap.org/kart/.
The translated bit at position pos in a key k of length klen can be calculated as:
unsigned int bit(size_t pos, unsigned char const* k, size_t klen) {
   if (pos/(CHAR_BIT+1)>=klen) return 0;
   if (pos%(CHAR_BIT+1)==0) return 1;
   return (((unsigned int)k[pos/(CHAR_BIT+1)])>>(CHAR_BIT-pos%(CHAR_BIT+1)))&(unsigned int)1;
 } 
 
    
    
        Micromega
        
- 12,486
- 7
- 35
- 72
