Add PushBytes to Heap

This commit is contained in:
Jae Kwon
2017-12-10 14:23:27 -08:00
parent 03dfb724c7
commit a0b692c86d

View File

@@ -1,6 +1,7 @@
package common
import (
"bytes"
"container/heap"
)
@@ -35,6 +36,10 @@ func (h *Heap) Push(value interface{}, priority int) {
heap.Push(&h.pq, &pqItem{value: value, priority: cmpInt(priority)})
}
func (h *Heap) PushBytes(value interface{}, priority []byte) {
heap.Push(&h.pq, &pqItem{value: value, priority: cmpBytes(priority)})
}
func (h *Heap) PushComparable(value interface{}, priority Comparable) {
heap.Push(&h.pq, &pqItem{value: value, priority: priority})
}
@@ -112,3 +117,9 @@ type cmpInt int
func (i cmpInt) Less(o interface{}) bool {
return int(i) < int(o.(cmpInt))
}
type cmpBytes []byte
func (bz cmpBytes) Less(o interface{}) bool {
return bytes.Compare([]byte(bz), []byte(o.(cmpBytes))) < 0
}