github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/structure/containers/containers.go (about) 1 package containers 2 3 import "github.com/songzhibin97/go-baseutils/base/bcomparator" 4 5 // Container is base interface that all data structures implement. 6 type Container[E any] interface { 7 Empty() bool 8 Size() int 9 Clear() 10 Values() []E 11 String() string 12 } 13 14 // GetSortedValues returns sorted container's elements with respect to the passed comparator. 15 // Does not affect the ordering of elements within the container. 16 func GetSortedValues[E any](container Container[E], comparator bcomparator.Comparator[E]) []E { 17 values := container.Values() 18 if len(values) < 2 { 19 return values 20 } 21 bcomparator.Sort(values, comparator) 22 return values 23 }