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-cidutil
Commits
e23b8609
Commit
e23b8609
authored
Aug 31, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a utility method for sorting CID slices
fixes
https://github.com/ipfs/go-cid/issues/46
parent
6c3d0c5a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
slice.go
slice.go
+30
-0
No files found.
slice.go
0 → 100644
View file @
e23b8609
package
cidutil
import
(
"github.com/ipfs/go-cid"
"sort"
)
// Slice is a convenience type for sorting CIDs
type
Slice
[]
cid
.
Cid
func
(
s
Slice
)
Len
()
int
{
return
len
(
s
)
}
func
(
s
Slice
)
Less
(
i
,
j
int
)
bool
{
return
s
[
i
]
.
KeyString
()
<
s
[
j
]
.
KeyString
()
}
func
(
s
Slice
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
func
(
s
Slice
)
Sort
()
{
sort
.
Sort
(
s
)
}
// Sort sorts a slice of CIDs
func
Sort
(
s
[]
cid
.
Cid
)
{
Slice
(
s
)
.
Sort
()
}
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