+ while(e) {
+ int index = ((int)(ptroff_t)e->data) - 1;
+ if(h->key_type->equals(e->key, name) && array->d[index].data == data) {
+ return index;
+ }
+ e = e->next;
+ }
+ return -1;
+}
+int array_update(array_t*array, const void*name, void*data) {
+ int pos = array_find(array, name);
+ if(pos>=0) {
+ array->d[pos].data = data;
+ return pos;
+ }
+ return array_append(array, name, data);
+}
+int array_append_if_new(array_t*array, const void*name, void*data) {
+ int pos = array_find(array, name);
+ if(pos>=0)
+ return pos;
+ return array_append(array, name, data);
+}
+void array_free(array_t*array) {
+ dict_destroy(array->entry2pos);
+ if(array->d) {
+ free(array->d);array->d = 0;
+ }
+ free(array);
+}
+
+// ------------------------------- list_t --------------------------------------
+
+struct _commonlist;
+typedef struct _listinfo {
+ int size;
+ struct _commonlist*last;
+} listinfo_t;
+
+typedef struct _commonlist {
+ void*entry;
+ struct _commonlist*next;
+ listinfo_t info[0];
+} commonlist_t;
+
+int list_length_(void*_list)
+{
+ commonlist_t*l = (commonlist_t*)_list;
+ if(!l)
+ return 0;
+ return l->info[0].size;
+}
+void list_append_(void*_list, void*entry)
+{
+ commonlist_t**list = (commonlist_t**)_list;
+ commonlist_t* n = 0;
+ if(!*list) {
+ n = malloc(sizeof(commonlist_t)+sizeof(listinfo_t));
+ *list = n;
+ (*list)->info[0].size = 0;
+ } else {
+ n = malloc(sizeof(commonlist_t));
+ (*list)->info[0].last->next = n;
+ }
+ n->next = 0;
+ n->entry = entry;
+ (*list)->info[0].last = n;
+ (*list)->info[0].size++;
+}
+void list_free_(void*_list)
+{
+ commonlist_t**list = (commonlist_t**)_list;
+ commonlist_t*l = *list;
+ while(l) {
+ commonlist_t*next = l->next;
+ free(l);
+ l = next;
+ }
+ *list = 0;
+}
+void*list_clone_(void*_list)
+{
+ commonlist_t*l = *(commonlist_t**)_list;
+
+ void*dest = 0;
+ while(l) {
+ commonlist_t*next = l->next;
+ list_append_(&dest, l->entry);
+ l = next;
+ }
+ return dest;
+
+}