You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
689 B
26 lines
689 B
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package ghash
|
|
|
|
// DJB implements the classic DJB hash algorithm for 32 bits.
|
|
func DJB(str []byte) uint32 {
|
|
var hash uint32 = 5381
|
|
for i := 0; i < len(str); i++ {
|
|
hash += (hash << 5) + uint32(str[i])
|
|
}
|
|
return hash
|
|
}
|
|
|
|
// DJB64 implements the classic DJB hash algorithm for 64 bits.
|
|
func DJB64(str []byte) uint64 {
|
|
var hash uint64 = 5381
|
|
for i := 0; i < len(str); i++ {
|
|
hash += (hash << 5) + uint64(str[i])
|
|
}
|
|
return hash
|
|
}
|