added ucx_dlist_remove and tests + fixed makefile error

Sun, 15 Jan 2012 14:12:34 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 15 Jan 2012 14:12:34 +0100
changeset 22
76cdd8209f1f
parent 21
d599fefc7620
child 23
ccc294fafb9b

added ucx_dlist_remove and tests + fixed makefile error

test/list_tests.c file | annotate | diff | comparison | revisions
ucx/Makefile file | annotate | diff | comparison | revisions
ucx/dlist.c file | annotate | diff | comparison | revisions
ucx/dlist.h file | annotate | diff | comparison | revisions
ucx/list.c file | annotate | diff | comparison | revisions
     1.1 --- a/test/list_tests.c	Sat Jan 14 13:07:18 2012 +0100
     1.2 +++ b/test/list_tests.c	Sun Jan 15 14:12:34 2012 +0100
     1.3 @@ -119,6 +119,34 @@
     1.4      
     1.5      printf("   TODO: test clone with copy\n");
     1.6  
     1.7 +    ucx_dlist_free(dl);
     1.8 +
     1.9 +    dl = NULL;
    1.10 +    printf("   Test ucx_dlist_remove\n");
    1.11 +    dl = ucx_dlist_append(dl, &v[4]);
    1.12 +    dl = ucx_dlist_append(dl, &v[0]);
    1.13 +    dl = ucx_dlist_append(dl, &v[3]);
    1.14 +    dl = ucx_dlist_remove(dl, dl->next);
    1.15 +    if (ucx_dlist_size(dl) == 2) {
    1.16 +        if ((*((int*)(dl->data)) != 4) || (*((int*)(dl->next->data)) != 3)) {
    1.17 +            fprintf(stderr, "ucx_dlist_remove failed (wrong data)\n");
    1.18 +            r--;
    1.19 +        }
    1.20 +    } else {
    1.21 +        fprintf(stderr, "ucx_dlist_remove failed (wrong size)\n");
    1.22 +        r--;
    1.23 +    }
    1.24 +    dl = ucx_dlist_remove(dl, dl);
    1.25 +    if (ucx_dlist_size(dl) == 1) {
    1.26 +        if ((*((int*)(dl->data)) != 3)) {
    1.27 +            fprintf(stderr, "ucx_dlist_remove first failed (wrong data)\n");
    1.28 +            r--;
    1.29 +        }
    1.30 +    } else {
    1.31 +        fprintf(stderr, "ucx_dlist_remove first failed (wrong size)\n");
    1.32 +        r--;
    1.33 +    }
    1.34 +
    1.35      return r;
    1.36  }
    1.37  
     2.1 --- a/ucx/Makefile	Sat Jan 14 13:07:18 2012 +0100
     2.2 +++ b/ucx/Makefile	Sun Jan 15 14:12:34 2012 +0100
     2.3 @@ -29,7 +29,7 @@
     2.4  include ../$(CONF).mk
     2.5  
     2.6  # list of source files
     2.7 -SRC = list.c dlist.c map.c mempool.c string.o
     2.8 +SRC = list.c dlist.c map.c mempool.c string.c
     2.9  
    2.10  OBJ = $(SRC:%.c=../build/%.$(OBJ_EXT))
    2.11  
     3.1 --- a/ucx/dlist.c	Sat Jan 14 13:07:18 2012 +0100
     3.2 +++ b/ucx/dlist.c	Sun Jan 15 14:12:34 2012 +0100
     3.3 @@ -45,6 +45,7 @@
     3.4      nl->data = data;
     3.5      nl->next = NULL;
     3.6      if (l == NULL) {
     3.7 +        nl->prev = NULL;
     3.8          return nl;
     3.9      } else {
    3.10          UcxDlist *t = ucx_dlist_last(l);
    3.11 @@ -113,9 +114,11 @@
    3.12  
    3.13  void ucx_dlist_foreach(UcxDlist *l, ucx_callback fnc, void* data) {
    3.14      UcxDlist *e = l;
    3.15 +    UcxDlist *n;
    3.16      while (e != NULL) {
    3.17 +        n = e->next;
    3.18          fnc(e, data);
    3.19 -        e = e->next;
    3.20 +        e = n;
    3.21      }
    3.22  }
    3.23  
    3.24 @@ -129,3 +132,15 @@
    3.25      }
    3.26      return e;
    3.27  }
    3.28 +
    3.29 +UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e) {
    3.30 +    if (e->prev == NULL) {
    3.31 +        e->next->prev = NULL;
    3.32 +        l = e->next;
    3.33 +    } else {
    3.34 +        e->prev->next = e->next;
    3.35 +        e->next->prev = e->prev;
    3.36 +    }
    3.37 +    free(e);
    3.38 +    return l;
    3.39 +}
     4.1 --- a/ucx/dlist.h	Sat Jan 14 13:07:18 2012 +0100
     4.2 +++ b/ucx/dlist.h	Sun Jan 15 14:12:34 2012 +0100
     4.3 @@ -33,6 +33,7 @@
     4.4  
     4.5  /* dlist specific functions */
     4.6  UcxDlist *ucx_dlist_first(UcxDlist *l);
     4.7 +UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e);
     4.8  
     4.9  #ifdef	__cplusplus
    4.10  }
     5.1 --- a/ucx/list.c	Sat Jan 14 13:07:18 2012 +0100
     5.2 +++ b/ucx/list.c	Sun Jan 15 14:12:34 2012 +0100
     5.3 @@ -110,8 +110,10 @@
     5.4  
     5.5  void ucx_list_foreach(UcxList *l, ucx_callback fnc, void* data) {
     5.6      UcxList *e = l;
     5.7 +    UcxList *n;
     5.8      while (e != NULL) {
     5.9 +        n = e->next;
    5.10          fnc(e, data);
    5.11 -        e = e->next;
    5.12 +        e = n;
    5.13      }
    5.14  }

mercurial