suffix_list.c

changeset 11
06cbd0ec003d
parent 10
ecf787666f44
child 17
5f43f733cc12
equal deleted inserted replaced
10:ecf787666f44 11:06cbd0ec003d
6 */ 6 */
7 7
8 #include "suffix_list.h" 8 #include "suffix_list.h"
9 9
10 suffix_list_t* new_suffix_list_t() { 10 suffix_list_t* new_suffix_list_t() {
11 suffix_list_t* suffixList = malloc(sizeof(suffix_list_t*)); 11 suffix_list_t* suffixList = malloc(sizeof(suffix_list_t));
12 suffixList->count = 0; 12 suffixList->count = 0;
13 suffixList->items = NULL; 13 suffixList->items = NULL;
14 14
15 return suffixList; 15 return suffixList;
16 } 16 }
17 17
18 void destroy_suffix_list_t(suffix_list_t* list) {
19 while (--list->count >= 0) {
20 free(list->items[list->count]);
21 }
22 free(list);
23 }
24
25 void add_suffix(suffix_list_t* list, char* item) { 18 void add_suffix(suffix_list_t* list, char* item) {
26 char** reallocated_list = 19 char** reallocated_list =
27 realloc(list->items, sizeof(char**) * list->count + 1); 20 realloc(list->items, sizeof(char*) * list->count + 1);
28 if (reallocated_list != NULL) { 21 if (reallocated_list != NULL) {
29 list->items = reallocated_list; 22 list->items = reallocated_list;
30 list->items[list->count] = item; 23 list->items[list->count] = item;
31 list->count++; 24 list->count++;
32 } 25 }

mercurial