mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
hash.wyhash: fix memory errors (#10051)
This commit is contained in:
parent
c16d4911c2
commit
0d205510d5
@ -1,4 +1,4 @@
|
|||||||
import hash as wyhash
|
module hash
|
||||||
|
|
||||||
struct WyHashTest {
|
struct WyHashTest {
|
||||||
s string
|
s string
|
||||||
@ -13,9 +13,13 @@ fn test_wyhash() {
|
|||||||
WyHashTest{'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 5, 0xe062dfda99413626},
|
WyHashTest{'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 5, 0xe062dfda99413626},
|
||||||
]
|
]
|
||||||
for test in tests {
|
for test in tests {
|
||||||
got := wyhash.sum64(test.s.bytes(), test.seed)
|
got := wyhash64(test.s.str, u64(test.s.len), test.seed)
|
||||||
// println(' # GOT: $got | $got.hex()')
|
// println(' # GOT: $got | $got.hex()')
|
||||||
// println(' # EXPECTED: $test.expected | $test.expected.hex()')
|
// println(' # EXPECTED: $test.expected | $test.expected.hex()')
|
||||||
assert got == test.expected
|
assert got == test.expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s := '/v/vmaster/vlib/v/fmt/tests/maps_of_fns_with_string_keys_keep.vv'
|
||||||
|
x := sum64_string(s, 5).hex_full()
|
||||||
|
println(x)
|
||||||
}
|
}
|
||||||
|
@ -25,15 +25,16 @@ const (
|
|||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn sum64_string(key string, seed u64) u64 {
|
pub fn sum64_string(key string, seed u64) u64 {
|
||||||
return wyhash64(key.str, u64(key.len), seed)
|
return wyhash_c(key.str, u64(key.len), seed)
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn sum64(key []byte, seed u64) u64 {
|
pub fn sum64(key []byte, seed u64) u64 {
|
||||||
return wyhash64(&byte(key.data), u64(key.len), seed)
|
return wyhash_c(&byte(key.data), u64(key.len), seed)
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
// This is an outdated version of wyhash with memory errors!
|
||||||
|
[deprecated; inline]
|
||||||
fn wyhash64(key &byte, len u64, seed_ u64) u64 {
|
fn wyhash64(key &byte, len u64, seed_ u64) u64 {
|
||||||
if len == 0 {
|
if len == 0 {
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
Reference in New Issue
Block a user