From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=32917 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOsAB-00014Y-0p for qemu-devel@nongnu.org; Wed, 16 Jun 2010 08:56:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OOrv9-0001ed-JB for qemu-devel@nongnu.org; Wed, 16 Jun 2010 08:40:44 -0400 Received: from e23smtp05.au.ibm.com ([202.81.31.147]:57157) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOrv9-0001eC-2K for qemu-devel@nongnu.org; Wed, 16 Jun 2010 08:40:43 -0400 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp05.au.ibm.com (8.14.4/8.13.1) with ESMTP id o5GCaaZY008444 for ; Wed, 16 Jun 2010 22:36:36 +1000 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5GCefcl1642604 for ; Wed, 16 Jun 2010 22:40:41 +1000 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o5GCee6V016179 for ; Wed, 16 Jun 2010 22:40:41 +1000 Date: Wed, 16 Jun 2010 18:10:36 +0530 From: Prerna Saxena Message-ID: <20100616181036.5c866658@zephyr> In-Reply-To: <20100616180542.474535e3@zephyr> References: <20100616180542.474535e3@zephyr> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH 1/3] Export hash function List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Prerna Saxena Cc: Anthony Liguori , Hajnoczi , kvm@vger.kernel.org, qemu-devel@nongnu.org, Capitulino , Luiz@gnu.org, Maneesh Soni , Stefan@us.ibm.com Rename tdb_hash() to qemu_hash(). Move definition from qdict.c to a new file qemu-misc.c for use by tracing infrastructure. Signed-off-by: Prerna Saxena --- Makefile.objs | 2 +- qdict.c | 24 ++++-------------------- qemu-common.h | 3 +++ qemu-misc.c | 24 ++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 qemu-misc.c diff --git a/Makefile.objs b/Makefile.objs index 7cb40ac..53e3a65 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -1,6 +1,6 @@ ####################################################################### # QObject -qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o +qobject-obj-y = qint.o qstring.o qdict.o qemu-misc.o qlist.o qfloat.o qbool.o qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o qobject-obj-y += qerror.o diff --git a/qdict.c b/qdict.c index 175bc17..d4588ef 100644 --- a/qdict.c +++ b/qdict.c @@ -53,22 +53,6 @@ QDict *qobject_to_qdict(const QObject *obj) } /** - * tdb_hash(): based on the hash agorithm from gdbm, via tdb - * (from module-init-tools) - */ -static unsigned int tdb_hash(const char *name) -{ - unsigned value; /* Used to compute the hash value. */ - unsigned i; /* Used to cycle through random values. */ - - /* Set the initial value from the key size. */ - for (value = 0x238F13AF * strlen(name), i=0; name[i]; i++) - value = (value + (((const unsigned char *)name)[i] << (i*5 % 24))); - - return (1103515243 * value + 12345); -} - -/** * alloc_entry(): allocate a new QDictEntry */ static QDictEntry *alloc_entry(const char *key, QObject *value) @@ -113,7 +97,7 @@ void qdict_put_obj(QDict *qdict, const char *key, QObject *value) unsigned int hash; QDictEntry *entry; - hash = tdb_hash(key) % QDICT_HASH_SIZE; + hash = qemu_hash(key) % QDICT_HASH_SIZE; entry = qdict_find(qdict, key, hash); if (entry) { /* replace key's value */ @@ -137,7 +121,7 @@ QObject *qdict_get(const QDict *qdict, const char *key) { QDictEntry *entry; - entry = qdict_find(qdict, key, tdb_hash(key) % QDICT_HASH_SIZE); + entry = qdict_find(qdict, key, qemu_hash(key) % QDICT_HASH_SIZE); return (entry == NULL ? NULL : entry->value); } @@ -148,7 +132,7 @@ QObject *qdict_get(const QDict *qdict, const char *key) */ int qdict_haskey(const QDict *qdict, const char *key) { - unsigned int hash = tdb_hash(key) % QDICT_HASH_SIZE; + unsigned int hash = qemu_hash(key) % QDICT_HASH_SIZE; return (qdict_find(qdict, key, hash) == NULL ? 0 : 1); } @@ -347,7 +331,7 @@ void qdict_del(QDict *qdict, const char *key) { QDictEntry *entry; - entry = qdict_find(qdict, key, tdb_hash(key) % QDICT_HASH_SIZE); + entry = qdict_find(qdict, key, qemu_hash(key) % QDICT_HASH_SIZE); if (entry) { QLIST_REMOVE(entry, next); qentry_destroy(entry); diff --git a/qemu-common.h b/qemu-common.h index a4888e5..d225e45 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -17,6 +17,9 @@ typedef struct QEMUTimer QEMUTimer; typedef struct QEMUFile QEMUFile; typedef struct QEMUBH QEMUBH; +/* Hash function definition */ +unsigned int qemu_hash(const char *name); + /* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that cannot include the following headers without conflicts. This condition has to be removed once dyngen is gone. */ diff --git a/qemu-misc.c b/qemu-misc.c new file mode 100644 index 0000000..a69196a --- /dev/null +++ b/qemu-misc.c @@ -0,0 +1,24 @@ +/* + * Definition of tdb_hash() moved here, from qdict.c. Renamed to qemu_hash() + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ +#include "qemu-common.h" + +/** + * tdb_hash(): based on the hash agorithm from gdbm, via tdb + * (from module-init-tools). Renamed to qemu_hash(). + */ +unsigned int qemu_hash(const char *name) +{ + unsigned value; /* Used to compute the hash value. */ + unsigned i; /* Used to cycle through random values. */ + + /* Set the initial value from the key size. */ + for (value = 0x238F13AF * strlen(name), i=0; name[i]; i++) + value = (value + (((const unsigned char *)name)[i] << (i*5 % 24))); + + return (1103515243 * value + 12345); +} -- Prerna Saxena Linux Technology Centre, IBM Systems and Technology Lab, Bangalore, India