diff options
| author | binbinshi <javabinbin@126.com> | 2020-02-05 16:56:23 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-05 16:56:23 +0800 |
| commit | d892cad15d748327c2b7c649f6398ff35d8dce0b (patch) | |
| tree | 29cb8adae01d9f4eaeabb02996d162700da2de1a /weed/util/bytes.go | |
| parent | d4f755347e4874cf0a2fd13480580f348b86a465 (diff) | |
| parent | 8d94564f4152cd890d5896a3dedf5e7589c5023e (diff) | |
| download | seaweedfs-d892cad15d748327c2b7c649f6398ff35d8dce0b.tar.xz seaweedfs-d892cad15d748327c2b7c649f6398ff35d8dce0b.zip | |
Merge pull request #1 from chrislusf/master
update from chrisluf
Diffstat (limited to 'weed/util/bytes.go')
| -rw-r--r-- | weed/util/bytes.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/weed/util/bytes.go b/weed/util/bytes.go index dfa4ae665..9c7e5e2cb 100644 --- a/weed/util/bytes.go +++ b/weed/util/bytes.go @@ -1,5 +1,10 @@ package util +import ( + "crypto/md5" + "io" +) + // big endian func BytesToUint64(b []byte) (v uint64) { @@ -43,3 +48,29 @@ func Uint16toBytes(b []byte, v uint16) { func Uint8toBytes(b []byte, v uint8) { b[0] = byte(v) } + +// returns a 64 bit big int +func HashStringToLong(dir string) (v int64) { + h := md5.New() + io.WriteString(h, dir) + + b := h.Sum(nil) + + v += int64(b[0]) + v <<= 8 + v += int64(b[1]) + v <<= 8 + v += int64(b[2]) + v <<= 8 + v += int64(b[3]) + v <<= 8 + v += int64(b[4]) + v <<= 8 + v += int64(b[5]) + v <<= 8 + v += int64(b[6]) + v <<= 8 + v += int64(b[7]) + + return +} |
