2020-05-30 07:00:35 +00:00
|
|
|
package etl
|
2020-05-26 13:37:25 +00:00
|
|
|
|
|
|
|
import "bytes"
|
|
|
|
|
|
|
|
type HeapElem struct {
|
2020-05-31 06:57:47 +00:00
|
|
|
Key []byte
|
|
|
|
TimeIdx int
|
|
|
|
Value []byte
|
2020-05-26 13:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Heap []HeapElem
|
|
|
|
|
|
|
|
func (h Heap) Len() int {
|
|
|
|
return len(h)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h Heap) Less(i, j int) bool {
|
2020-05-31 06:57:47 +00:00
|
|
|
if c := bytes.Compare(h[i].Key, h[j].Key); c != 0 {
|
2020-05-26 13:37:25 +00:00
|
|
|
return c < 0
|
|
|
|
}
|
2020-05-31 06:57:47 +00:00
|
|
|
return h[i].TimeIdx < h[j].TimeIdx
|
2020-05-26 13:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h Heap) Swap(i, j int) {
|
|
|
|
h[i], h[j] = h[j], h[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Heap) Push(x interface{}) {
|
|
|
|
// Push and Pop use pointer receivers because they modify the slice's length,
|
|
|
|
// not just its contents.
|
|
|
|
*h = append(*h, x.(HeapElem))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Heap) Pop() interface{} {
|
|
|
|
old := *h
|
|
|
|
n := len(old)
|
|
|
|
x := old[n-1]
|
|
|
|
*h = old[0 : n-1]
|
|
|
|
return x
|
|
|
|
}
|