- 浏览: 72700 次
- 性别:
- 来自: 北京
hash.h
#include <stdio.h> #define HASHSIZE 101 struct nlist { struct nlist *next; char *name; char *defn; }; unsigned hash(char *s); struct nlist *lookup(char *s); struct nlist *install(char *name, char *defn);
hash.c
#include <string.h> #include "hash.h" static struct nlist *hashtab[HASHSIZE]; unsigned hash(char *s) { unsigned hashval; for (hashval = 0; *s != '\0'; s++) hashval = *s + 31 * hashval; return hashval % HASHSIZE; } struct nlist *lookup(char *s) { struct nlist *np; for (np = hashtab[hash(s)]; np != NULL; np = np->next) if (strcmp(s, np->name) == 0) return np; return NULL; } struct nlist *install(char *name, char *defn) { struct nlist *np; unsigned hashval; if ((np = lookup(name)) == NULL) { np = (struct nlist *)malloc(sizeof(struct nlist)); if (np == NULL || (np->name = strdup(name)) == NULL) return NULL; hashval = hash(name); np->next = hashtab[hashval]; hashtab[hashval] = np; } else free((void *)np->defn); if ((np->defn = strdup(defn)) == NULL) return NULL; return np; }
发表评论
-
排序算法---计数排序
2011-11-27 14:57 556#include <stdio.h> vo ... -
排序算法---归并排序
2011-11-26 19:33 697#include <stdio.h> vo ... -
排序算法---交换排序(冒泡排序、快速排序)
2011-11-26 19:32 665#include <stdio.h> vo ... -
排序算法---选择排序(简单插入排序、堆排序)
2011-11-26 19:31 598#include <stdio.h> vo ... -
排序算法---插入排序(简单排序、shell排序)
2011-11-26 19:29 600#include <stdio.h> vo ... -
删除字符串中的特定字符和重复字符
2011-11-26 13:45 630#include <stdio.h> vo ... -
Linux编程-多线程、同步和互斥(转载)
2011-11-14 15:27 1151http://www.cnblogs.com/skynet/a ... -
寻找字符串中的最大数字子串
2011-09-22 17:17 1471#include <stdio.h> int f ... -
删除子字符串
2011-09-21 15:27 562#include <stdio.h> #incl ... -
c语言随机数
2011-09-18 17:15 655#include <stdio.h> #i ... -
带头结点有序单链表的合并
2011-09-08 14:21 1143typedef int Item; typedef s ... -
链表逆序的递归/非递归算法
2011-09-01 23:37 1357/** *链表逆序的递归/非递归算法 */ # ... -
递归算法---字符串---全/部分组合和全排列
2011-08-30 23:01 1173#include <stdio.h> #i ... -
递归算法---0-1背包问题(面试宝典)
2011-08-28 21:11 1852/** *正整数n,m,从数列1、2、3、...、n中随 ... -
递归算法---字符串全组合(面试宝典)
2011-08-28 17:24 1210/** *求一字符串所有字串的组合 */ #i ... -
递归算法---求解多元一次方程
2011-08-28 10:38 1860/** * 求解x1+x2+x3+...+x10 = ... -
(zz)关于类的sizeof
2011-08-27 18:16 524http://blog.sina.com.cn/s/blog_ ... -
(zz)结构体字节对齐原则
2011-08-27 17:53 1548结构体默认的字节对齐一般满足三个准则: 结构体变量的首 ... -
list.h from linux-2.4
2011-08-25 09:59 569#ifndef _LIST_H_ #define _L ... -
Josephus环
2011-08-23 11:20 660/*************************** ...
相关推荐
Build working implementations of hash tables, written in the C programming language. This book starts with simple first attempts devoid of collision resolution strategies, and moves through ...
c语言hash table的实现:经典代码段
For the misspelled word "acr", replacing the "c" with an "i" yields "air", replacing the "r" with an "e" yields "ace", and so on. • Inserting any letter at any position in a word The program ...
VC 编程哈希表创建设计模块代码VC design module programming code to create the hash table
FPGAs based hash table
Sorting Hash Table Increase Sorting Searching Elementd in hash table BSTree
The Joys of Hashing,Hash Table Programming with C,2019年新书,哈希编程的乐趣,基于C语言实现Hash表。
. In hash table, to complete the code for Insert_Hash, HashSearch and OverHandle funtions to finish employee’s information search.
方便地查看文件的MD5/SHA1值 – HashTab给文件属性窗口添加校验值!
代码重点是hash_table,附加std::map与其做对比,实现的是一条sql语句:select c_nationkey, c_mktsegment, count(*), max(c_acctbal) from aaa_customer_1g group by c_nationkey, c_mktsegment order by c_...
无线安全破解专用WPA-PSK_Hash_Table_DVD下载地址汇总.
Hash programming in SAS. to show you how hash objects in SAS DATA steps can be used to lookup data, combine data, and organize data. After reading the discussions and trying the examples, you should ...
C语言实现hash算法源码,实现了sha256,sha384,sha512三种哈希算法,项目中用到的,提取出来测试使用的。
this is a hash table using hash function
C语言实现的Hash表(代码)。C语言实现的Hash表(代码)。C语言实现的Hash表(代码)。C语言实现的Hash表(代码)。
做工程需要 hash table,而 VC6 没有提供,GLIB中的hash table 简单易用,于是拆出来用。
HASH ID FOR CHEAT TABLE
现行哈希的C++实现代码,具体原理可以参考:Larson, Per-Ake (April 1988),"Dynamic Hash Tables",Communications of the ACM 31: 446–457, doi:10.1145/42404.42410.
(1) 建立一个哈希表,哈希函数为除留余数法,处理冲突的方法为线性探测再散列或二次探测再散列。 (2) 往哈希表中依次存入插入多个单词。 (3) 显示哈希表的存储情况。 (4) 计算哈希表的平均查找长度。...
Hash join算法的一个基本思想就是根据小的row sources(称作build input,我们记较小的表为S,较大的表为B) 建立一个可以存在于hash area内存中的hash table,然后用大的row sources(称作probe input) 来探测前面所建...