From patchwork Wed Jun 16 12:40:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prerna Saxena X-Patchwork-Id: 106484 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5GCekmo000330 for ; Wed, 16 Jun 2010 12:40:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755501Ab0FPMko (ORCPT ); Wed, 16 Jun 2010 08:40:44 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:60598 "EHLO e23smtp01.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754920Ab0FPMkn (ORCPT ); Wed, 16 Jun 2010 08:40:43 -0400 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp01.au.ibm.com (8.14.4/8.13.1) with ESMTP id o5GCc9qU003172 for ; Wed, 16 Jun 2010 22:38:09 +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 o5GCefAf1433620 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 o5GCee6b016179 for ; Wed, 16 Jun 2010 22:40:41 +1000 Received: from zephyr (K50wks273870wss.in.ibm.com [9.124.35.32]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o5GCecNP016140; Wed, 16 Jun 2010 22:40:39 +1000 Date: Wed, 16 Jun 2010 18:10:36 +0530 From: Prerna Saxena To: Prerna Saxena Cc: qemu-devel@nongnu.org, Anthony Liguori , Hajnoczi , kvm@vger.kernel.org, Stefan@us.ibm.com, Luiz Capitulino , Maneesh Soni Subject: [PATCH 1/3] Export hash function Message-ID: <20100616181036.5c866658@zephyr> In-Reply-To: <20100616180542.474535e3@zephyr> References: <20100616180542.474535e3@zephyr> Organization: IBM X-Mailer: Claws Mail 3.7.5 (GTK+ 2.16.6; i586-redhat-linux-gnu) Mime-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 16 Jun 2010 12:40:46 +0000 (UTC) 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); +}