-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from phelmkamp/sort
Sort
- Loading branch information
Showing
8 changed files
with
135 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Less reports whether the element with | ||
// index i should sort before the element with index j. | ||
func ({{.RcvName}} {{.RcvType}}) Less(i, j int) bool { | ||
return {{.RcvName}}.{{.FldName}}[i].String() < {{.RcvName}}.{{.FldName}}[j].String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Len is the number of elements in the collection. | ||
func ({{.RcvName}} {{.RcvType}}) Len() int { | ||
return len({{.RcvName}}.{{.FldName}}) | ||
} | ||
|
||
// Swap swaps the elements with indexes i and j. | ||
func ({{.RcvName}} {{.RcvType}}) Swap(i, j int) { | ||
{{.RcvName}}.{{.FldName}}[i], {{.RcvName}}.{{.FldName}}[j] = {{.RcvName}}.{{.FldName}}[j], {{.RcvName}}.{{.FldName}}[i] | ||
} | ||
|
||
// Sort is a convenience method. | ||
func ({{.RcvName}} {{.RcvType}}) Sort() { | ||
sort.Sort({{.RcvName}}) | ||
} |