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
e92ee20e
Commit
e92ee20e
authored
Dec 10, 2014
by
Jeromy
Committed by
Juan Batiz-Benet
Dec 17, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create wantlist object
parent
b3f309a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
0 deletions
+56
-0
wantlist/wantlist.go
wantlist/wantlist.go
+56
-0
No files found.
wantlist/wantlist.go
0 → 100644
View file @
e92ee20e
package
wantlist
import
(
u
"github.com/jbenet/go-ipfs/util"
"sort"
)
type
Wantlist
struct
{
set
map
[
u
.
Key
]
*
Entry
}
func
NewWantlist
()
*
Wantlist
{
return
&
Wantlist
{
set
:
make
(
map
[
u
.
Key
]
*
Entry
),
}
}
type
Entry
struct
{
Value
u
.
Key
Priority
int
}
func
(
w
*
Wantlist
)
Add
(
k
u
.
Key
,
priority
int
)
{
if
_
,
ok
:=
w
.
set
[
k
];
ok
{
return
}
w
.
set
[
k
]
=
&
Entry
{
Value
:
k
,
Priority
:
priority
,
}
}
func
(
w
*
Wantlist
)
Remove
(
k
u
.
Key
)
{
delete
(
w
.
set
,
k
)
}
func
(
w
*
Wantlist
)
Contains
(
k
u
.
Key
)
bool
{
_
,
ok
:=
w
.
set
[
k
]
return
ok
}
type
entrySlice
[]
*
Entry
func
(
es
entrySlice
)
Len
()
int
{
return
len
(
es
)
}
func
(
es
entrySlice
)
Swap
(
i
,
j
int
)
{
es
[
i
],
es
[
j
]
=
es
[
j
],
es
[
i
]
}
func
(
es
entrySlice
)
Less
(
i
,
j
int
)
bool
{
return
es
[
i
]
.
Priority
<
es
[
j
]
.
Priority
}
func
(
w
*
Wantlist
)
Entries
()
[]
*
Entry
{
var
es
entrySlice
for
_
,
e
:=
range
w
.
set
{
es
=
append
(
es
,
e
)
}
sort
.
Sort
(
es
)
return
es
}
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