高手帮忙看看小弟我写的哈希函数为什么不对,谢谢!
高手帮忙看看我写的哈希函数为什么不对,多谢!!!
#include <stdio.h>
#include <malloc.h>
#include <fatal.h>
#ifndef _HashSep_H_
#define MinTableSize 128129
typedef char *ElementType; //自定义Key数据类型
struct ListNode; //节点的结构体
typedef struct ListNode *Position; //指向节点的指针
typedef Position List; //指向头节点的指针
struct HashTbl; //哈希表的结构体
typedef struct HashTbl *HashTable;
HashTable InitializeTable(long TableSize); //基本函数声明
void DestroyTable(HashTable H);
Position Find(ElementType Key,HashTable H);
void Insert(ElementType Key,HashTable H);
ElementType Retrieve(Position P);
#endif
////////////////////////////////////////////具体的结构体定义
struct ListNode{
ElementType Element;
Position Next;
};
struct HashTbl{
long TableSize;
List *TheLists;
};
////////////////////////////////////////////////////////函数定义
long IndexHash(unsigned char *Key,long TableSize){
unsigned long HashVal;
HashVal=(*Key)*1000+*(Key+1);
return HashVal%TableSize;
}
HashTable InitializeTable(long TableSize){
HashTable H;
long i;
if(TableSize <MinTableSize){
Error( "TableSize is too small ");
return NULL;
}
H=malloc( sizeof( struct HashTbl) );
if( H==NULL )
FatalError( "out of space!!! ");
//H-> TableSize=NextPrime(TableSize); //求大于TableSize的最小素数
H-> TheLists=malloc( sizeof(List)*H-> TableSize );
if(H-> TheLists==NULL)
FatalError( "TheLists ");
for(i=0;i <H-> TableSize;i++){
H-> TheLists[i]=malloc( sizeof(struct ListNode) );
if(H-> TheLists[i]==NULL)
FatalError( "fuck ");
#include <stdio.h>
#include <malloc.h>
#include <fatal.h>
#ifndef _HashSep_H_
#define MinTableSize 128129
typedef char *ElementType; //自定义Key数据类型
struct ListNode; //节点的结构体
typedef struct ListNode *Position; //指向节点的指针
typedef Position List; //指向头节点的指针
struct HashTbl; //哈希表的结构体
typedef struct HashTbl *HashTable;
HashTable InitializeTable(long TableSize); //基本函数声明
void DestroyTable(HashTable H);
Position Find(ElementType Key,HashTable H);
void Insert(ElementType Key,HashTable H);
ElementType Retrieve(Position P);
#endif
////////////////////////////////////////////具体的结构体定义
struct ListNode{
ElementType Element;
Position Next;
};
struct HashTbl{
long TableSize;
List *TheLists;
};
////////////////////////////////////////////////////////函数定义
long IndexHash(unsigned char *Key,long TableSize){
unsigned long HashVal;
HashVal=(*Key)*1000+*(Key+1);
return HashVal%TableSize;
}
HashTable InitializeTable(long TableSize){
HashTable H;
long i;
if(TableSize <MinTableSize){
Error( "TableSize is too small ");
return NULL;
}
H=malloc( sizeof( struct HashTbl) );
if( H==NULL )
FatalError( "out of space!!! ");
//H-> TableSize=NextPrime(TableSize); //求大于TableSize的最小素数
H-> TheLists=malloc( sizeof(List)*H-> TableSize );
if(H-> TheLists==NULL)
FatalError( "TheLists ");
for(i=0;i <H-> TableSize;i++){
H-> TheLists[i]=malloc( sizeof(struct ListNode) );
if(H-> TheLists[i]==NULL)
FatalError( "fuck ");