Skip to content

Commit

Permalink
utility.go: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
distributed committed Jan 22, 2010
1 parent 9f7d95f commit cf6ebcd
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ import (
)


type Distance []byte;
type Distance []byte


func (d Distance) String() string {
return hex.EncodeToString(d)
}
func (d Distance) String() string { return hex.EncodeToString(d) }

const K = 20

// Hashes a byte slice and returns a 20 byte string.
func SHA1Bytes(b []byte) string {
h := sha1.New()
h.Write(b)
return string(h.Sum())
}

// Hashes a string and returns a 20 byte string.
func SHA1String(s string) string {
h := sha1.New()
h.Write(strings.Bytes(s))
Expand All @@ -32,10 +34,10 @@ func XOR(a, b string) Distance {
if l != len(b) {
return nil
}

d := make(Distance, l)

for i := 0; i < l; i ++ {
for i := 0; i < l; i++ {
d[i] = a[i] ^ b[i]
}

Expand All @@ -56,14 +58,14 @@ func BucketNo(d Distance) uint {
continue
}
var bitnr uint = 0
for i := 0; i < 8; i ++ {
for i := 0; i < 8; i++ {
if (b & (0x80 >> bitnr)) != 0 {
return basebitnr + bitnr
}
bitnr++
}
}

return basebitnr
}

Expand All @@ -75,7 +77,7 @@ func (a Distance) Less(b Distance) bool {

//fmt.Printf("distance Less called: %v < %v\n", a, b)

for i, ea := range(a) {
for i, ea := range a {
eb := b[i]
switch {
case ea < eb:
Expand Down

0 comments on commit cf6ebcd

Please sign in to comment.