src/hashkit: apply clang-format
[m6w6/libmemcached] / src / libhashkit / fnv_32.cc
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #include "libhashkit/common.h"
17
18 /* FNV hash'es lifted from Dustin Sallings work */
19 static uint32_t FNV_32_INIT = 2166136261UL;
20 static uint32_t FNV_32_PRIME = 16777619;
21
22 uint32_t hashkit_fnv1_32(const char *key, size_t key_length, void *context) {
23 uint32_t hash = FNV_32_INIT;
24 (void) context;
25
26 for (size_t x = 0; x < key_length; x++) {
27 uint32_t val = (uint32_t) key[x];
28 hash *= FNV_32_PRIME;
29 hash ^= val;
30 }
31
32 return hash;
33 }
34
35 uint32_t hashkit_fnv1a_32(const char *key, size_t key_length, void *context) {
36 uint32_t hash = FNV_32_INIT;
37 (void) context;
38
39 for (size_t x = 0; x < key_length; x++) {
40 uint32_t val = (uint32_t) key[x];
41 hash ^= val;
42 hash *= FNV_32_PRIME;
43 }
44
45 return hash;
46 }