summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-10-01 13:59:48 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2010-10-01 13:59:48 +0000
commit255895a58b3f2a54fecf971da700caf265b4e1f0 (patch)
tree6f8f7a3d6249d667c51c83b8dbe582fb1ba71010 /runtime
parent9696cdef34f5d033564138fb9d4afb87daa6b1be (diff)
downloadrsyslog-255895a58b3f2a54fecf971da700caf265b4e1f0.tar.gz
rsyslog-255895a58b3f2a54fecf971da700caf265b4e1f0.tar.xz
rsyslog-255895a58b3f2a54fecf971da700caf265b4e1f0.zip
omhdfs: more improvements
finally this looks almost production ready for files where no directory path needs to be created
Diffstat (limited to 'runtime')
-rw-r--r--runtime/hashtable.h3
-rw-r--r--runtime/hashtable/hashtable.c17
-rw-r--r--runtime/hashtable/hashtable_private.h1
3 files changed, 17 insertions, 4 deletions
diff --git a/runtime/hashtable.h b/runtime/hashtable.h
index 0f980127..f777ad0b 100644
--- a/runtime/hashtable.h
+++ b/runtime/hashtable.h
@@ -68,13 +68,14 @@ struct hashtable;
* @param minsize minimum initial size of hashtable
* @param hashfunction function for hashing keys
* @param key_eq_fn function for determining key equality
+ * @param dest destructor for value entries (NULL -> use free())
* @return newly created hashtable or NULL on failure
*/
struct hashtable *
create_hashtable(unsigned int minsize,
unsigned int (*hashfunction) (void*),
- int (*key_eq_fn) (void*,void*));
+ int (*key_eq_fn) (void*,void*), void (*dest) (void*));
/*****************************************************************************
* hashtable_insert
diff --git a/runtime/hashtable/hashtable.c b/runtime/hashtable/hashtable.c
index e2a2b3f4..41fc60fe 100644
--- a/runtime/hashtable/hashtable.c
+++ b/runtime/hashtable/hashtable.c
@@ -29,7 +29,7 @@ const float max_load_factor = 0.65;
struct hashtable *
create_hashtable(unsigned int minsize,
unsigned int (*hashf) (void*),
- int (*eqf) (void*,void*))
+ int (*eqf) (void*,void*), void (*dest)(void*))
{
struct hashtable *h;
unsigned int pindex, size = primes[0];
@@ -49,6 +49,7 @@ create_hashtable(unsigned int minsize,
h->entrycount = 0;
h->hashfn = hashf;
h->eqfn = eqf;
+ h->dest = dest;
h->loadlimit = (unsigned int) ceil(size * max_load_factor);
return h;
}
@@ -225,7 +226,16 @@ hashtable_destroy(struct hashtable *h, int free_values)
{
e = table[i];
while (NULL != e)
- { f = e; e = e->next; freekey(f->k); free(f->v); free(f); }
+ {
+ f = e;
+ e = e->next;
+ freekey(f->k);
+ if(h->dest == NULL)
+ free(f->v);
+ else
+ h->dest(f->v);
+ free(f);
+ }
}
}
else
@@ -264,7 +274,8 @@ hash_from_string(void *k)
int
key_equals_string(void *key1, void *key2)
{
- return strcmp(key1, key2);
+ /* we must return true IF the keys are equal! */
+ return !strcmp(key1, key2);
}
diff --git a/runtime/hashtable/hashtable_private.h b/runtime/hashtable/hashtable_private.h
index 3e95f600..10b82da4 100644
--- a/runtime/hashtable/hashtable_private.h
+++ b/runtime/hashtable/hashtable_private.h
@@ -21,6 +21,7 @@ struct hashtable {
unsigned int primeindex;
unsigned int (*hashfn) (void *k);
int (*eqfn) (void *k1, void *k2);
+ void (*dest) (void *v); /* destructor for values, if NULL use free() */
};
/*****************************************************************************/