Browse Source

Add PushBytes to Heap

pull/1842/head
Jae Kwon 7 years ago
parent
commit
a0b692c86d
1 changed files with 11 additions and 0 deletions
  1. +11
    -0
      common/heap.go

+ 11
- 0
common/heap.go 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
}

Loading…
Cancel
Save