File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -265,3 +265,25 @@ func FNVStringToInt64(data string, args ...string) int64 {
265265
266266 return int64 (hasher .Sum64 ())
267267}
268+
269+ // FNVStringToInt32 is a ready‑to‑use 32‑bit FNV‑1a implementation compatible
270+ // with the `HashFunc` signature.
271+ //
272+ // It concatenates *data* and *args* (already salted) and returns the 32‑bit
273+ // digest as a signed integer (`int32`).
274+ //
275+ // # Example
276+ //
277+ // hasher := yahash.NewHash(yahash.FNVStringToInt32, "secret", time.Minute, 3)
278+ // code := hasher.HashWithTime(time.Now(), "ya_args")
279+ // fmt.Println(code)
280+ func FNVStringToInt32 (data string , args ... string ) int32 {
281+ hasher := fnv .New32 ()
282+ hasher .Write ([]byte (data ))
283+
284+ for _ , arg := range args {
285+ hasher .Write ([]byte (arg ))
286+ }
287+
288+ return int32 (hasher .Sum32 ())
289+ }
You can’t perform that action at this time.
0 commit comments