本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1KB

  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. // Package containers provides core interfaces and functions for data structures.
  5. //
  6. // Container is the base interface for all data structures to implement.
  7. //
  8. // Iterators provide stateful iterators.
  9. //
  10. // Enumerable provides Ruby inspired (each, select, map, find, any?, etc.) container functions.
  11. //
  12. // Serialization provides serializers (marshalers) and deserializers (unmarshalers).
  13. package containers
  14. import "github.com/emirpasic/gods/utils"
  15. // Container is base interface that all data structures implement.
  16. type Container interface {
  17. Empty() bool
  18. Size() int
  19. Clear()
  20. Values() []interface{}
  21. }
  22. // GetSortedValues returns sorted container's elements with respect to the passed comparator.
  23. // Does not effect the ordering of elements within the container.
  24. func GetSortedValues(container Container, comparator utils.Comparator) []interface{} {
  25. values := container.Values()
  26. if len(values) < 2 {
  27. return values
  28. }
  29. utils.Sort(values, comparator)
  30. return values
  31. }
上海开阖软件有限公司 沪ICP备12045867号-1