Пример #1
0
// Returns sorted container's elements using with respect to the passed comparator.
// Does not effect the ordering of elements within the container.
// Uses timsort.
func GetSortedValues(container Interface, comparator utils.Comparator) []interface{} {
	values := container.Values()
	if len(values) < 2 {
		return values
	}
	utils.Sort(values, comparator)
	return values
}
Пример #2
0
// Sorts values (in-place) using timsort.
func (list *List) Sort(comparator utils.Comparator) {
	list.mutex.Lock()
	defer list.mutex.Unlock()

	if len(list.elements) < 2 {
		return
	}
	utils.Sort(list.elements[:list.size], comparator)
}