博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c哈希表hashtable操作
阅读量:6292 次
发布时间:2019-06-22

本文共 4129 字,大约阅读时间需要 13 分钟。

# # # "linkedlist.h"typedef struct {	int ;	 **;    int ;} ; *(int ); *( *);void ( *);void ( *);void ( *, const void *, int );const void *( *, int );void ( *, int );int ( *, int );int (const char *);#

 

-------------------------------------------

 

# "hashtable.h"# "linkedlist.h"# "logger.h"# <.># <.># # "dmalloc.h"#typedef struct {    int ;    const void *;} ;static  *(int , const void *); static void ( *);/* * FIXME: Needs to handle growing past initial capacity when table gets full. *        Note that it will be a slow operation because all table elements *        will have to be rehashed. * * FIXME: Currently uses chaining which isn't great.  Probably would be better *        to do double hashing or quadratic probing or something. If not,  *        it would be at least a good idea to maintain which elements get  *        accessed the most in any given chain and move them to the front. */ *(int ) {	 * = ;	    /*     * Allocate space for the object and set all fields to zero.     */ 	 = (1, sizeof());		if ( == ) {        return ;    }    /*     * Allocate space for the table elements      */    -> = (, sizeof( *));    if (-> == ) {        return ;    }    /*     * Initially set the capacity to the passed size      */    -> = ;    /*     * FIXME: Do something with this.  Make it a random number or something.     */    -> = 1;    /*     * Return the HashTable object     */	return ;}void ( *) {	    int  = 0;	if ( == ) {        return;    }		    /*     * Free all the chains     */    if (-> != ) {        for ( = 0;  < ->; ++) {             if (->[] != ) {                (->[]);                ->[] = ;            }        }        (->);        -> = ;    }	();} *( *) {    /*     * Fixme, write this function!     */     return ;}void ( *) {        /*     * Fixme, write this function!     */ }void ( *, const void *, int ) {     * = ;     * = ;    int  = -1;    if ( == ) {        return;    }    /*     * Find out which chain the element should be appended to.     */     = (, );    if ( == -1) {        return;    }    /*     * If there isn't a LinkedList object at the index     * already then put one there     */    if (->[] == ) {        ->[] = ();        if (->[] == ) {            return;        }    }    /*     * Create a HashTableElement object to hold the given data and hash code     */     = (, );    /*     * If the element could not be created then bail     */    if ( == ) {        return;    }    /*     * Create a linked list node with the given element     */     = ();    if ( == ) {        return;    }    /*     * Otherwise, add the node to the linked list     */    (->[], );}const void *( *, int ) {     * = ;     * = ;    const void * = ;    int  = -1;    if ( == ) {        return ;    }    /*     * Which chain does the desired element reside on?      */     = (, );    if ( == -1) {        return ;    }    if (->[] == ) {        return ;    }    /*     * Start at the beginning of the chain.     */    (->[]);    /*     * Traverse each node, and compare hash codes for a valid match     */    while(( = (->[])) != ) {         = ( *) ();        if ( == ->) {             = ->;            break;        }    }    if ( == ) {    }    return ;}int ( *, int ) {    if ( == ) {        return -1;    }        if ( < 0) {        return -1;    }    if (-> == 0) {        return -1;    }    /*     * Is their a better hashing function?     */    return (-> * ) % ->;}int (const char *) {    const char * = ;    int  = -1,  = 0;    if ( == ) {        return -1;    }    /*     * Generate a reversed (least significant character is most significant     * number) radix 128 evaluated polynomial of the input key     */    for ( = ; [0] != 0; ++, ++) {        int  = 0,  = 1;        for ( = 0;  < ; ++) {             += 128;        }         += ([0] * );            }    return ;}static  *(int ,                                                 const void *) {	     * = ;    /*     * Allocate space for the object and set all fields to zero.     */     = (1, sizeof());	if ( == ) {        return ;    }		    -> = ;    -> = ;	    return ;}static void ( *) {		if ( == ) {        return;    }	();}

 

转载地址:http://nycta.baihongyu.com/

你可能感兴趣的文章
网络通讯程序整理(一)
查看>>
[转载]一站式WPF--Window
查看>>
poj-1159 Palindrome **
查看>>
VS2010/VS 2013 删除空行
查看>>
解决linux ssh登陆缓慢问题
查看>>
将二叉查找树转化为链表的代码实现
查看>>
[转]宽字符的介绍
查看>>
UIScrollView用法
查看>>
SQL 判断两个时间段是否有交叉
查看>>
python打包_cx_freeze
查看>>
web.config/app.config敏感数据加/解密的二种方法
查看>>
PHP监控linux服务器负载
查看>>
delphi 入门教程
查看>>
技术人员,你拿什么拯救你的生活----温水煮青蛙
查看>>
最小排列数
查看>>
[C] zintrin.h: 智能引入intrinsic函数 V1.01版。改进对Mac OS X的支持,增加INTRIN_WORDSIZE宏...
查看>>
uva 101 The Blocks Problem
查看>>
Linux终端中设置vi编辑命令
查看>>
setup vaio winxp
查看>>
EBS FORM(10g)开发步骤
查看>>