main
1// Copyright (c) 2015, Emir Pasic. 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.
4
5// Package containers provides core interfaces and functions for data structures.
6//
7// Container is the base interface for all data structures to implement.
8//
9// Iterators provide stateful iterators.
10//
11// Enumerable provides Ruby inspired (each, select, map, find, any?, etc.) container functions.
12//
13// Serialization provides serializers (marshalers) and deserializers (unmarshalers).
14package containers
15
16import "github.com/emirpasic/gods/utils"
17
18// Container is base interface that all data structures implement.
19type Container interface {
20 Empty() bool
21 Size() int
22 Clear()
23 Values() []interface{}
24 String() string
25}
26
27// GetSortedValues returns sorted container's elements with respect to the passed comparator.
28// Does not affect the ordering of elements within the container.
29func GetSortedValues(container Container, comparator utils.Comparator) []interface{} {
30 values := container.Values()
31 if len(values) < 2 {
32 return values
33 }
34 utils.Sort(values, comparator)
35 return values
36}