// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package collate

import (
	
	
)

const (
	maxSortBuffer  = 40960
	maxSortEntries = 4096
)

type swapper interface {
	Swap(i, j int)
}

type sorter struct {
	buf  *Buffer
	keys [][]byte
	src  swapper
}

func ( *sorter) ( int) {
	if .buf == nil {
		.buf = &Buffer{}
		.buf.init()
	}
	if cap(.keys) <  {
		.keys = make([][]byte, )
	}
	.keys = .keys[0:]
}

func ( *sorter) ( swapper) {
	.src = 
	sort.Sort()
}

func ( sorter) () int {
	return len(.keys)
}

func ( sorter) (,  int) bool {
	return bytes.Compare(.keys[], .keys[]) == -1
}

func ( sorter) (,  int) {
	.keys[], .keys[] = .keys[], .keys[]
	.src.Swap(, )
}

// A Lister can be sorted by Collator's Sort method.
type Lister interface {
	Len() int
	Swap(i, j int)
	// Bytes returns the bytes of the text at index i.
	Bytes(i int) []byte
}

// Sort uses sort.Sort to sort the strings represented by x using the rules of c.
func ( *Collator) ( Lister) {
	 := .Len()
	.sorter.init()
	for  := 0;  < ; ++ {
		.sorter.keys[] = .Key(.sorter.buf, .Bytes())
	}
	.sorter.sort()
}

// SortStrings uses sort.Sort to sort the strings in x using the rules of c.
func ( *Collator) ( []string) {
	.sorter.init(len())
	for ,  := range  {
		.sorter.keys[] = .KeyFromString(.sorter.buf, )
	}
	.sorter.sort(sort.StringSlice())
}