aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/hash.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-12-05 15:44:50 +0100
committerGitHub <noreply@github.com>2016-12-05 15:44:50 +0100
commit11735c3b3aaa8f789dc10739a4de7ad438196000 (patch)
treec83fa6ddf9748fd0e4e4edb4d0e2692994145ace /plumbing/hash.go
parent0042bb031676a20ffc789f94e332a6da70e2756d (diff)
downloadgo-git-11735c3b3aaa8f789dc10739a4de7ad438196000.tar.gz
plumbing/protocol: paktp avoid duplication of haves, wants and shallow (#158)
Diffstat (limited to 'plumbing/hash.go')
-rw-r--r--plumbing/hash.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/plumbing/hash.go b/plumbing/hash.go
index 7fa953d..8e60877 100644
--- a/plumbing/hash.go
+++ b/plumbing/hash.go
@@ -1,9 +1,11 @@
package plumbing
import (
+ "bytes"
"crypto/sha1"
"encoding/hex"
"hash"
+ "sort"
"strconv"
)
@@ -56,3 +58,16 @@ func (h Hasher) Sum() (hash Hash) {
copy(hash[:], h.Hash.Sum(nil))
return
}
+
+// HashesSort sorts a slice of Hashes in increasing order.
+func HashesSort(a []Hash) {
+ sort.Sort(HashSlice(a))
+}
+
+// HashSlice attaches the methods of sort.Interface to []Hash, sorting in
+// increasing order.
+type HashSlice []Hash
+
+func (p HashSlice) Len() int { return len(p) }
+func (p HashSlice) Less(i, j int) bool { return bytes.Compare(p[i][:], p[j][:]) < 0 }
+func (p HashSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }