github.com/gogf/gf/v2@v2.7.4/encoding/ghash/ghash_rs.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package ghash 8 9 // RS implements the classic RS hash algorithm for 32 bits. 10 func RS(str []byte) uint32 { 11 var ( 12 b uint32 = 378551 13 a uint32 = 63689 14 hash uint32 = 0 15 ) 16 for i := 0; i < len(str); i++ { 17 hash = hash*a + uint32(str[i]) 18 a *= b 19 } 20 return hash 21 } 22 23 // RS64 implements the classic RS hash algorithm for 64 bits. 24 func RS64(str []byte) uint64 { 25 var ( 26 b uint64 = 378551 27 a uint64 = 63689 28 hash uint64 = 0 29 ) 30 for i := 0; i < len(str); i++ { 31 hash = hash*a + uint64(str[i]) 32 a *= b 33 } 34 return hash 35 }