曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 4463|回复: 0
打印 上一主题 下一主题

gdbm hash 算法

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34397
跳转到指定楼层
楼主
发表于 2011-7-25 11:40:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
原来使用于 gdbm 数据库的源码中,下面代码片段来自 linux 内核代码中的 modpost 工具源码 modpost.c :
[C++] 纯文本查看 复制代码
#define SYMBOL_HASH_SIZE 1024

static struct symbol *symbolhash[SYMBOL_HASH_SIZE];
... ...
/* This is based on the hash agorithm from gdbm, via tdb */
static inline unsigned int tdb_hash(const char *name)
{
    unsigned value;    /* Used to compute the hash value.  */
    unsigned   i;    /* Used to cycle through random values. */

    /* Set the initial value from the key size. */
    for (value = 0x238F13AF * strlen(name), i = 0; name[i]; i++)
        value = (value + (((unsigned char *)name)[i] << (i*5 % 24)));

    return (1103515243 * value + 12345);
}

symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-6-17 18:51 , Processed in 0.082123 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表