1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

cleanup: better expressing passing key arg to _hash

This commit is contained in:
Zdenek Kabelac 2020-08-29 22:37:17 +02:00
parent 4baedfc578
commit 1ff1e86deb
2 changed files with 10 additions and 8 deletions

View File

@ -59,26 +59,27 @@ static unsigned char _nums[] = {
209 209
}; };
static struct dm_hash_node *_create_node(const char *str, unsigned len) static struct dm_hash_node *_create_node(const void *key, unsigned len)
{ {
struct dm_hash_node *n = malloc(sizeof(*n) + len); struct dm_hash_node *n = malloc(sizeof(*n) + len);
if (n) { if (n) {
memcpy(n->key, str, len); memcpy(n->key, key, len);
n->keylen = len; n->keylen = len;
} }
return n; return n;
} }
static unsigned long _hash(const char *str, unsigned len) static unsigned long _hash(const void *key, unsigned len)
{ {
const unsigned char *str = key;
unsigned long h = 0, g; unsigned long h = 0, g;
unsigned i; unsigned i;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
h <<= 4; h <<= 4;
h += _nums[(unsigned char) *str++]; h += _nums[*str++];
g = h & ((unsigned long) 0xf << 16u); g = h & ((unsigned long) 0xf << 16u);
if (g) { if (g) {
h ^= g >> 16u; h ^= g >> 16u;

View File

@ -57,26 +57,27 @@ static unsigned char _nums[] = {
209 209
}; };
static struct dm_hash_node *_create_node(const char *str, unsigned len) static struct dm_hash_node *_create_node(const void *key, unsigned len)
{ {
struct dm_hash_node *n = dm_malloc(sizeof(*n) + len); struct dm_hash_node *n = dm_malloc(sizeof(*n) + len);
if (n) { if (n) {
memcpy(n->key, str, len); memcpy(n->key, key, len);
n->keylen = len; n->keylen = len;
} }
return n; return n;
} }
static unsigned long _hash(const char *str, unsigned len) static unsigned long _hash(const void *key, unsigned len)
{ {
const unsigned char *str = key;
unsigned long h = 0, g; unsigned long h = 0, g;
unsigned i; unsigned i;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
h <<= 4; h <<= 4;
h += _nums[(unsigned char) *str++]; h += _nums[*str++];
g = h & ((unsigned long) 0xf << 16u); g = h & ((unsigned long) 0xf << 16u);
if (g) { if (g) {
h ^= g >> 16u; h ^= g >> 16u;