aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/hash.go
diff options
context:
space:
mode:
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] }