-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtab_hash.c
48 lines (43 loc) · 1.18 KB
/
htab_hash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*****************
** Vit Pavlik **
** xpavli0a **
** 251301 **
** **
** Created: **
** 2023-04-13 **
** **
** Last edited: **
** 2023-04-13 **
*****************/
// Fakulta: FIT VUT
// Vyvíjeno s gcc 10.2.1 na Debian GNU/Linux 11
/**
* Puvodni implementace teto hash funkce se objevila v projektu `sdbm` (Public
* domain implementace `dbm`)
*
* vizte:
*
* Wikipedia: DBM (computing)
* https://en.wikipedia.org/wiki/DBM_(computing)
* * prevzato 2023-04-13
*
* Ozan Yigit: A collection of non-cryptographic hash functions.
* http://www.cse.yorku.ca/~oz/hash.html
* * prevzato 2023-04-13
*
* programmingalgorithms.com: SDBM Hash
* https://www.programmingalgorithms.com/algorithm/sdbm-hash/c/
* * prevzato 2023-04-13
*
* Original SBDM source code (github mirror repository)
* https://github.com/davidar/sdbm/blob/29d5ed2b5297e51125ee45f6efc5541851aab0fb/hash.c#L18-L47
* * prevzato 2023-04-13
*/
#include "htab_priv.h"
size_t htab_hash_function(htab_key_t str) {
size_t output = 0;
for (unsigned int i = 0; str[i] != '\0'; i++) {
output = str[i] + (output << 6) + (output << 16) - output;
}
return output;
}