字符串哈希算法参照.pdfVIP

  • 1
  • 0
  • 约7.43千字
  • 约 7页
  • 2021-12-01 发布于福建
  • 举报
经典字符串 Hash 函数 工作中经常需要用大 hash 这个强有力的工具, hash 表最核心的部分则在于怎么设 计一个好的 hash 函数 ,以使数据更均匀地分布在若干个桶上。 下面来介绍一下我现在用到 的一个 hash 函数 ,我们来看代码: unsigned chostcachehash::get_host_key(const string host) { int result = 1; unsigned i = 0; for (i = 0; i host.size(); i++) result = 31 * result + host[i]; return abs(result); } inline unsigned getkey(unsigned key) { return (key % m_capacity); } m_capacity 为 hash 桶的个数 对于一个 字符串 ,我们首先调用 get_host_key(

文档评论(0)

1亿VIP精品文档

相关文档