Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
8d4791c9
提交
8d4791c9
authored
11月 17, 2016
作者:
Jeromy
提交者:
Jeromy
3月 21, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add more docs on hamt
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
上级
c8af993a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
27 行增加
和
0 行删除
+27
-0
hamt.go
unixfs/hamt/hamt.go
+25
-0
util.go
unixfs/hamt/util.go
+2
-0
没有找到文件。
unixfs/hamt/hamt.go
浏览文件 @
8d4791c9
// Package hamt implements a Hash Array Mapped Trie over ipfs merkledag nodes.
// It is implemented mostly as described in the wikipedia article on HAMTs,
// however the table size is variable (usually 256 in our usages) as opposed to
// 32 as suggested in the article. The hash function used is currently
// Murmur3, but this value is configurable (the datastructure reports which
// hash function its using).
//
// The one algorithmic change we implement that is not mentioned in the
// wikipedia article is the collapsing of empty shards.
// Given the following tree: ( '[' = shards, '{' = values )
// [ 'A' ] -> [ 'B' ] -> { "ABC" }
// | L-> { "ABD" }
// L-> { "ASDF" }
// If we simply removed "ABC", we would end up with a tree where shard 'B' only
// has a single child. This causes two issues, the first, is that now we have
// an extra lookup required to get to "ABD". The second issue is that now we
// have a tree that contains only "ABD", but is not the same tree that we would
// get by simply inserting "ABD" into a new tree. To address this, we always
// check for empty shard nodes upon deletion and prune them to maintain a
// consistent tree, independent of insertion order.
package
hamt
import
(
...
...
@@ -450,10 +470,15 @@ func (ds *HamtShard) modifyValue(ctx context.Context, hv *hashBits, key string,
}
}
// indexForBitPos returns the index within the collapsed array corresponding to
// the given bit in the bitset. The collapsed array contains only one entry
// per bit set in the bitfield, and this function is used to map the indices.
func
(
ds
*
HamtShard
)
indexForBitPos
(
bp
int
)
int
{
// TODO: an optimization could reuse the same 'mask' here and change the size
// as needed. This isnt yet done as the bitset package doesnt make it easy
// to do.
// make a bitmask (all bits set) 'bp' bits long
mask
:=
new
(
big
.
Int
)
.
Sub
(
new
(
big
.
Int
)
.
Exp
(
big
.
NewInt
(
2
),
big
.
NewInt
(
int64
(
bp
)),
nil
),
big
.
NewInt
(
1
))
mask
.
And
(
mask
,
ds
.
bitfield
)
...
...
unixfs/hamt/util.go
浏览文件 @
8d4791c9
...
...
@@ -4,6 +4,7 @@ import (
"math/big"
)
// hashBits is a helper that allows the reading of the 'next n bits' as an integer.
type
hashBits
struct
{
b
[]
byte
consumed
int
...
...
@@ -13,6 +14,7 @@ func mkmask(n int) byte {
return
(
1
<<
uint
(
n
))
-
1
}
// Next returns the next 'i' bits of the hashBits value as an integer
func
(
hb
*
hashBits
)
Next
(
i
int
)
int
{
curbi
:=
hb
.
consumed
/
8
leftb
:=
8
-
(
hb
.
consumed
%
8
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论