2016-06-27 02:21:09 +00:00
|
|
|
// Copyright (c) 2015, Emir Pasic. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
2015-03-07 18:23:43 +00:00
|
|
|
|
2016-06-25 16:17:48 +00:00
|
|
|
// Package containers provides core interfaces and functions for data structures.
|
2016-06-25 15:02:21 +00:00
|
|
|
//
|
|
|
|
// Container is the base interface for all data structures to implement.
|
|
|
|
//
|
|
|
|
// Iterators provide stateful iterators.
|
|
|
|
//
|
|
|
|
// Enumerable provides Ruby inspired (each, select, map, find, any?, etc.) container functions.
|
2017-03-06 00:05:01 +00:00
|
|
|
//
|
|
|
|
// Serialization provides serializers (marshalers) and deserializers (unmarshalers).
|
2015-03-07 18:23:43 +00:00
|
|
|
package containers
|
|
|
|
|
2015-03-08 02:13:26 +00:00
|
|
|
import "github.com/emirpasic/gods/utils"
|
|
|
|
|
2016-06-25 15:02:21 +00:00
|
|
|
// Container is base interface that all data structures implement.
|
2016-06-22 01:09:48 +00:00
|
|
|
type Container interface {
|
2015-03-07 18:23:43 +00:00
|
|
|
Empty() bool
|
|
|
|
Size() int
|
|
|
|
Clear()
|
|
|
|
Values() []interface{}
|
2022-04-12 17:30:54 +00:00
|
|
|
String() string
|
2015-03-07 18:23:43 +00:00
|
|
|
}
|
2015-03-08 02:13:26 +00:00
|
|
|
|
2016-06-24 19:52:16 +00:00
|
|
|
// GetSortedValues returns sorted container's elements with respect to the passed comparator.
|
2022-04-12 17:30:54 +00:00
|
|
|
// Does not affect the ordering of elements within the container.
|
2016-06-22 01:09:48 +00:00
|
|
|
func GetSortedValues(container Container, comparator utils.Comparator) []interface{} {
|
2015-03-08 02:13:26 +00:00
|
|
|
values := container.Values()
|
|
|
|
if len(values) < 2 {
|
|
|
|
return values
|
|
|
|
}
|
|
|
|
utils.Sort(values, comparator)
|
|
|
|
return values
|
|
|
|
}
|