HashMap/README.md

89 lines
4.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#HashMap
###1.本库使用了C语言实现了一个基本的hashmap
包含的功能有如下几点:
/*********************************************************************
*入口参数: hashmap的无类型指针
*出口参数: 无
*返回值 : int 永远返回0可以不判断
*函数功能: 打印hashmap中所有的元素,主要用于调试和检查散列分布
*********************************************************************/
`int XipHashmapPrint( void * hashmap);`
/*********************************************************************
*入口参数: 无
*出口参数: 无
*返回值 : 创建的hashmap的指针,强制转换成了void *类型,方便调用
*函数功能: 以默认方式创建一个hashmap,默认的初始容量是16,加载因子是0.75f
**********************************************************************/
`void * XipHashmapNew();`
/*********************************************************************
*入口参数: int opacity 初始容量, float factor 加载因子
*出口参数: 无
*返回值 : 创建的hashmap的指针,强制转换成了void *类型,方便调用
*函数功能: 按照传入的信息进行初始hashmap创建,
*如果opacity为0,则为默认值16,如果factor为0,则默认为0.75f
*********************************************************************/
`void * XipHashmapInit( int opacity , float factor);`
/*********************************************************************
*入口参数: hashmap指针
*出口参数: 无
*返回值 : int , 永远返回0可以不判断
*函数功能: 按照传入的信息进行初始hashmap创建,
*如果opacity为0,则为默认值16,如果factor为0,则默认为0.75f
**********************************************************************/
`int XipHashmapDestory( void * in_map);`
/*********************************************************************
*入口参数: hashmap指针, char * key, void * value
*出口参数: 无
*返回值 : 返回 void * oldvalue 的指针,如果为新增则返回NULL
*如果put失败则返回XIP_HASHMAP_PUT_ERR
*函数功能: 根据key和value放入到hashmap中,如果map中已经存在该key的值
*则替换成最新的value,同时返回旧value指针
*如果put之后达到了临界值,则重新创建hashmap
*********************************************************************/
`void * XipHashmapPut( void * in_map, char * key, void * value);`
/*********************************************************************
*入口参数: hashmap指针, char * key
*出口参数: 无
*返回值 : 返回 void * value 的指针
*函数功能: 根据key值从hashmap中取得value的指针返回
*********************************************************************/
`void * XipHashmapGet( void * TxipHashmap, char * key);`
/*********************************************************************
*入口参数: hashmap指针, char * key
*出口参数: 无
*返回值 : int 返回值XIP_HASHMAP_EXIST_TURE(1), XIP_HASHMAP_EXIST_FALSE(0)
*函数功能: 根据key值从hashmap中查找是否存在,存在返回真,不存在返回假
*********************************************************************/
`int XipHashmapExists( void * TxipHashmap, char * key);`
/*********************************************************************
*入口参数: hashmap指针, char * key
*出口参数: 无
*返回值 : void * value
*函数功能: 根据key值从hashmap中删除key对应的node节点,如果删除成功,
*则返回删除节点的value的地址,未找到节点则返回NULL
*********************************************************************/
`void * XipHashmapRemove( void * TxipHashmap, char * key);`
###2.哈希算法
哈希算法使用了JAVA的JDK中默认的simple BKDR hash algorithm
有需要的也可以替换成暴雪的One-Way-Hash或者PHP中的time33之类的
###3.编译方法
我是在cygwin环境下编写的,linux下要改一下makefile中的cc -shared命令, unix类似,可以生成动态库
当然也可以直接把代码copy
test_hash.c可是执行mk来编译
###4.注意事项
使用的时候,调用程序请注意包含头文件hashmap.h来声明调用函数原型 否则可能会导致core dump