共 6 篇文章
显示摘要每页显示  条
散列函数有很多,好的散列函数特点是:(近似的)满足简单一致散列,即对于关键字集合U中的任何一个关键字,经散列函数映射到地址集合中任何一个地址的概率是相等的,此时可以称为均匀散列函数,也就是说使关键字经过散列函数得到一个“随机的地址”,以便使一组关键字的散列地址均匀分布在整个地址区间,减少冲突。H=(H(key)+d) mod m 其中m表...
Hash(char**,T*,short);void add(char**,T*,short);Hash<T>::Hash(char **ps,T *pv,short nm)unsigned char *w;for(w=(unsigned char*)ps[nm],t=1;p=p->nxt)q->key=new char[(char*)w-ps[nm]+1];void Hash<T>::add(char *s, T v)for(w=(unsigned char*)s,t=1;q->key=new char[(char*)w-s+1];void Hash<T>::add(char...
np!np=np->next){ 32 if(!strcmp(np->name,n)) 33 return np;41 char *ns=(char*)malloc(l*sizeof(char));47 } 48 49 char* get(char* name){ 50 node* n=lookup(name);55 } 56 57 int install(char* name,char* desc){ 58 unsigned int hi;59 node* np;60 if((np=lookup(name))==NULL){ 61 hi=hash(name);66 if(np->name==NULL) re...
Pair *pairs;/* Create a key-value pair */ if (bucket->count == 0) { /* The bucket is empty, lazily allocate space for a single * key-value pair.*/ tmp_pairs = realloc(bucket->pairs, (bucket->count + 1) * sizeof(Pair));/* Get the last pair in the chain for the bucket */ pair = &(bucket->pairs[bucket->...
int GetHashTablePos(char *lpszString, MPQHASHTABLE *lpTable, int nTableSize){ const int HASH_OFFSET = 0, HASH_A = 1, HASH_B = 2;int nHash = HashString(lpszString, HASH_OFFSET),nHashA = HashString(lpszString, HASH_A),nHashB = HashString(lpszString, HASH_B), nHashStart = nHash % nTableSize,nHashPos = nHashStart;Compute...
图解数据结构(5)——散列法及哈希表。元素特征转变为数组下标的方法就是散列法。1,除法散列法最直观的一种,上图使用的就是这种散列法,公式:index = value % 16学过汇编的都知道,求模数其实是通过一个除法运算得到的,所以叫“除法散列法”。2,平方散列法求index是非常频繁的操作,而乘法的运算要比除法来得省时(对现在的CPU来说,估计...
帮助 | 留言交流 | 联系我们 | 服务条款 | 下载网文摘手 | 下载手机客户端
北京六智信息技术股份有限公司 Copyright© 2005-2024 360doc.com , All Rights Reserved
京ICP证090625号 京ICP备05038915号 京网文[2016]6433-853号 京公网安备11010502030377号
返回
顶部