Skip to content

Commit

Permalink
Merge branch clean-code to master
Browse files Browse the repository at this point in the history
  • Loading branch information
Tran Hoang committed Mar 28, 2020
1 parent f46419c commit e75aae2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
Go Murmur3
===

> Project được xây dựng nhằm mục đích giải quyết việc hash với seed là số âm trong golang
Ouput
---

* `Integer:`
* `AsInt()` Trả về 1 số nguyên 32 bits được lấy từ 4 bytes đầu tiên của `ByteBuffer`
* `String:`
* `ToString()` Trả về 1 chuỗi 256 bits, được hash từ 16 bytes của `ByteBuffer`
* `Bytes:`
* `ToBytes()` Trả về mảng 16 bytes từ `H1``H2` sau khi hash
* `AsBytes()` Trả về mảng 4 bytes đầu tiên của ToBytes theo thứ tự ngược lại

Examples:

```go
m3_128 := murmur3.HashString(-1467523828, "681236075540516864")

// AsInt()
m3_128.AsInt()
// output: -1239833368

// ToString()
m3_128.ToString()
// output: e8a419b6a02dd4769f55b02614e8644e

// ToBytes()
m3_128.ToBytes()
// output: [232 164 25 182 160 45 212 118 159 85 176 38 20 232 100 78]

// AsBytes()
m3_128.AsBytes()
// output: [182 25 164 232]
```

14 changes: 7 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"log"
"murmur3"
)
Expand All @@ -11,13 +10,14 @@ func main() {

log.Println(m3_128.AsBytes())
log.Println(m3_128.ToBytes())
log.Println(murmur3.IntToBytes("681236075540516864"))
log.Println(m3_128.AsInt())
log.Println(m3_128.ToString())

key := append(m3_128.AsBytes(), murmur3.IntToBytes("681236075540516864")...)
key = append(key, murmur3.IntToBytes("17480678941457235")...)
fmt.Println(key)
key1 := []byte{182, 25, 164, 232, 9, 116, 60, 153, 242, 198, 16, 0, 0, 62, 26, 149, 186, 188, 251, 83}
fmt.Println(key1)
//key := append(m3_128.AsBytes(), murmur3.IntToBytes("681236075540516864")...)
//key = append(key, murmur3.IntToBytes("17480678941457235")...)
//fmt.Println(key)
//key1 := []byte{182, 25, 164, 232, 9, 116, 60, 153, 242, 198, 16, 0, 0, 62, 26, 149, 186, 188, 251, 83}
//fmt.Println(key1)

//fmt.Println(m3_128.AsInt())
//fmt.Println(m3_128.ToString())
Expand Down

0 comments on commit e75aae2

Please sign in to comment.