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
cdbdf6d4
Commit
cdbdf6d4
authored
Mar 26, 2020
by
Petar Maymounkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add intersection of key slices, for testing purposes.
parent
b1cd035c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
trie/intersect.go
trie/intersect.go
+19
-0
No files found.
trie/intersect.go
View file @
cdbdf6d4
...
...
@@ -4,6 +4,25 @@ import (
"github.com/libp2p/go-libp2p-xor/key"
)
func
IntersectKeySlices
(
p
,
q
[]
key
.
Key
)
[]
key
.
Key
{
hat
:=
[]
key
.
Key
{}
for
_
,
p
:=
range
p
{
if
keyIsIn
(
p
,
q
)
&&
!
keyIsIn
(
p
,
hat
)
{
hat
=
append
(
hat
,
p
)
}
}
return
hat
}
func
keyIsIn
(
q
key
.
Key
,
s
[]
key
.
Key
)
bool
{
for
_
,
s
:=
range
s
{
if
key
.
Equal
(
q
,
s
)
{
return
true
}
}
return
false
}
// Intersect computes the intersection of the keys in p and q.
// p and q must be non-nil. The returned trie is never nil.
func
Intersect
(
p
,
q
*
Trie
)
*
Trie
{
...
...
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