diff options
author | Haoping Ku <haoping.ku@dexon.org> | 2018-07-24 18:35:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-24 18:35:32 +0800 |
commit | 39bcb39dd5d93401c21b374cbd1e1818b76d6891 (patch) | |
tree | dba957003d1d1c7bb79cebcc5063a7ba765a0eba /common | |
parent | 2108b92131fff21c8e2b7e5b85a77e3f693dadd9 (diff) | |
download | dexon-consensus-39bcb39dd5d93401c21b374cbd1e1818b76d6891.tar dexon-consensus-39bcb39dd5d93401c21b374cbd1e1818b76d6891.tar.gz dexon-consensus-39bcb39dd5d93401c21b374cbd1e1818b76d6891.tar.bz2 dexon-consensus-39bcb39dd5d93401c21b374cbd1e1818b76d6891.tar.lz dexon-consensus-39bcb39dd5d93401c21b374cbd1e1818b76d6891.tar.xz dexon-consensus-39bcb39dd5d93401c21b374cbd1e1818b76d6891.tar.zst dexon-consensus-39bcb39dd5d93401c21b374cbd1e1818b76d6891.zip |
Fix blocklattice_test.go's ordering check (#15)
Outputs of total ordering are sorted by hash value in blocklattice.go,
but was checked orderly in test, which the order might change due to
random hash.
Added common.Hashes.
Diffstat (limited to 'common')
-rw-r--r-- | common/types.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/common/types.go b/common/types.go index 495b10d..0a78111 100644 --- a/common/types.go +++ b/common/types.go @@ -18,6 +18,7 @@ package common import ( + "bytes" "encoding/hex" ) @@ -50,3 +51,10 @@ func (h *Hash) UnmarshalText(text []byte) error { _, err := hex.Decode(h[:], text) return err } + +// Hashes is for sorting hashes. +type Hashes []Hash + +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] } |