parser: Remove the unused attribute alignment from struct declaration_specifiers_t.
[cparser] / adt / hash_string.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
4  */
5 #ifndef _FIRM_HASH_STRING_H_
6 #define _FIRM_HASH_STRING_H_
7
8 #define _FIRM_FNV_OFFSET_BASIS 2166136261U
9 #define _FIRM_FNV_FNV_PRIME 16777619U
10
11 static inline __attribute__((pure))
12 unsigned hash_string(const char* str)
13 {
14         const unsigned char *p;
15         unsigned hash = _FIRM_FNV_OFFSET_BASIS;
16
17         for(p = (const unsigned char*) str; *p != 0; ++p) {
18                 hash *= _FIRM_FNV_FNV_PRIME;
19                 hash ^= *p;
20         }
21
22         return hash;
23 }
24
25 static inline __attribute__((pure))
26 unsigned hash_string_size(const char* str, size_t size)
27 {
28         size_t i;
29         unsigned hash = _FIRM_FNV_OFFSET_BASIS;
30
31         for(i = 0; i < size; ++i) {
32                 hash *= _FIRM_FNV_FNV_PRIME;
33                 hash ^= str[i];
34         }
35
36         return hash;
37 }
38
39 #endif