Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. func hashify(appList []string, vectorLength int64) ([]int){
  2. hashedList := make([]int, vectorLength)
  3. for _, app := range appList {
  4. hashedValue := sha256.New()
  5. hashedValue.Write([]byte(app))
  6. hexStr := fmt.Sprintf("%x", hashedValue.Sum(nil))
  7.  
  8. hexInt := new(big.Int)
  9. hexInt, ok := hexInt.SetString(hexStr, 16)
  10. if !ok {
  11. fmt.Println("error")
  12. panic("couldn't create bigint")
  13. }
  14. bigVectorLength := big.NewInt(vectorLength)
  15. modulo := new(big.Int)
  16. modulo = modulo.Mod(hexInt, bigVectorLength)
  17. moduloInt64 := modulo.Int64()
  18. hashedList[moduloInt64] += 1
  19. }
  20. return hashedList
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement