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
dms3
go-bitswap
Commits
61972176
Commit
61972176
authored
Aug 23, 2019
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: cheaper rand want selection
parent
ec9fb77f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
3 deletions
+2
-3
session/sessionwants.go
session/sessionwants.go
+2
-3
No files found.
session/sessionwants.go
View file @
61972176
package
session
import
(
"math"
"math/rand"
"sync"
"time"
...
...
@@ -134,7 +133,7 @@ func (sw *sessionWants) LiveWants() []cid.Cid {
// RandomLiveWant returns a randomly selected live want
func
(
sw
*
sessionWants
)
RandomLiveWant
()
cid
.
Cid
{
r
:=
rand
.
Floa
t64
()
i
:=
rand
.
Uin
t64
()
sw
.
RLock
()
defer
sw
.
RUnlock
()
...
...
@@ -142,7 +141,7 @@ func (sw *sessionWants) RandomLiveWant() cid.Cid {
if
len
(
sw
.
liveWants
)
==
0
{
return
cid
.
Cid
{}
}
i
:
=
math
.
Floor
(
r
*
floa
t64
(
len
(
sw
.
liveWants
))
)
i
%
=
uin
t64
(
len
(
sw
.
liveWants
))
// picking a random live want
for
k
:=
range
sw
.
liveWants
{
if
i
==
0
{
...
...
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