Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
460ecfe8
Commit
460ecfe8
authored
Jan 11, 2020
by
AlexStocks
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/dubbogo/gost
parents
da528eb1
c46b1410
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
sort.go
sort/sort.go
+18
-0
sort_test.go
sort/sort_test.go
+12
-0
No files found.
sort/sort.go
View file @
460ecfe8
...
...
@@ -29,6 +29,10 @@ func Int32(slice []int32) {
sort
.
Sort
(
Int32Slice
(
slice
))
}
func
Uint32
(
slice
[]
uint32
)
{
sort
.
Sort
(
Uint32Slice
(
slice
))
}
type
Int64Slice
[]
int64
func
(
p
Int64Slice
)
Len
()
int
{
...
...
@@ -56,3 +60,17 @@ func (p Int32Slice) Less(i, j int) bool {
func
(
p
Int32Slice
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
]
}
type
Uint32Slice
[]
uint32
func
(
p
Uint32Slice
)
Len
()
int
{
return
len
(
p
)
}
func
(
p
Uint32Slice
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
<
p
[
j
]
}
func
(
p
Uint32Slice
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
]
}
sort/sort_test.go
View file @
460ecfe8
...
...
@@ -48,3 +48,15 @@ func TestSortInt64(t *testing.T) {
assert
.
Equal
(
t
,
int64
(
5
),
data
[
5
])
assert
.
Equal
(
t
,
int64
(
9
),
data
[
6
])
}
func
TestSortUint32
(
t
*
testing
.
T
)
{
data
:=
[]
uint32
{
3
,
5
,
1
,
9
,
0
,
2
,
2
}
Uint32
(
data
)
assert
.
Equal
(
t
,
uint32
(
0
),
data
[
0
])
assert
.
Equal
(
t
,
uint32
(
1
),
data
[
1
])
assert
.
Equal
(
t
,
uint32
(
2
),
data
[
2
])
assert
.
Equal
(
t
,
uint32
(
2
),
data
[
3
])
assert
.
Equal
(
t
,
uint32
(
3
),
data
[
4
])
assert
.
Equal
(
t
,
uint32
(
5
),
data
[
5
])
assert
.
Equal
(
t
,
uint32
(
9
),
data
[
6
])
}
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