MCPcopy Create free account
hub / github.com/PerroEngine/Perro / string_to_u64

Function string_to_u64

perro_source/core/perro_ids/src/ids.rs:12–40  ·  view source on GitHub ↗
(s: &str)

Source from the content-addressed store, hash-verified

10
11#[inline]
12pub const fn string_to_u64(s: &str) -> u64 {
13 let bytes = s.as_bytes();
14 let len = bytes.len();
15 if len == 0 {
16 return EMPTY_STRING_HASH;
17 }
18
19 let mut hash = STRING_HASH_SEED ^ (len as u64).wrapping_mul(STRING_HASH_PRIME);
20 let mut i = 0usize;
21
22 while i + 8 <= len {
23 hash ^= read_u64_le(bytes, i);
24 hash = hash.wrapping_mul(STRING_HASH_PRIME);
25 hash ^= hash >> 32;
26 i += 8;
27 }
28
29 let mut tail = 0u64;
30 let mut shift = 0u32;
31 while i < len {
32 tail |= (bytes[i] as u64) << shift;
33 shift += 8;
34 i += 1;
35 }
36
37 hash ^= tail;
38 hash = hash.wrapping_mul(STRING_HASH_SEED);
39 mix64(hash)
40}
41
42const fn read_u64_le(bytes: &[u8], offset: usize) -> u64 {
43 (bytes[offset] as u64)

Callers 15

huge_csv_benchFunction · 0.85
header_indexMethod · 0.85
get_by_headerMethod · 0.85
find_primaryMethod · 0.85
findMethod · 0.85
add_textMethod · 0.85
add_inMethod · 0.85
leak_cellsFunction · 0.85
from_stringMethod · 0.85
write_scripts_libFunction · 0.85
generate_static_audiosFunction · 0.85

Calls 4

read_u64_leFunction · 0.85
mix64Function · 0.85
as_bytesMethod · 0.45
lenMethod · 0.45

Tested by 3

test_lookupFunction · 0.68
lookupFunction · 0.68