1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 func sortStable(s sort.Interface) {
14 pos: make([]int, s.Len()),
16 for i := range ss.pos {
22 type stableSort struct {
27 func (s *stableSort) Len() int {
31 func (s *stableSort) Less(i, j int) bool {
32 return s.s.Less(i, j) || !s.s.Less(j, i) && s.pos[i] < s.pos[j]
35 func (s *stableSort) Swap(i, j int) {
37 s.pos[i], s.pos[j] = s.pos[j], s.pos[i]