diff --git a/helper/hashcode/hashcode.go b/helper/hashcode/hashcode.go new file mode 100644 index 0000000000..1cc8fa1645 --- /dev/null +++ b/helper/hashcode/hashcode.go @@ -0,0 +1,10 @@ +package hashcode + +import ( + "hash/crc32" +) + +// String hashes a string to a unique hashcode. +func String(s string) int { + return int(crc32.ChecksumIEEE([]byte(s))) +} diff --git a/helper/hashcode/hashcode_test.go b/helper/hashcode/hashcode_test.go new file mode 100644 index 0000000000..5406f40bf6 --- /dev/null +++ b/helper/hashcode/hashcode_test.go @@ -0,0 +1,16 @@ +package hashcode + +import ( + "testing" +) + +func TestString(t *testing.T) { + v := "hello, world" + expected := String(v) + for i := 0; i < 100; i++ { + actual := String(v) + if actual != expected { + t.Fatalf("bad: %#v", actual) + } + } +}