Created
August 2, 2018 04:57
-
-
Save maxymania/1bf5cd9695f931da20e7e6d5a2a30093 to your computer and use it in GitHub Desktop.
Integer hash
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
import "sort" | |
/* | |
Generates n unique numbers mod m. v is used as deterministic source. | |
*/ | |
func Inthash(v, n, m int) []int { | |
if n>m { panic("less unique numbers than slots") } | |
r := make([]int,n) | |
for i := range r { | |
r[i] = v%m | |
v/=m | |
m-- | |
} | |
for i := range r { | |
cv := r[i] | |
for j := i+1 ; j<n ; j++ { | |
if r[j]==cv { r[j]++ } | |
} | |
} | |
sort.Ints(r) | |
return r | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment