数据结构 – 稀疏哈希表背后的主要实现思想是什么?

栏目: 数据库 · 发布时间: 7年前

内容简介:为什么Google sparsehash的开源库有两个实现:一个密集的哈希表和一个稀疏的代码日志版权声明:翻译自:http://stackoverflow.com/questions/5289241/what-is-the-main-implementation-idea-behind-sparse-hash-table

为什么Google sparsehash的开源库有两个实现:一个密集的哈希表和一个稀疏的

密集哈希表是您普通教科书的哈希表实现.

稀疏哈希表仅存储实际设置的元素,并分割数组.引用从 comments 执行稀疏表:

// The idea is that a table with (logically) t buckets is divided
// into t/M *groups* of M buckets each.  (M is a constant set in
// GROUP_SIZE for efficiency.)  Each group is stored sparsely.
// Thus, inserting into the table causes some array to grow, which is
// slow but still constant time.  Lookup involves doing a
// logical-position-to-sparse-position lookup, which is also slow but
// constant time.  The larger M is, the slower these operations are
// but the less overhead (slightly).

要知道数组的哪些元素被设置,一个稀疏表包括一个位图:

// To store the sparse array, we store a bitmap B, where B[i] = 1 iff
// bucket i is non-empty.  Then to look up bucket i we really look up
// array[# of 1s before i in B].  This is constant time for fixed M.

因此每个元素仅产生1位的开销(限制).

代码日志版权声明:

翻译自:http://stackoverflow.com/questions/5289241/what-is-the-main-implementation-idea-behind-sparse-hash-table


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web开发秘方

Web开发秘方

Brian P. Hogan、Chris Warren、Mike Weber、Chris Johnson、Aaron Godin / 七印部落 / 华中科技大学出版社 / 2013-7-10 / 66.00元

猜猜硅谷的前端工程师怎么折腾JS的?想知道无限下拉的列表怎么做吗?你知道DropBox可以当Web服务器用吗?你知道怎么做出跨平台的幻灯片效果吗?不借助插件,怎样在移动设备上实现动画效果?怎样快速搭建和测试HTML电子邮箱?怎样制作跨PC和移动设备显示的应用界面?怎样利用最新的JavaScript框架(Backbone和Knockout)提高应用的响应速度?怎样有效利用CoffeeScript和S......一起来看看 《Web开发秘方》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具