X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fq.c;h=9f7ce2c5384e6e9f4ceb7ebedfd1d323845876a2;hp=a2d7a63a989d06bf98efdfdd8bd578a439c4fe6e;hb=c63b2bf21dc1df9a736f0b4c08f6cba828cdab92;hpb=2391d7ae5d8a145a250a8b80ab8c93ba74eba030 diff --git a/lib/q.c b/lib/q.c index a2d7a63..9f7ce2c 100644 --- a/lib/q.c +++ b/lib/q.c @@ -688,6 +688,18 @@ unsigned int crc32_add_string(unsigned int checksum, const char*s) } return checksum; } +unsigned int crc32_add_bytes(unsigned int checksum, const void*_s, int len) +{ + unsigned char*s = (unsigned char*)_s; + crc32_init(); + if(!s || !len) + return checksum; + do { + checksum = checksum>>8 ^ crc32[(*s^checksum)&0xff]; + s++; + } while(--len); + return checksum; +} unsigned int string_hash(const string_t*str) { @@ -887,6 +899,23 @@ void ptr_free(void*o) return; } +char int_equals(const void*o1, const void*o2) +{ + return o1==o2; +} +unsigned int int_hash(const void*o) +{ + return string_hash3((const char*)&o, sizeof(o)); +} +void* int_dup(const void*o) +{ + return (void*)o; +} +void int_free(void*o) +{ + return; +} + char charptr_equals(const void*o1, const void*o2) { if(!o1 || !o2) @@ -952,6 +981,13 @@ void stringstruct_free(void*o) string_free(o); } +type_t int_type = { + equals: int_equals, + hash: int_hash, + dup: int_dup, + free: int_free, +}; + type_t ptr_type = { equals: ptr_equals, hash: ptr_hash, @@ -1302,6 +1338,51 @@ void dict_destroy(dict_t*dict) rfx_free(dict); } +// ------------------------------- mtf_t -------------------------------------- +mtf_t* mtf_new(type_t*type) +{ + NEW(mtf_t, mtf); + mtf->type = type; + return mtf; +} +void mtf_increase(mtf_t*m, const void*key) +{ + mtf_item_t*item = m->first; + mtf_item_t*last = 0; + while(item) { + if(m->type->equals(item->key, key)) { + item->num++; + if(item->num>m->first->num) { + if(last) last->next = item->next; + else m->first = item->next; + item->next = m->first; + m->first = item; + } + return; + } + last = item; + item = item->next; + } + NEW(mtf_item_t,n); + if(last) last->next = n; + else m->first = n; + n->key = key; + n->num = 1; +} +void mtf_destroy(mtf_t*m) +{ + if(!m) return; + mtf_item_t*item = m->first; + m->first = 0; + while(item) { + mtf_item_t*next = item->next; + item->next = 0; + free(item); + item = next; + } + free(m); +} + // ------------------------------- map_t -------------------------------------- typedef struct _map_internal_t