add golang version of emojihash and colorhash#2
Conversation
KilianKae
left a comment
There was a problem hiding this comment.
Hey! I started the review on the emojihash code, I will probably need another round.
I did not look at the rest of the code.
Could you add a few more comments? e.g. what does BigBase exactly do?
| > 🌙🔕🏒🍝🥁🏟🐽😳🌲🏈🍁🕘👶😠🧸💙 | ||
| ``` | ||
|
|
||
| go-lang version of emojihash and colorhash (output as sequence of color indexes 0-31) |
There was a problem hiding this comment.
Any reasons for go-lang not just go. Here and in folder structure?
|
|
||
| import "math/big" | ||
|
|
||
| func ToBigBase(value *big.Int, base uint64) (res [](uint64)) { |
There was a problem hiding this comment.
You don't need the () around the uint64 in the return type.
| return | ||
| } | ||
|
|
||
| func toBigBaseImpl(value *big.Int, base uint64, res *[](uint64)) { |
| } else if hashLen > len(indexes) { | ||
| prependLen := hashLen - len(indexes) | ||
| for i := 0; i < prependLen; i++ { | ||
| indexes = append([](uint64){0}, indexes...) |
| "strings" | ||
| ) | ||
|
|
||
| func ToEmojiHash(value *big.Int, hashLen int, alphabet *[]string) (hash []string, err error) { |
There was a problem hiding this comment.
err is used nowhere. Just (hash []string, error) is enough
There was a problem hiding this comment.
I would suggest to not use a pointer to the alphabet slice.
-> alphabet []string
|
|
||
| func ToEmojiHash(value *big.Int, hashLen int, alphabet *[]string) (hash []string, err error) { | ||
| valueBitLen := value.BitLen() | ||
| alphabetLen := new(big.Int).SetInt64(int64(len(*alphabet))) |
There was a problem hiding this comment.
I would suggest alphabetLen := uint64(len(*alphabet)) to keep it readable.
Simplifies line 15.
Adds a new(big.Int).SetUint64(alphabetLen) to line 26
| return hash, nil | ||
| } | ||
|
|
||
| func LoadEmojisAlphabet() (*[]string, error) { |
There was a problem hiding this comment.
I would suggest not to return a pointer to the alphabet.
| return nil, err | ||
| } | ||
|
|
||
| alphabet := make([]string, 0) |
There was a problem hiding this comment.
Instantiating the slice like this var alphabet []string would be the more common approach.
| return | ||
| } | ||
|
|
||
| func toBigBaseImpl(value *big.Int, base uint64, res *[](uint64)) { |
There was a problem hiding this comment.
To be more in line with the standard libs I would suggest an approach in which the slice is returned and not referenced to. Does anything speak against that?
No description provided.