diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-09-12 15:35:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-12 15:35:24 +0800 |
commit | b4af97dd8cfd5bbd7032fb5e1aff240625df06cb (patch) | |
tree | 7cfd54754cc8dbdb6a3165cf7b1ba3af0ab88986 /common | |
parent | 743983c82b601e200fa53d4aa8973f83ff628d29 (diff) | |
download | dexon-consensus-b4af97dd8cfd5bbd7032fb5e1aff240625df06cb.tar dexon-consensus-b4af97dd8cfd5bbd7032fb5e1aff240625df06cb.tar.gz dexon-consensus-b4af97dd8cfd5bbd7032fb5e1aff240625df06cb.tar.bz2 dexon-consensus-b4af97dd8cfd5bbd7032fb5e1aff240625df06cb.tar.lz dexon-consensus-b4af97dd8cfd5bbd7032fb5e1aff240625df06cb.tar.xz dexon-consensus-b4af97dd8cfd5bbd7032fb5e1aff240625df06cb.tar.zst dexon-consensus-b4af97dd8cfd5bbd7032fb5e1aff240625df06cb.zip |
core: replace acks with slice (#102)
Diffstat (limited to 'common')
-rw-r--r-- | common/types.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/common/types.go b/common/types.go index 9dc9f1c..bd15c5b 100644 --- a/common/types.go +++ b/common/types.go @@ -20,6 +20,7 @@ package common import ( "bytes" "encoding/hex" + "sort" "time" ) @@ -60,6 +61,17 @@ func (hs Hashes) Len() int { return len(hs) } func (hs Hashes) Less(i, j int) bool { return bytes.Compare(hs[i][:], hs[j][:]) < 0 } func (hs Hashes) Swap(i, j int) { hs[i], hs[j] = hs[j], hs[i] } +// SortedHashes is a slice of hashes sorted in ascending order. +type SortedHashes Hashes + +// NewSortedHashes converts a slice of hashes to a sorted one. It's a +// firewall to prevent us from assigning unsorted hashes to a variable +// declared as SortedHashes directly. +func NewSortedHashes(hs Hashes) SortedHashes { + sort.Sort(hs) + return SortedHashes(hs) +} + // ByTime implements sort.Interface for time.Time. type ByTime []time.Time |