gitee.com/quant1x/gox@v1.21.2/util/internal/containers.go (about)

     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).
    14  package internal
    15  
    16  // Container is base interface that all data structures implement.
    17  type Container interface {
    18  	Empty() bool
    19  	Size() int
    20  	Clear()
    21  	Values() []interface{}
    22  }
    23  
    24  // GetSortedValues returns sorted container's elements with respect to the passed comparator.
    25  // Does not effect the ordering of elements within the container.
    26  func GetSortedValues(container Container, comparator Comparator) []interface{} {
    27  	values := container.Values()
    28  	if len(values) < 2 {
    29  		return values
    30  	}
    31  	Sort(values, comparator)
    32  	return values
    33  }