Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

Commit

Permalink
{internal,search}: remove ByComponentLengthOrStart
Browse files Browse the repository at this point in the history
This sort order was a lazy solution to sorting [][]int, so remove it.
  • Loading branch information
kortschak committed May 2, 2015
1 parent 496c808 commit 0e33fa0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
10 changes: 2 additions & 8 deletions internal/sort.go
Expand Up @@ -4,14 +4,8 @@

package internal

type ByComponentLengthOrStart [][]int

func (c ByComponentLengthOrStart) Len() int { return len(c) }
func (c ByComponentLengthOrStart) Less(i, j int) bool {
return len(c[i]) < len(c[j]) || (len(c[i]) == len(c[j]) && c[i][0] < c[j][0])
}
func (c ByComponentLengthOrStart) Swap(i, j int) { c[i], c[j] = c[j], c[i] }

// BySliceValues implements the sort.Interface sorting a slice of
// []int lexically by the values of the []int.
type BySliceValues [][]int

func (c BySliceValues) Len() int { return len(c) }
Expand Down
7 changes: 4 additions & 3 deletions search/search_test.go
Expand Up @@ -361,7 +361,8 @@ var tarjanTests = []struct {
{0, 2},
},
want: [][]int{
{3, 4}, {0, 1, 2},
{0, 1, 2},
{3, 4},
},
},
}
Expand Down Expand Up @@ -390,8 +391,8 @@ func TestTarjanSCC(t *testing.T) {
sort.Ints(gotIDs[i])
}
for _, iv := range test.ambiguousOrder {
sort.Sort(internal.ByComponentLengthOrStart(test.want[iv.start:iv.end]))
sort.Sort(internal.ByComponentLengthOrStart(gotIDs[iv.start:iv.end]))
sort.Sort(internal.BySliceValues(test.want[iv.start:iv.end]))
sort.Sort(internal.BySliceValues(gotIDs[iv.start:iv.end]))
}
if !reflect.DeepEqual(gotIDs, test.want) {
t.Errorf("unexpected Tarjan scc result for %d:\n\tgot:%v\n\twant:%v", i, gotIDs, test.want)
Expand Down

0 comments on commit 0e33fa0

Please sign in to comment.