new function list_concat
[swftools.git] / lib / q.c
diff --git a/lib/q.c b/lib/q.c
index a53994a..3b9a62f 100644 (file)
--- a/lib/q.c
+++ b/lib/q.c
@@ -800,10 +800,12 @@ int dict_count(dict_t*h)
     return h->num;
 }
 
-void* dict_lookup(dict_t*h, const void*key)
+void dict_do_lookup(dict_t*h, const void*key, void***match)
 {
-    if(!h->num)
-        return 0;
+    if(!h->num) {
+        *match = 0;
+        return;
+    }
     
     unsigned int ohash = h->key_type->hash(key);
     unsigned int hash = ohash % h->hashsize;
@@ -811,7 +813,8 @@ void* dict_lookup(dict_t*h, const void*key)
     /* check first entry for match */
     dictentry_t*e = h->slots[hash];
     if(e && h->key_type->equals(e->key, key)) {
-        return e->data;
+        *match = &e->data;
+        return;
     } else if(e) {
         e = e->next;
     }
@@ -832,12 +835,28 @@ void* dict_lookup(dict_t*h, const void*key)
     /* check subsequent entries for a match */
     while(e) {
         if(h->key_type->equals(e->key, key)) {
-            return e->data;
+            *match = &e->data;
+            return;
         }
         e = e->next;
     }
+    *match = 0;
+}
+void* dict_lookup(dict_t*h, const void*key)
+{
+    void**data = 0;
+    dict_do_lookup(h, key, &data);
+    if(data)
+        return *data;
     return 0;
 }
+char dict_contains(dict_t*h, const void*key)
+{
+    void**data = 0;
+    dict_do_lookup(h, key, &data);
+    return !!data;
+}
+
 char dict_del(dict_t*h, const void*key)
 {
     if(!h->num)
@@ -1103,6 +1122,20 @@ int list_length_(void*_list)
         return 0;
     return l->info[0].size;
 }
+void list_concat_(void*_l1, void*_l2)
+{
+    commonlist_t**l1 = (commonlist_t**)_l1;
+    commonlist_t**l2 = (commonlist_t**)_l2;
+
+    if(!*l1) {
+        *l1 = *l2;
+    } else if(*l2) {
+        (*l1)->info[0].last->next = *l2;
+        (*l1)->info[0].last = (*l2)->info[0].last;
+        (*l1)->info[0].size += (*l2)->info[0].size;
+    }
+    *l2 = 0;
+}
 void list_append_(void*_list, void*entry)
 {
     commonlist_t**list = (commonlist_t**)_list;