X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fq.c;h=0b19aa96f2b612c84cc2d3cbf3e9ffb76b2ba2eb;hb=b49af457d8554794e1550e3051a4fcd67a965d8a;hp=5a9cf7d8b20dbba427d5d287c88985471cc7451e;hpb=3bda5a775df240e8fee97922db4e3fe482d8ecc3;p=swftools.git diff --git a/lib/q.c b/lib/q.c index 5a9cf7d..0b19aa9 100644 --- a/lib/q.c +++ b/lib/q.c @@ -619,6 +619,27 @@ void dict_init(dict_t*h, int size) h->key_type = &charptr_type; } +dict_t*dict_clone(dict_t*o) +{ + dict_t*h = rfx_alloc(sizeof(dict_t)); + memcpy(h, o, sizeof(dict_t)); + h->slots = h->hashsize?(dictentry_t**)rfx_calloc(sizeof(dictentry_t*)*h->hashsize):0; + int t; + for(t=0;thashsize;t++) { + dictentry_t*e = o->slots[t]; + while(e) { + dictentry_t*n = (dictentry_t*)rfx_alloc(sizeof(dictentry_t)); + memcpy(n, e, sizeof(dictentry_t)); + n->key = h->key_type->dup(e->key); + n->data = e->data; + n->next = h->slots[t]; + h->slots[t] = n; + e = e->next; + } + } + return h; +} + static void dict_expand(dict_t*h, int newlen) { assert(h->hashsize < newlen); @@ -746,7 +767,7 @@ char dict_del(dict_t*h, const void*key) return 0; } -static dictentry_t* dict_get_slot(dict_t*h, const void*key) +dictentry_t* dict_get_slot(dict_t*h, const void*key) { if(!h->num) return 0; @@ -799,6 +820,7 @@ void dict_free_all(dict_t*h, void (*freeFunction)(void*)) rfx_free(e); e = next; } + h->slots[t]=0; } rfx_free(h->slots); memset(h, 0, sizeof(dict_t));