mirror of https://github.com/hashicorp/terraform
parent
9d53689f11
commit
a5040ecc03
@ -1,10 +1,16 @@
|
||||
package hashcode
|
||||
|
||||
import (
|
||||
"hash/crc32"
|
||||
)
|
||||
import "hash/crc32"
|
||||
|
||||
// String hashes a string to a unique hashcode.
|
||||
//
|
||||
// crc32 returns a uint32, but for our use we need
|
||||
// and non negative integer. Here we cast to an integer
|
||||
// and invert it if the result is negative.
|
||||
func String(s string) int {
|
||||
return int(crc32.ChecksumIEEE([]byte(s)))
|
||||
v := int(crc32.ChecksumIEEE([]byte(s)))
|
||||
if v < 0 {
|
||||
return -v
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue