1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

js: initial work on porting rand module to JS backend (#11188)

This commit is contained in:
playX
2021-08-15 15:09:51 +00:00
committed by GitHub
parent 6ee77724e8
commit 659f823c5c
7 changed files with 182 additions and 152 deletions

View File

@@ -21,3 +21,13 @@ pub fn wyhash_c(key &byte, len u64, seed u64) u64 {
pub fn wyhash64_c(a u64, b u64) u64 {
return C.wyhash64(a, b)
}
[inline]
pub fn sum64_string(key string, seed u64) u64 {
return wyhash_c(key.str, u64(key.len), seed)
}
[inline]
pub fn sum64(key []byte, seed u64) u64 {
return wyhash_c(&byte(key.data), u64(key.len), seed)
}

1
vlib/hash/wyhash.js.v Normal file
View File

@@ -0,0 +1 @@
module hash

View File

@@ -23,16 +23,6 @@ const (
wyp4 = u64(0x1d8e4e27c47d124f)
)
[inline]
pub fn sum64_string(key string, seed u64) u64 {
return wyhash_c(key.str, u64(key.len), seed)
}
[inline]
pub fn sum64(key []byte, seed u64) u64 {
return wyhash_c(&byte(key.data), u64(key.len), seed)
}
[inline]
fn wyrotr(v u64, k u32) u64 {
return (v >> k) | (v << (64 - k))