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
fe4f8ad2
Commit
fe4f8ad2
authored
Jan 20, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
expose O(1) len
parent
3c044d23
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
wantlist/wantlist.go
wantlist/wantlist.go
+13
-2
No files found.
wantlist/wantlist.go
View file @
fe4f8ad2
...
@@ -7,13 +7,14 @@ import (
...
@@ -7,13 +7,14 @@ import (
)
)
type
ThreadSafe
struct
{
type
ThreadSafe
struct
{
lk
sync
.
RWMutex
lk
sync
.
RWMutex
Wantlist
Wantlist
Wantlist
}
}
// not threadsafe
// not threadsafe
type
Wantlist
struct
{
type
Wantlist
struct
{
set
map
[
u
.
Key
]
Entry
set
map
[
u
.
Key
]
Entry
// TODO provide O(1) len accessor if cost becomes an issue
}
}
type
Entry
struct
{
type
Entry
struct
{
...
@@ -74,6 +75,16 @@ func (w *ThreadSafe) SortedEntries() []Entry {
...
@@ -74,6 +75,16 @@ func (w *ThreadSafe) SortedEntries() []Entry {
return
w
.
Wantlist
.
SortedEntries
()
return
w
.
Wantlist
.
SortedEntries
()
}
}
func
(
w
*
ThreadSafe
)
Len
()
int
{
w
.
lk
.
RLock
()
defer
w
.
lk
.
RUnlock
()
return
w
.
Wantlist
.
Len
()
}
func
(
w
*
Wantlist
)
Len
()
int
{
return
len
(
w
.
set
)
}
func
(
w
*
Wantlist
)
Add
(
k
u
.
Key
,
priority
int
)
{
func
(
w
*
Wantlist
)
Add
(
k
u
.
Key
,
priority
int
)
{
if
_
,
ok
:=
w
.
set
[
k
];
ok
{
if
_
,
ok
:=
w
.
set
[
k
];
ok
{
return
return
...
...
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