sort.go 555 B

12345678910111213141516171819202122232425262728
  1. package semver
  2. import (
  3. "sort"
  4. )
  5. // Versions represents multiple versions.
  6. type Versions []Version
  7. // Len returns length of version collection
  8. func (s Versions) Len() int {
  9. return len(s)
  10. }
  11. // Swap swaps two versions inside the collection by its indices
  12. func (s Versions) Swap(i, j int) {
  13. s[i], s[j] = s[j], s[i]
  14. }
  15. // Less checks if version at index i is less than version at index j
  16. func (s Versions) Less(i, j int) bool {
  17. return s[i].LT(s[j])
  18. }
  19. // Sort sorts a slice of versions
  20. func Sort(versions []Version) {
  21. sort.Sort(Versions(versions))
  22. }