forked from cloudfoundry/noaa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort_recent.go
More file actions
30 lines (23 loc) · 744 Bytes
/
Copy pathsort_recent.go
File metadata and controls
30 lines (23 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package noaa
import (
"sort"
"github.com/cloudfoundry/sonde-go/events"
)
// SortRecent sorts a slice of LogMessages by timestamp. The sort is stable, so messages with the same timestamp are sorted
// in the order that they are received.
//
// The input slice is sorted; the return value is simply a pointer to the same slice.
func SortRecent(messages []*events.LogMessage) []*events.LogMessage {
sort.Stable(logMessageSlice(messages))
return messages
}
type logMessageSlice []*events.LogMessage
func (lms logMessageSlice) Len() int {
return len(lms)
}
func (lms logMessageSlice) Less(i, j int) bool {
return *(lms[i]).Timestamp < *(lms[j]).Timestamp
}
func (lms logMessageSlice) Swap(i, j int) {
lms[i], lms[j] = lms[j], lms[i]
}