From 3bda5a775df240e8fee97922db4e3fe482d8ecc3 Mon Sep 17 00:00:00 2001 From: kramm Date: Fri, 19 Dec 2008 08:05:49 +0000 Subject: [PATCH] dict_init() now takes a size argument --- lib/q.c | 10 +++++----- lib/q.h | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/q.c b/lib/q.c index 989c47f..5a9cf7d 100644 --- a/lib/q.c +++ b/lib/q.c @@ -600,20 +600,20 @@ static int max(int x, int y) { dict_t*dict_new() { dict_t*d = rfx_alloc(sizeof(dict_t)); - dict_init(d); + dict_init(d, INITIAL_SIZE); return d; } dict_t*dict_new2(type_t*t) { dict_t*d = rfx_alloc(sizeof(dict_t)); - dict_init(d); + dict_init(d, INITIAL_SIZE); d->key_type = t; return d; } -void dict_init(dict_t*h) +void dict_init(dict_t*h, int size) { memset(h, 0, sizeof(dict_t)); - h->hashsize = INITIAL_SIZE; + h->hashsize = size; h->slots = h->hashsize?(dictentry_t**)rfx_calloc(sizeof(dictentry_t*)*h->hashsize):0; h->num = 0; h->key_type = &charptr_type; @@ -827,7 +827,7 @@ void map_init(map_t*map) map_internal_t*m; map->internal = (map_internal_t*)rfx_calloc(sizeof(map_internal_t)); m = (map_internal_t*)map->internal; - dict_init(&m->d); + dict_init(&m->d, INITIAL_SIZE); } void map_put(map_t*map, string_t t1, string_t t2) { diff --git a/lib/q.h b/lib/q.h index 58064f3..26bd051 100644 --- a/lib/q.h +++ b/lib/q.h @@ -156,7 +156,7 @@ void stringarray_destroy(stringarray_t*sa); dict_t*dict_new(); dict_t*dict_new2(type_t*type); -void dict_init(dict_t*dict); +void dict_init(dict_t*dict, int size); dictentry_t*dict_put(dict_t*h, const void*key, void* data); int dict_count(dict_t*h); void dict_dump(dict_t*h, FILE*fi, const char*prefix); @@ -191,10 +191,12 @@ void array_free(array_t*array); void*array_getkey(array_t*array, int nr); void*array_getvalue(array_t*array, int nr); int array_append(array_t*array, const void*name, void*data); +#define array_contains(a,b) (array_find((a),(b))>=0) int array_find(array_t*array, const void*name); int array_find2(array_t*array, const void*name, void*data); int array_update(array_t*array, const void*name, void*data); int array_append_if_new(array_t*array, const void*name, void*data); +#define array_length(a) ((a)->num) #define DECLARE(x) struct _##x;typedef struct _##x x##_t; #define DECLARE_LIST(x) \ -- 1.7.10.4