suffix_list.c

changeset 10
ecf787666f44
child 11
06cbd0ec003d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/suffix_list.c	Thu Sep 15 13:29:06 2011 +0200
     1.3 @@ -0,0 +1,34 @@
     1.4 +/*
     1.5 + * suffix_list.c
     1.6 + *
     1.7 + *  Created on: 15.09.2011
     1.8 + *      Author: beckermi
     1.9 + */
    1.10 +
    1.11 +#include "suffix_list.h"
    1.12 +
    1.13 +suffix_list_t* new_suffix_list_t() {
    1.14 +  suffix_list_t* suffixList = malloc(sizeof(suffix_list_t*));
    1.15 +  suffixList->count = 0;
    1.16 +  suffixList->items = NULL;
    1.17 +
    1.18 +  return suffixList;
    1.19 +}
    1.20 +
    1.21 +void destroy_suffix_list_t(suffix_list_t* list) {
    1.22 +  while (--list->count >= 0) {
    1.23 +    free(list->items[list->count]);
    1.24 +  }
    1.25 +  free(list);
    1.26 +}
    1.27 +
    1.28 +void add_suffix(suffix_list_t* list, char* item) {
    1.29 +  char** reallocated_list =
    1.30 +    realloc(list->items, sizeof(char**) * list->count + 1);
    1.31 +  if (reallocated_list != NULL) {
    1.32 +    list->items = reallocated_list;
    1.33 +    list->items[list->count] = item;
    1.34 +    list->count++;
    1.35 +  }
    1.36 +}
    1.37 +

mercurial