X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fq.h;h=d7cd3c8830ca0c422c99f9fa56454a3c81a694b4;hb=210871fb25129505f89062549560543181f9f2f2;hp=fbc6d194b8f5753eea1d8576f59028d535ba35c5;hpb=fd9b29867f4b4ad5d1ea71eb12145b2020604328;p=swftools.git diff --git a/lib/q.h b/lib/q.h index fbc6d19..d7cd3c8 100644 --- a/lib/q.h +++ b/lib/q.h @@ -53,20 +53,24 @@ typedef struct _map_t { void*internal; } map_t; -/* (void*)s referenced by strings */ typedef struct _dictentry { const char*s; + int len; + unsigned int hash; void*data; struct _dictentry*next; } dictentry_t; +/* (void*) pointers referenced by strings */ typedef struct _dict { dictentry_t**slots; int hashsize; int num; } dict_t; -/* array of strings */ +/* array of strings, string<->int mapping, + with O(1) for int->string lookup and + ~O(n/hashsize) for string->int lookup */ typedef struct _stringarray_t { void*internal; @@ -98,6 +102,7 @@ string_t string_new(const char*text, int len); string_t string_new2(const char*text); unsigned int string_hash(string_t*str); unsigned int string_hash2(const char*str); +unsigned int string_hash3(const char*str, int len); void string_set(string_t*str, const char*text); void string_set2(string_t*str, const char*text, int len); void string_dup(string_t*str, const char*text); @@ -112,27 +117,30 @@ int stringarray_find(stringarray_t*sa, string_t*str); void stringarray_clear(stringarray_t*sa); void stringarray_destroy(stringarray_t*sa); -void map_init(map_t*map); -void map_put(map_t*map, string_t t1, string_t t2); -const char* map_lookup(map_t*map, const char*name); -void map_dump(map_t*map, FILE*fi, const char*prefix); -void map_clear(map_t*map); -void map_destroy(map_t*map); - dict_t*dict_new(); void dict_init(dict_t*dict); void dict_put(dict_t*dict, string_t t1, void* t2); void dict_put2(dict_t*dict, const char* t1, void* t2); +void dict_put3(dict_t*dict, const char* t1, int len, void* t2); + stringarray_t* dict_index(dict_t*dict); int dict_count(dict_t* dict); void* dict_lookup(dict_t*dict, const char*name); void dict_dump(dict_t*dict, FILE*fi, const char*prefix); char dict_del(dict_t*dict, const char* name); +void dict_foreach_keyvalue(dict_t*h, void (*runFunction)(void*data, const char*key, void*val), void*data); void dict_foreach_value(dict_t*h, void (*runFunction)(void*)); void dict_free_all(dict_t*h, void (*freeFunction)(void*)); void dict_clear(dict_t*dict); void dict_destroy(dict_t*dict); +void map_init(map_t*map); +void map_put(map_t*map, string_t t1, string_t t2); +const char* map_lookup(map_t*map, const char*name); +void map_dump(map_t*map, FILE*fi, const char*prefix); +void map_clear(map_t*map); +void map_destroy(map_t*map); + void heap_init(heap_t*h,int n,int elem_size, int(*compare)(const void *, const void *)); void heap_clear(heap_t*h); void heap_put(heap_t*h, void*e);