Computes the DJB2 hash for the given buffer
(buffer: &[u8])
| 83 | |
| 84 | /// Computes the DJB2 hash for the given buffer |
| 85 | pub fn dbj2_hash(buffer: &[u8]) -> u32 { |
| 86 | let mut hsh: u32 = 5381; |
| 87 | let mut iter: usize = 0; |
| 88 | let mut cur: u8; |
| 89 | |
| 90 | while iter < buffer.len() { |
| 91 | cur = buffer[iter]; |
| 92 | |
| 93 | if cur == 0 { |
| 94 | iter += 1; |
| 95 | continue; |
| 96 | } |
| 97 | |
| 98 | if cur >= ('a' as u8) { |
| 99 | cur -= 0x20; |
| 100 | } |
| 101 | |
| 102 | hsh = ((hsh << 5).wrapping_add(hsh)) + cur as u32; |
| 103 | iter += 1; |
| 104 | } |
| 105 | hsh |
| 106 | } |
| 107 | |
| 108 | /// Calculates the length of a C-style null-terminated string. |
| 109 | pub fn get_cstr_len(pointer: *const char) -> usize { |
no outgoing calls
no test coverage detected