FOSSology  4.4.0
Open Source License Compliance by Open Source Software
hash.c
1 /*
2  Author: Daniele Fognini, Andreas Wuerl
3  SPDX-FileCopyrightText: © 2013-2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 #include "hash.h"
9 #include <stdio.h>
10 
11 uint32_t hash(const char* string) {
12 
13  uint32_t result = hash_init();
14 
15  const char* ptr = string;
16 
17  while (*ptr) {
18  hash_add(ptr, &result);
19  ptr++;
20  }
21 
22  return result;
23 }
24 
25 uint32_t hash_init() {
26  return 5231;
27 }
28 
29 void hash_add(const char* value, uint32_t* currentHash) {
30  *currentHash = ((*currentHash << 6) + *currentHash) + *value;
31 }