通用哈希散列表C语言实现
此博客只有代码,hash表概念等,请自行学习。此次hash中使用链表为本人所写。后续改写此hash表,使用内核链表,详情请查看下一个博客。
代码块
common.h:
#pragma once
#ifndef _COMMON_H_
#define _COMMON_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
hash.h
#pragma once
#ifndef _HASH_H_
#define _HASH_H_
/*此方法采用的是连地址法*/
/*为了不将hash结构暴露在外面,所以就必须typedef*/
typedef struct hash hash_t;
//这是一个hash函数指针,对用户来说应该需要使用一个合适的hash函数
//第一个参数unsigned int指的是桶的大小 第二个参数是key值
typedef unsigned int(*hash_func_t)(unsigned int,void *);
/*返回的是hash表指针,创建hash表*/
hash_t *hash_alloc(unsigned int,hash_func_t);
void *hash_lookup_entry(hash_t *,void *,unsigned int );
void hash_add_entry(hash_t *, void *, unsigned int ,
void *, unsigned int );
void hash_free_entry(hash_t *,void *,int );
#endif /*_HASH_H_*/
hash.c
#include "hash.h"
#include "common.h"
//必须在前面声明typedef
typedef struct hash_node {


297

被折叠的 条评论
为什么被折叠?



