From 11177572bc8635d38409232e36c6a29447cd6508 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 1 Jun 2009 15:05:33 -0700 Subject: [PATCH] hash: New convenience function hash_string() for hashing a string. --- lib/hash.h | 6 ++++++ lib/shash.c | 2 +- vswitchd/proc-net-compat.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/hash.h b/lib/hash.h index e1393ddf..0dabb439 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -35,6 +35,7 @@ #include #include +#include /* This is the public domain lookup3 hash by Bob Jenkins from * http://burtleburtle.net/bob/c/lookup3.c, modified for style. */ @@ -65,4 +66,9 @@ uint32_t hash_words(const uint32_t *, size_t n_word, uint32_t basis); uint32_t hash_bytes(const void *, size_t n_bytes, uint32_t basis); +static inline uint32_t hash_string(const char *s, uint32_t basis) +{ + return hash_bytes(s, strlen(s), basis); +} + #endif /* hash.h */ diff --git a/lib/shash.c b/lib/shash.c index 84485888..e4c9f1eb 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -39,7 +39,7 @@ static size_t hash_name(const char *name) { - return hash_bytes(name, strlen(name), 0); + return hash_string(name, 0); } void diff --git a/vswitchd/proc-net-compat.c b/vswitchd/proc-net-compat.c index 848fbd70..a5b86ea8 100644 --- a/vswitchd/proc-net-compat.c +++ b/vswitchd/proc-net-compat.c @@ -296,7 +296,7 @@ remove_tagged_dev(struct shash_node *node, const char *tagged_dev) static uint32_t hash_vlan(const char *trunk_dev, uint32_t vid) { - return hash_words(&vid, 1, hash_bytes(trunk_dev, strlen(trunk_dev), 0)); + return hash_words(&vid, 1, hash_string(trunk_dev, 0)); } /* Update /proc/net/vlan/ for 'vlan'. */ -- 2.30.2