/* Symbol table support
Copyright 2016 Molnár Károly
*/
#include "stdhdr.h"
#include "libgputils.h"
/*------------------------------------------------------------------------------------------------*/
void hash128_t::reset() {
lo = (uint64_t)0x210F61E7510E3743;
hi = (uint64_t)0x811CA7F5A9E47333;
}
void hash128_t::hash(uint32_t ch) {
struct Z{
uint32_t lo,hi;
}*p = (Z*)&lo;
p->lo ^= ch;
p->lo *= 0x01023FD3;
p->hi ^= ch;
p->hi *= 0x0103E49D;
p = (Z*)&hi;
p->lo ^= ch;
p->lo *= 0x01015469;
p->hi ^= ch;
p->hi *= 0x01041943;
}
void hash128_t::hash(const char*a, size_t l,bool low) {
if (!a || !l) return;
do{
char c=*a++;
if (low && 'A'<=c && c<='Z') c|=0x20;
hash((uint8_t)c); // let zero-extend to 32 bits!
}while(--l);
}
/*------------------------------------------------------------------------------------------------*/
void gp_hash_mem(hash128_t *Hash, const void *Array, size_t Length) {
Hash->hash(static_cast<const char*>(Array),Length);
}
/*------------------------------------------------------------------------------------------------*/
void gp_hash_str_len(hash128_t *Hash, const char *String, size_t Length, bool Case_insensitive) {
Hash->hash(String,Length,Case_insensitive);
}
/*------------------------------------------------------------------------------------------------*/
void gp_hash_str(hash128_t *Hash, const char *String, bool Case_insensitive) {
Hash->hash(String,strlen(String),Case_insensitive);
}
Detected encoding: UTF-8 | 0
|