16 lines
		
	
	
		
			379 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			16 lines
		
	
	
		
			379 B
		
	
	
	
		
			C
		
	
	
	
	
	
#include "strutil.h"
 | 
						|
#include "string.h"
 | 
						|
 | 
						|
uintptr_t strnhash(const char* s, size_t n) {
 | 
						|
    static const size_t shift = sizeof(uintptr_t) * 8 - 4;
 | 
						|
    uintptr_t hash = 0;
 | 
						|
    for(size_t i = 0; i < n; ++i) {
 | 
						|
        hash = ((hash << 4) | s[i]) ^ (((uintptr_t)0xF << shift) & hash);
 | 
						|
    }
 | 
						|
    return hash;
 | 
						|
}
 | 
						|
 | 
						|
uintptr_t strhash(const char* s) {
 | 
						|
    return strnhash(s, strlen(s));
 | 
						|
}
 |