X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fhash.h;h=531c6639827a512f639f94fb918c56326cdbf5f3;hb=28b7a53b693f6b4e70218a926e68a36ece54cda1;hp=11d132a49f9bb3f49cd1facbee72b56f586dda49;hpb=0912276c6467aa3ee6f570b31245367319da572a;p=tinc diff --git a/src/hash.h b/src/hash.h index 11d132a4..531c6639 100644 --- a/src/hash.h +++ b/src/hash.h @@ -3,7 +3,7 @@ /* hash.h -- header file for hash.c - Copyright (C) 2012 Guus Sliepen + Copyright (C) 2012-2022 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,10 +37,10 @@ uint32_t modulo(uint32_t hash, size_t n); t keys[n]; \ const void *values[n]; \ } hash_ ## t; \ - static uint32_t inline hash_modulo_ ## t(uint32_t hash) { \ + static inline uint32_t hash_modulo_ ## t(uint32_t hash) { \ return hash & (n - 1); \ } \ - void hash_insert_ ## t (hash_ ##t *hash, const t *key, const void *value) { \ + static inline void hash_insert_ ## t (hash_ ##t *hash, const t *key, const void *value) { \ uint32_t i = hash_modulo_ ## t(hash_function_ ## t(key)); \ for(uint8_t f=0; f< (HASH_SEARCH_ITERATIONS - 1); f++){ \ if(hash->values[i] == NULL || !memcmp(key, &hash->keys[i], sizeof(t))) { \ @@ -54,7 +54,7 @@ uint32_t modulo(uint32_t hash, size_t n); memcpy(&hash->keys[i], key, sizeof(t)); \ hash->values[i] = value; \ } \ - void *hash_search_ ## t (const hash_ ##t *hash, const t *key) { \ + static inline void *hash_search_ ## t (const hash_ ##t *hash, const t *key) { \ uint32_t i = hash_modulo_ ## t(hash_function_ ## t(key)); \ for(uint8_t f=0; fkeys[i], sizeof(t))) { \ @@ -64,7 +64,7 @@ uint32_t modulo(uint32_t hash, size_t n); } \ return NULL; \ } \ - void hash_delete_ ## t (hash_ ##t *hash, const t *key) { \ + static inline void hash_delete_ ## t (hash_ ##t *hash, const t *key) { \ uint32_t i = hash_modulo_ ## t(hash_function_ ## t(key)); \ for(uint8_t f=0; fkeys[i], sizeof(t))) { \ @@ -74,7 +74,7 @@ uint32_t modulo(uint32_t hash, size_t n); if(++i == n) i = 0; \ } \ } \ - void hash_clear_ ## t(hash_ ##t *hash) { \ + static inline void hash_clear_ ## t(hash_ ##t *hash) { \ memset(hash->values, 0, n * sizeof(*hash->values)); \ memset(hash->keys, 0, n * sizeof(*hash->keys)); \ }