2 * This file is part of cparser.
3 * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
5 #ifndef _FIRM_HASH_STRING_H_
6 #define _FIRM_HASH_STRING_H_
8 #define _FIRM_FNV_OFFSET_BASIS 2166136261U
9 #define _FIRM_FNV_FNV_PRIME 16777619U
11 static inline __attribute__((pure))
12 unsigned hash_string(const char* str)
14 const unsigned char *p;
15 unsigned hash = _FIRM_FNV_OFFSET_BASIS;
17 for(p = (const unsigned char*) str; *p != 0; ++p) {
18 hash *= _FIRM_FNV_FNV_PRIME;
25 static inline __attribute__((pure))
26 unsigned hash_string_size(const char* str, size_t size)
29 unsigned hash = _FIRM_FNV_OFFSET_BASIS;
31 for(i = 0; i < size; ++i) {
32 hash *= _FIRM_FNV_FNV_PRIME;