哈希表和哈希桶

哈希表简介:

      哈希表是通过关键值来访问的数据结构,也就是说他通过把关键值映射到表中的一个位置来访问记录,以加快 查找速度,这个映射关系就是哈希函数,存放数据的列表叫做散列表。

 

 

 

 

首先给出实现哈希表的头文件

#ifndef __HASHTABLE_H__
#define __HASHTABLE_H__

#include<stdio.h>
#include<assert.h>
#include<malloc.h>
#include<string.h>
#include"Common.h"


typedef int DataType;

typedef void (*explore)(int * ,int );


enum State//每个位置都有自己的状态
{
   EXIST,//存在的
   EMPTY,//可用的
   DELETE//被删除的
};

typedef struct KVP
{
  DataType value;//存储的值
  enum State state;//位置的状态
  int order;//顺序
  
}KVP;


typedef struct HashTable
{
   KVP *array;
   int  size;//有效容量
   int capacity;//容量
   int total;//已用容量(包括EXIST,DELETE)
   explore exp;//函数指针
}HashTable;

//初始化
void InitHashTable(HashTable* ph,explore exp,DataType capacity);

//哈希函数
int HashFunc(int capacity,DataType data);

//插入
void InsertHashTable(HashTable* ph,DataType data);

//打印
void Print(HashTable* ph);

//查找
int Find(HashTable* ph,DataType data);

//删除
void DeleteHashTable(HashTable* ph,DataType data);

//判空
int EmptyHashTable(HashTable* ph);

//有效元素个数
int SizeHashTable(HashTable* ph);

//线性探索
void linear(int* hashaddr,int capacity);

//二次探索
void doub(int* hashaddr,int capacity);



//字符哈希函数
static size_t BKDRHash(const char * str);

//交换数组指针
void swap(HashTable *NewHt,HashTable * ph);

//销毁哈希表
void DestroyHashTable (HashTable * ph);

//增容
void AddCapacity(HashTable *ph);






#endif  //__HASHTABLE_H__//每个位置都有自己的状态
{
   EXIST,
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值