mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-28 05:46:36 +08:00
288b74d104
Result: {"status":"keep","total_issues":33,"golint_canonicalheader":0,"golint_errname":1,"golint_errorlint":12,"golint_forcetypeassert":3,"golint_gosec":0,"golint_intrange":0,"golint_modernize":3,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":3,"golint_recvcheck":7,"golint_usestdlibvars":0,"golint_wastedassign":0,"golint_total":32,"eslint_problems":1,"eslint_errors":0,"eslint_warnings":1,"tsc_errors":0,"measure_s":45}
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package cap
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// fnv1a returns the 32-bit FNV-1a hash of a string
|
|
//
|
|
//nolint:mnd // FNV-1a 算法位移常量
|
|
func fnv1a(str string) uint32 {
|
|
var hash uint32 = 2166136261
|
|
for i := range len(str) {
|
|
hash ^= uint32(str[i])
|
|
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24)
|
|
}
|
|
return hash
|
|
}
|
|
|
|
// fnv1aResume resumes FNV-1a hashing from a given state
|
|
//
|
|
//nolint:mnd // FNV-1a 算法位移常量
|
|
func fnv1aResume(state uint32, str string) uint32 {
|
|
h := state
|
|
for i := range len(str) {
|
|
h ^= uint32(str[i])
|
|
h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24)
|
|
}
|
|
return h
|
|
}
|
|
|
|
// prngFromHash generates a hex string of specified length using an initial hash state
|
|
//
|
|
//nolint:mnd // xorshift 算法位移常量
|
|
func prngFromHash(initialHash uint32, length int) string {
|
|
state := initialHash
|
|
var result strings.Builder
|
|
for result.Len() < length {
|
|
state ^= state << 13
|
|
state ^= state >> 17
|
|
state ^= state << 5
|
|
hexStr := fmt.Sprintf("%08x", state)
|
|
result.WriteString(hexStr)
|
|
}
|
|
return result.String()[:length]
|
|
}
|