mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-02 16:11:21 +00:00
Add KI64Pair(s)
This commit is contained in:
parent
b70ae4919b
commit
f2a8e95248
@ -5,6 +5,9 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
// KVPair
|
||||||
|
|
||||||
type KVPair struct {
|
type KVPair struct {
|
||||||
Key Bytes
|
Key Bytes
|
||||||
Value Bytes
|
Value Bytes
|
||||||
@ -28,3 +31,30 @@ func (kvs KVPairs) Less(i, j int) bool {
|
|||||||
}
|
}
|
||||||
func (kvs KVPairs) Swap(i, j int) { kvs[i], kvs[j] = kvs[j], kvs[i] }
|
func (kvs KVPairs) Swap(i, j int) { kvs[i], kvs[j] = kvs[j], kvs[i] }
|
||||||
func (kvs KVPairs) Sort() { sort.Sort(kvs) }
|
func (kvs KVPairs) Sort() { sort.Sort(kvs) }
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
// KI64Pair
|
||||||
|
|
||||||
|
type KI64Pair struct {
|
||||||
|
Key Bytes
|
||||||
|
Value int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type KI64Pairs []KI64Pair
|
||||||
|
|
||||||
|
// Sorting
|
||||||
|
func (kvs KI64Pairs) Len() int { return len(kvs) }
|
||||||
|
func (kvs KI64Pairs) Less(i, j int) bool {
|
||||||
|
switch bytes.Compare(kvs[i].Key, kvs[j].Key) {
|
||||||
|
case -1:
|
||||||
|
return true
|
||||||
|
case 0:
|
||||||
|
return kvs[i].Value < kvs[j].Value
|
||||||
|
case 1:
|
||||||
|
return false
|
||||||
|
default:
|
||||||
|
panic("invalid comparison result")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (kvs KI64Pairs) Swap(i, j int) { kvs[i], kvs[j] = kvs[j], kvs[i] }
|
||||||
|
func (kvs KI64Pairs) Sort() { sort.Sort(kvs) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user