Implemention of HashTable(Part I)

来源:互联网 发布:淘宝卫浴店铺装修 编辑:程序博客网 时间:2024/04/27 19:05

 fellowing is some hash function:

 

/*
  Name: hash functions
  Copyright: All Right Reserved @ lizuding@gmail.com
  Author: lizuding
  Date: 21-01-08 21:46
  Description: implemention of hash function
*/

const unsigned long M=100;

/*
 * ELFHash 函数,由于UNIX的“可执行链接格式,ELF”
 * const char *key 关键字 
 
*/

  
int ELFHash(const char *key) {
    unsigned 
long h = 0;
    
    
while ( *key ) {
        h 
= (h << 4+ *key ++;
        unsigned 
long g = h & 0XF0000000L;
        
if ( g )
            h 
^= g >> 24;
        h 
&= -g;
    }

    
    
return h % M;
}



template
<class T>
int remainder_hash(int key) {
   
    
}

/*
 * 移位折叠法
 
*/
 
template
<class T>
int shift_pucker_hash(int key) {
    unsigned 
long tmp = 0;
    unsigned 
long filter = 0X00000033L
      
    
for (int i = 0; i < 16; i += 4{        
        filter 
<<= i;
        tmp 
+= key & filter;
    }

    
    
return tmp % M;    
}


template
<class T>
int divide_pucker_hash(int key) {}

template
<class T>
int square_media_hash(int key) {
    unsigned 
long hash = 0;
    hash 
= key * key;
    hash 
&= 0X0001FF00L;
    
return hash % 100;
}
 
原创粉丝点击