Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-xor
Commits
625914b4
Commit
625914b4
authored
Mar 27, 2020
by
Petar Maymounkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor efficiency optimization.
parent
ab48ec28
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
trie/check.go
trie/check.go
+11
-11
No files found.
trie/check.go
View file @
625914b4
...
...
@@ -54,22 +54,22 @@ func (p *triePath) RootPath() []byte {
func
(
p
*
triePath
)
matchesKey
(
k
key
.
Key
)
bool
{
// Slower, but more explicit:
for
i
,
b
:=
range
p
.
RootPath
()
{
if
k
.
BitAt
(
i
)
!=
b
{
return
false
}
}
return
true
//
ok, _ := p.
matchesKeyW
alk(k, 0)
//
return ok
//
for i, b := range p.RootPath() {
//
if k.BitAt(i) != b {
//
return false
//
}
//
}
//
return true
ok
,
_
:=
p
.
w
alk
(
k
,
0
)
return
ok
}
func
(
p
*
triePath
)
matchesKeyW
alk
(
k
key
.
Key
,
depthToLeaf
int
)
(
ok
bool
,
depthToRoot
int
)
{
func
(
p
*
triePath
)
w
alk
(
k
key
.
Key
,
depthToLeaf
int
)
(
ok
bool
,
depthToRoot
int
)
{
if
p
==
nil
{
return
true
,
0
}
else
{
parOk
,
parDepthToRoot
:=
p
.
parent
.
matchesKeyW
alk
(
k
,
depthToLeaf
+
1
)
return
k
.
BitAt
(
parDepthToRoot
+
1
)
==
p
.
bit
&&
parOk
,
parDepthToRoot
+
1
parOk
,
parDepthToRoot
:=
p
.
parent
.
w
alk
(
k
,
depthToLeaf
+
1
)
return
k
.
BitAt
(
parDepthToRoot
)
==
p
.
bit
&&
parOk
,
parDepthToRoot
+
1
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment