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-kad-dht
Commits
f1ba975b
Commit
f1ba975b
authored
Sep 17, 2014
by
Juan Batiz-Benet
Committed by
Brian Tiger Chow
Sep 22, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SortByDistance copy fix
parent
681a47eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
2 deletions
+12
-2
keyspace/keyspace.go
keyspace/keyspace.go
+3
-1
keyspace/xor_test.go
keyspace/xor_test.go
+9
-1
No files found.
keyspace/keyspace.go
View file @
f1ba975b
...
...
@@ -86,9 +86,11 @@ func (s byDistanceToCenter) Less(i, j int) bool {
// It returns a new list, where the Keys toSort have been sorted by their
// distance to the center Key.
func
SortByDistance
(
sp
KeySpace
,
center
Key
,
toSort
[]
Key
)
[]
Key
{
toSortCopy
:=
make
([]
Key
,
len
(
toSort
))
copy
(
toSortCopy
,
toSort
)
bdtc
:=
&
byDistanceToCenter
{
Center
:
center
,
Keys
:
toSort
[
:
]
,
// copy
Keys
:
toSort
Copy
,
// copy
}
sort
.
Sort
(
bdtc
)
return
bdtc
.
Keys
...
...
keyspace/xor_test.go
View file @
f1ba975b
...
...
@@ -97,7 +97,7 @@ func TestXorKeySpace(t *testing.T) {
}
}
func
TestCenterSorting
(
t
*
testing
.
T
)
{
func
Test
DistancesAnd
CenterSorting
(
t
*
testing
.
T
)
{
adjs
:=
[][]
byte
{
[]
byte
{
173
,
149
,
19
,
27
,
192
,
183
,
153
,
192
,
177
,
175
,
71
,
127
,
177
,
79
,
207
,
38
,
166
,
169
,
247
,
96
,
121
,
228
,
139
,
240
,
144
,
172
,
183
,
232
,
54
,
123
,
253
,
14
},
...
...
@@ -136,4 +136,12 @@ func TestCenterSorting(t *testing.T) {
t
.
Errorf
(
"2<<32 should be smaller"
)
}
keys2
:=
SortByDistance
(
XORKeySpace
,
keys
[
2
],
keys
)
order
:=
[]
int
{
2
,
3
,
4
,
5
,
1
,
0
}
for
i
,
o
:=
range
order
{
if
!
bytes
.
Equal
(
keys
[
o
]
.
Adjusted
,
keys2
[
i
]
.
Adjusted
)
{
t
.
Errorf
(
"order is wrong. %d?? %v == %v"
,
o
,
keys
[
o
],
keys2
[
i
])
}
}
}
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