Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Go
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Stiemerling
Go
Commits
185ae4f9
Commit
185ae4f9
authored
15 years ago
by
Rob Pike
Browse files
Options
Downloads
Patches
Plain Diff
add Sort methods for convenience types
R=gri DELTA=9 (9 added, 0 deleted, 0 changed) OCL=34000 CL=34003
parent
8b6274eb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pkg/sort/sort.go
+9
-0
9 additions, 0 deletions
src/pkg/sort/sort.go
with
9 additions
and
0 deletions
src/pkg/sort/sort.go
+
9
−
0
View file @
185ae4f9
...
@@ -152,6 +152,9 @@ func (p IntArray) Len() int { return len(p); }
...
@@ -152,6 +152,9 @@ func (p IntArray) Len() int { return len(p); }
func
(
p
IntArray
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
<
p
[
j
];
}
func
(
p
IntArray
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
<
p
[
j
];
}
func
(
p
IntArray
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
];
}
func
(
p
IntArray
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
];
}
// Sort is a convenience method.
func
(
p
IntArray
)
Sort
()
{
Sort
(
p
);
}
// FloatArray attaches the methods of SortInterface to []float, sorting in increasing order.
// FloatArray attaches the methods of SortInterface to []float, sorting in increasing order.
type
FloatArray
[]
float
type
FloatArray
[]
float
...
@@ -160,6 +163,9 @@ func (p FloatArray) Len() int { return len(p); }
...
@@ -160,6 +163,9 @@ func (p FloatArray) Len() int { return len(p); }
func
(
p
FloatArray
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
<
p
[
j
];
}
func
(
p
FloatArray
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
<
p
[
j
];
}
func
(
p
FloatArray
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
];
}
func
(
p
FloatArray
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
];
}
// Sort is a convenience method.
ffunc
(
p
FloatArray
)
Sort
()
{
Sort
(
p
);
}
// StringArray attaches the methods of SortInterface to []string, sorting in increasing order.
// StringArray attaches the methods of SortInterface to []string, sorting in increasing order.
type
StringArray
[]
string
type
StringArray
[]
string
...
@@ -168,6 +174,9 @@ func (p StringArray) Len() int { return len(p); }
...
@@ -168,6 +174,9 @@ func (p StringArray) Len() int { return len(p); }
func
(
p
StringArray
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
<
p
[
j
];
}
func
(
p
StringArray
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
<
p
[
j
];
}
func
(
p
StringArray
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
];
}
func
(
p
StringArray
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
];
}
// Sort is a convenience method.
ffunc
(
p
StringArray
)
Sort
()
{
Sort
(
p
);
}
// Convenience wrappers for common cases
// Convenience wrappers for common cases
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment