// sort
package util

import (
	"sort"
)

type DataStruct struct {
	Key, Name string
	Value     interface{}
	Index     int
}
type StructSort []*DataStruct

func (list StructSort) Len() int {
	return len(list)
}

func (list StructSort) Less(i, j int) bool {
	if list[i].Index < list[j].Index {
		return true
	} else if list[i].Index > list[j].Index {
		return false
	} else {
		return list[i].Key > list[j].Key
	}
}

func (list StructSort) Swap(i, j int) {
	var temp *DataStruct = list[i]
	list[i] = list[j]
	list[j] = temp
}

func ToSortData(list []*DataStruct) []*DataStruct {
	pList := StructSort(list)
	sort.Sort(pList)
	return pList
}
