mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-31 12:11:58 +00:00
Add PushBytes to Heap
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"container/heap"
|
"container/heap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,6 +36,10 @@ func (h *Heap) Push(value interface{}, priority int) {
|
|||||||
heap.Push(&h.pq, &pqItem{value: value, priority: cmpInt(priority)})
|
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) {
|
func (h *Heap) PushComparable(value interface{}, priority Comparable) {
|
||||||
heap.Push(&h.pq, &pqItem{value: value, priority: priority})
|
heap.Push(&h.pq, &pqItem{value: value, priority: priority})
|
||||||
}
|
}
|
||||||
@@ -112,3 +117,9 @@ type cmpInt int
|
|||||||
func (i cmpInt) Less(o interface{}) bool {
|
func (i cmpInt) Less(o interface{}) bool {
|
||||||
return int(i) < int(o.(cmpInt))
|
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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user