-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b404941
commit cff6da7
Showing
6 changed files
with
151 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package finger | ||
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"github.com/spaolacci/murmur3" | ||
) | ||
|
||
func InsertInto(s string, interval int, sep rune) string { | ||
var buffer bytes.Buffer | ||
before := interval - 1 | ||
last := len(s) - 1 | ||
for i, char := range s { | ||
buffer.WriteRune(char) | ||
if i%interval == before && i != last { | ||
buffer.WriteRune(sep) | ||
} | ||
} | ||
buffer.WriteRune(sep) | ||
return buffer.String() | ||
} | ||
func mmh3(data []byte) int32 { | ||
hash := murmur3.New32WithSeed(0) | ||
_, err := hash.Write([]byte(base64Py(data))) | ||
if err != nil { | ||
return 0 | ||
} | ||
return int32(hash.Sum32()) | ||
} | ||
|
||
func base64Py(data []byte) string { | ||
// python encodes to base64 with lines of 76 bytes terminated by new line "\n" | ||
stdBase64 := base64.StdEncoding.EncodeToString(data) | ||
return InsertInto(stdBase64, 76, '\n') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters