X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fq.h;h=997b470be52ec0172a42347cb136795efa4183c3;hb=3dea7306ae2c9590673c10dec1fbabcd6d7e1806;hp=3cf8cbef2ed54534b13bac84fa593ec6dbd6b224;hpb=514edfe0ed692a226002388f6de8100beb28f90f;p=swftools.git diff --git a/lib/q.h b/lib/q.h index 3cf8cbe..997b470 100644 --- a/lib/q.h +++ b/lib/q.h @@ -110,8 +110,7 @@ typedef struct _stringarray_t } stringarray_t; /* heap */ -typedef struct _heap -{ +typedef struct _heap { void**elements; char*data; int elem_size; @@ -120,11 +119,17 @@ typedef struct _heap int(*compare)(const void *, const void *); } heap_t; -typedef struct _trie { - struct _trie*row[256]; +/* trie (with rollback) */ +typedef struct _trielayer { + struct _trielayer*row[256]; unsigned char*rest; -} trie_t; + void*data; +} trielayer_t; +typedef struct _trie { + trielayer_t* start; + void*rollback; +} trie_t; char* strdup_n(const char*str, int size); @@ -174,6 +179,7 @@ void stringarray_destroy(stringarray_t*sa); dict_t*dict_new(); dict_t*dict_new2(type_t*type); void dict_init(dict_t*dict, int size); +void dict_init2(dict_t*dict, type_t*type, int size); dictentry_t*dict_put(dict_t*h, const void*key, void* data); void dict_put2(dict_t*h, const char*s, void*data); int dict_count(dict_t*h); @@ -210,8 +216,14 @@ void* heap_chopmax(heap_t*h); void heap_dump(heap_t*h, FILE*fi); void** heap_flatten(heap_t*h); -void trie_put(trie_t**t, unsigned const char*id); -int trie_lookup(trie_t*t, unsigned const char*id); +trie_t*trie_new(); +void trie_put(trie_t*t, unsigned const char*id, void*data); +char trie_remove(trie_t*t, unsigned const char*id); +void*trie_lookup(trie_t*t, unsigned const char*id); +int trie_contains(trie_t*t, unsigned const char*id); +void trie_remember(trie_t*t); +void trie_rollback(trie_t*t); +void trie_dump(trie_t*t); array_t* array_new(); array_t* array_new2(type_t*type); @@ -246,7 +258,7 @@ void list_concat_(void*l1, void*l2); #define list_prepend(list, e) {sizeof((list)->next);list_prepend_(&(list),(e));} #define list_free(list) {sizeof((list)->next);list_free_(&(list));} #define list_deep_free(list) {sizeof((list)->next);list_deep_free_(&(list));} -#define list_clone(list) (sizeof((list)->next),list_clone_(&(list))) +#define list_clone(list) (sizeof((list)->next),(list?list_clone_(&(list)):0)) #define list_length(list) (sizeof((list)->next),list_length_(list)) #ifdef __cplusplus