aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/envoyproxy/go-control-plane/pkg/cache/v3/order.go
blob: c416946e82be4cb0e05e89eaec6ffc6ae16f0405 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package cache

// Key is an internal sorting data structure we can use to
// order responses by Type and their associated watch IDs.
type key struct {
	ID      int64
	TypeURL string
}

// Keys implements Go's sorting.Sort interface
type keys []key

func (k keys) Len() int {
	return len(k)
}

// Less compares the typeURL and determines what order things should be sent.
func (k keys) Less(i, j int) bool {
	return GetResponseType(k[i].TypeURL) < GetResponseType(k[j].TypeURL)
}

func (k keys) Swap(i, j int) {
	k[i], k[j] = k[j], k[i]
}