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.

29 lines
809 B

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package util
  5. import "sort"
  6. // Int64Slice attaches the methods of Interface to []int64, sorting in increasing order.
  7. type Int64Slice []int64
  8. func (p Int64Slice) Len() int { return len(p) }
  9. func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] }
  10. func (p Int64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
  11. // IsSliceInt64Eq returns if the two slice has the same elements but different sequences.
  12. func IsSliceInt64Eq(a, b []int64) bool {
  13. if len(a) != len(b) {
  14. return false
  15. }
  16. sort.Sort(Int64Slice(a))
  17. sort.Sort(Int64Slice(b))
  18. for i := 0; i < len(a); i++ {
  19. if a[i] != b[i] {
  20. return false
  21. }
  22. }
  23. return true
  24. }