summaryrefslogtreecommitdiff
path: root/src/post/goom/goom_hash.c
diff options
context:
space:
mode:
authorMichael Roitzsch <mroi@users.sourceforge.net>2004-06-27 11:58:47 +0000
committerMichael Roitzsch <mroi@users.sourceforge.net>2004-06-27 11:58:47 +0000
commit90f730ca714fb53f47ee16be46fcb06bd98d53ed (patch)
treec028f9afa30ec4137501fdada9c6ef1130daf2fb /src/post/goom/goom_hash.c
parent29f04d913513a470bc91aff3e6c0fca699e460f8 (diff)
downloadxine-lib-90f730ca714fb53f47ee16be46fcb06bd98d53ed.tar.gz
xine-lib-90f730ca714fb53f47ee16be46fcb06bd98d53ed.tar.bz2
include the new goom version 2k4-dev15
everybody: test, test, test CVS patchset: 6756 CVS date: 2004/06/27 11:58:47
Diffstat (limited to 'src/post/goom/goom_hash.c')
-rw-r--r--src/post/goom/goom_hash.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/post/goom/goom_hash.c b/src/post/goom/goom_hash.c
new file mode 100644
index 000000000..09052ed90
--- /dev/null
+++ b/src/post/goom/goom_hash.c
@@ -0,0 +1,100 @@
+#include "goom_hash.h"
+#include <string.h>
+#include <stdlib.h>
+
+static GoomHashEntry *entry_new(const char *key, HashValue value) {
+
+ GoomHashEntry *entry = (GoomHashEntry*)malloc(sizeof(GoomHashEntry));
+
+ entry->key = (char *)malloc(strlen(key)+1);
+ strcpy(entry->key,key);
+ entry->value = value;
+ entry->lower = NULL;
+ entry->upper = NULL;
+
+ return entry;
+}
+
+static void entry_free(GoomHashEntry *entry) {
+ if (entry!=NULL) {
+ entry_free(entry->lower);
+ entry_free(entry->upper);
+ free(entry->key);
+ free(entry);
+ }
+}
+
+static void entry_put(GoomHashEntry *entry, const char *key, HashValue value) {
+ int cmp = strcmp(key,entry->key);
+ if (cmp==0) {
+ entry->value = value;
+ }
+ else if (cmp > 0) {
+ if (entry->upper == NULL)
+ entry->upper = entry_new(key,value);
+ else
+ entry_put(entry->upper, key, value);
+ }
+ else {
+ if (entry->lower == NULL)
+ entry->lower = entry_new(key,value);
+ else
+ entry_put(entry->lower, key, value);
+ }
+}
+
+static HashValue *entry_get(GoomHashEntry *entry, const char *key) {
+
+ int cmp;
+ if (entry==NULL)
+ return NULL;
+ cmp = strcmp(key,entry->key);
+ if (cmp > 0)
+ return entry_get(entry->upper, key);
+ else if (cmp < 0)
+ return entry_get(entry->lower, key);
+ else
+ return &(entry->value);
+}
+
+GoomHash *goom_hash_new() {
+ GoomHash *_this = (GoomHash*)malloc(sizeof(GoomHash));
+ _this->root = NULL;
+ return _this;
+}
+
+void goom_hash_free(GoomHash *_this) {
+ entry_free(_this->root);
+ free(_this);
+}
+
+void goom_hash_put(GoomHash *_this, const char *key, HashValue value) {
+ if (_this->root == NULL)
+ _this->root = entry_new(key,value);
+ else
+ entry_put(_this->root,key,value);
+}
+
+HashValue *goom_hash_get(GoomHash *_this, const char *key) {
+ return entry_get(_this->root,key);
+}
+
+void goom_hash_put_int(GoomHash *_this, const char *key, int i) {
+ HashValue value;
+ value.i = i;
+ goom_hash_put(_this,key,value);
+}
+
+void goom_hash_put_float(GoomHash *_this, const char *key, float f) {
+ HashValue value;
+ value.f = f;
+ goom_hash_put(_this,key,value);
+}
+
+void goom_hash_put_ptr(GoomHash *_this, const char *key, void *ptr) {
+ HashValue value;
+ value.ptr = ptr;
+ goom_hash_put(_this,key,value);
+}
+
+