All of lore.kernel.org
 help / color / mirror / Atom feed
From: Prerna Saxena <prerna@linux.vnet.ibm.com>
To: Prerna Saxena <prerna@linux.vnet.ibm.com>
Cc: qemu-devel@nongnu.org, Anthony Liguori <aliguori@us.ibm.com>,
	Hajnoczi <stefanha@linux.vnet.ibm.com>,
	kvm@vger.kernel.org, Stefan@us.ibm.com,
	Luiz Capitulino <lcapitulino@redhat.com>,
	Maneesh Soni <maneesh@linux.vnet.ibm.com>
Subject: [PATCH 1/3] Export hash function
Date: Wed, 16 Jun 2010 18:10:36 +0530	[thread overview]
Message-ID: <20100616181036.5c866658@zephyr> (raw)
In-Reply-To: <20100616180542.474535e3@zephyr>

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 <prerna@linux.vnet.ibm.com>
---

 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


WARNING: multiple messages have this Message-ID (diff)
From: Prerna Saxena <prerna@linux.vnet.ibm.com>
To: Prerna Saxena <prerna@linux.vnet.ibm.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	Hajnoczi <stefanha@linux.vnet.ibm.com>,
	kvm@vger.kernel.org, qemu-devel@nongnu.org,
	Capitulino <lcapitulino@redhat.com>,
	Luiz@gnu.org, Maneesh Soni <maneesh@linux.vnet.ibm.com>,
	Stefan@us.ibm.com
Subject: [Qemu-devel] [PATCH 1/3] Export hash function
Date: Wed, 16 Jun 2010 18:10:36 +0530	[thread overview]
Message-ID: <20100616181036.5c866658@zephyr> (raw)
In-Reply-To: <20100616180542.474535e3@zephyr>

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 <prerna@linux.vnet.ibm.com>
---

 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

  reply	other threads:[~2010-06-16 12:40 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-16 12:35 [PATCH 0/3] Monitor support QEMU trace framework Prerna Saxena
2010-06-16 12:35 ` [Qemu-devel] " Prerna Saxena
2010-06-16 12:40 ` Prerna Saxena [this message]
2010-06-16 12:40   ` [Qemu-devel] [PATCH 1/3] Export hash function Prerna Saxena
2010-06-16 12:42 ` [PATCH 2/3] Monitor command 'info trace' Prerna Saxena
2010-06-16 12:42   ` [Qemu-devel] " Prerna Saxena
2010-06-17 15:08   ` Stefan Hajnoczi
2010-06-17 15:08     ` [Qemu-devel] " Stefan Hajnoczi
2010-06-18 11:58     ` Prerna Saxena
2010-06-18 11:58       ` [Qemu-devel] " Prerna Saxena
2010-06-18 12:34       ` Stefan Hajnoczi
2010-06-18 12:34         ` [Qemu-devel] " Stefan Hajnoczi
2010-06-16 12:44 ` [PATCH 3/3] Toggle tracepoint state Prerna Saxena
2010-06-16 12:44   ` [Qemu-devel] " Prerna Saxena
2010-06-17 16:03   ` Stefan Hajnoczi
2010-06-17 16:03     ` [Qemu-devel] " Stefan Hajnoczi
2010-06-18 12:24     ` Prerna Saxena
2010-06-18 12:46       ` Stefan Hajnoczi
2010-06-18 12:46         ` Stefan Hajnoczi
2010-06-16 13:50 ` [PATCH 0/3] Monitor support QEMU trace framework Jan Kiszka
2010-06-16 13:50   ` [Qemu-devel] " Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100616181036.5c866658@zephyr \
    --to=prerna@linux.vnet.ibm.com \
    --cc=Stefan@us.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=lcapitulino@redhat.com \
    --cc=maneesh@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.