Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
1d284c20
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1d284c20
编写于
1月 03, 2019
作者:
J
Janoš Guljaš
提交者:
Viktor Trón
1月 03, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
swarm/storage: change Proximity function and add TestProximity test (#18379)
上级
b025053a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
186 addition
and
3 deletion
+186
-3
swarm/storage/types.go
swarm/storage/types.go
+0
-3
swarm/storage/types_test.go
swarm/storage/types_test.go
+186
-0
未找到文件。
swarm/storage/types.go
浏览文件 @
1d284c20
...
...
@@ -59,9 +59,6 @@ func Proximity(one, other []byte) (ret int) {
m
:=
8
for
i
:=
0
;
i
<
b
;
i
++
{
oxo
:=
one
[
i
]
^
other
[
i
]
if
i
==
b
-
1
{
m
=
MaxPO
%
8
}
for
j
:=
0
;
j
<
m
;
j
++
{
if
(
oxo
>>
uint8
(
7
-
j
))
&
0x01
!=
0
{
return
i
*
8
+
j
...
...
swarm/storage/types_test.go
0 → 100644
浏览文件 @
1d284c20
// Copyright 2018 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
storage
import
(
"strconv"
"testing"
)
// TestProximity validates Proximity function with explicit
// values in a table-driven test. It is highly dependant on
// MaxPO constant and it validates cases up to MaxPO=32.
func
TestProximity
(
t
*
testing
.
T
)
{
// integer from base2 encoded string
bx
:=
func
(
s
string
)
uint8
{
i
,
err
:=
strconv
.
ParseUint
(
s
,
2
,
8
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
uint8
(
i
)
}
// adjust expected bins in respect to MaxPO
limitPO
:=
func
(
po
uint8
)
uint8
{
if
po
>
MaxPO
{
return
MaxPO
}
return
po
}
base
:=
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)}
for
_
,
tc
:=
range
[]
struct
{
addr
[]
byte
po
uint8
}{
{
addr
:
base
,
po
:
MaxPO
,
},
{
addr
:
[]
byte
{
bx
(
"10000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
0
),
},
{
addr
:
[]
byte
{
bx
(
"01000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
1
),
},
{
addr
:
[]
byte
{
bx
(
"00100000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
2
),
},
{
addr
:
[]
byte
{
bx
(
"00010000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
3
),
},
{
addr
:
[]
byte
{
bx
(
"00001000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
4
),
},
{
addr
:
[]
byte
{
bx
(
"00000100"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
5
),
},
{
addr
:
[]
byte
{
bx
(
"00000010"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
6
),
},
{
addr
:
[]
byte
{
bx
(
"00000001"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
7
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"10000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
8
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"01000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
9
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00100000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
10
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00010000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
11
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00001000"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
12
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000100"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
13
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000010"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
14
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000001"
),
bx
(
"00000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
15
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"10000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
16
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"01000000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
17
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00100000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
18
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00010000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
19
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00001000"
),
bx
(
"00000000"
)},
po
:
limitPO
(
20
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000100"
),
bx
(
"00000000"
)},
po
:
limitPO
(
21
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000010"
),
bx
(
"00000000"
)},
po
:
limitPO
(
22
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000001"
),
bx
(
"00000000"
)},
po
:
limitPO
(
23
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"10000000"
)},
po
:
limitPO
(
24
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"01000000"
)},
po
:
limitPO
(
25
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00100000"
)},
po
:
limitPO
(
26
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00010000"
)},
po
:
limitPO
(
27
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00001000"
)},
po
:
limitPO
(
28
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000100"
)},
po
:
limitPO
(
29
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000010"
)},
po
:
limitPO
(
30
),
},
{
addr
:
[]
byte
{
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000000"
),
bx
(
"00000001"
)},
po
:
limitPO
(
31
),
},
}
{
got
:=
uint8
(
Proximity
(
base
,
tc
.
addr
))
if
got
!=
tc
.
po
{
t
.
Errorf
(
"got %v bin, want %v"
,
got
,
tc
.
po
)
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录