projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add tests for network commands
[tinc]
/
src
/
hash.h
diff --git
a/src/hash.h
b/src/hash.h
index
45cf641
..
531c663
100644
(file)
--- a/
src/hash.h
+++ b/
src/hash.h
@@
-3,7
+3,7
@@
/*
hash.h -- header file for hash.c
/*
hash.h -- header file for hash.c
- Copyright (C) 2012 Guus Sliepen <guus@tinc-vpn.org>
+ Copyright (C) 2012
-2022
Guus Sliepen <guus@tinc-vpn.org>
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
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,45
+37,46
@@
uint32_t modulo(uint32_t hash, size_t n);
t keys[n]; \
const void *values[n]; \
} hash_ ## t; \
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); \
} \
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++){ \
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))) { \
- memcpy(&hash->keys[i], key, sizeof(
#
t)); \
+ if(hash->values[i] == NULL || !memcmp(key, &hash->keys[i], sizeof(t))) { \
+ memcpy(&hash->keys[i], key, sizeof(t)); \
hash->values[i] = value; \
return; \
} \
if(++i == n) i = 0; \
} \
/* We always pick the last slot. It's unfair. But thats life */ \
hash->values[i] = value; \
return; \
} \
if(++i == n) i = 0; \
} \
/* We always pick the last slot. It's unfair. But thats life */ \
- memcpy(&hash->keys[i], key, sizeof(
#
t)); \
+ memcpy(&hash->keys[i], key, sizeof(t)); \
hash->values[i] = value; \
} \
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; f<HASH_SEARCH_ITERATIONS; f++){ \
uint32_t i = hash_modulo_ ## t(hash_function_ ## t(key)); \
for(uint8_t f=0; f<HASH_SEARCH_ITERATIONS; f++){ \
- if(!memcmp(key, &hash->keys[i], sizeof(
#
t))) { \
+ if(!memcmp(key, &hash->keys[i], sizeof(t))) { \
return (void *)hash->values[i]; \
} \
if(++i == n) i = 0; \
} \
return NULL; \
} \
return (void *)hash->values[i]; \
} \
if(++i == n) i = 0; \
} \
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; f<HASH_SEARCH_ITERATIONS; f++){ \
uint32_t i = hash_modulo_ ## t(hash_function_ ## t(key)); \
for(uint8_t f=0; f<HASH_SEARCH_ITERATIONS; f++){ \
- if(!memcmp(key, &hash->keys[i], sizeof(
#
t))) { \
+ if(!memcmp(key, &hash->keys[i], sizeof(t))) { \
hash->values[i] = NULL; \
return; \
} \
if(++i == n) i = 0; \
} \
} \
hash->values[i] = NULL; \
return; \
} \
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->values, 0, n * sizeof(*hash->values)); \
+ memset(hash->keys, 0, n * sizeof(*hash->keys)); \
}
}