]> Cypherpunks repositories - gostls13.git/commitdiff
sort: fix Example_sortMultiKeys
authorAndriy Lytvynov <lytvynov.a.v@gmail.com>
Fri, 6 Sep 2013 20:49:34 +0000 (16:49 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 6 Sep 2013 20:49:34 +0000 (16:49 -0400)
Old example referenced global var from multiSorter.Sort and ignored it's argument.
Changed one of example calls to actually pass slice to sort.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/13551044

src/pkg/sort/example_multi_test.go

index d0a9e7dc3748cbe52f2b0412198638366d03a98c..b2ebc4c61011f992edade0e1eba174424ba9bb6f 100644 (file)
@@ -26,6 +26,7 @@ type multiSorter struct {
 
 // Sort sorts the argument slice according to the less functions passed to OrderedBy.
 func (ms *multiSorter) Sort(changes []Change) {
+       ms.changes = changes
        sort.Sort(ms)
 }
 
@@ -33,8 +34,7 @@ func (ms *multiSorter) Sort(changes []Change) {
 // Call its Sort method to sort the data.
 func OrderedBy(less ...lessFunc) *multiSorter {
        return &multiSorter{
-               changes: changes,
-               less:    less,
+               less: less,
        }
 }
 
@@ -108,11 +108,10 @@ func Example_sortMultiKeys() {
        OrderedBy(user).Sort(changes)
        fmt.Println("By user:", changes)
 
-       // multiSorter implements the Sort interface, so we can also do this.
-       sort.Sort(OrderedBy(user, increasingLines))
+       // More examples.
+       OrderedBy(user, increasingLines).Sort(changes)
        fmt.Println("By user,<lines:", changes)
 
-       // More examples.
        OrderedBy(user, decreasingLines).Sort(changes)
        fmt.Println("By user,>lines:", changes)