int test_datastructure_link_list() { llist_t *llist; allocator_t *allocator; struct test t1={1,2}; struct test t2={2,2}; struct test t3={3,2}; struct test t4={4,2}; int ret = 0; /* *allocator = allocator_creator(ALLOCATOR_TYPE_CTR_MALLOC); *allocator_ctr_init(allocator, 0, 0, 1024); *dbg_str(DBG_CONTAINER_DETAIL,"list allocator addr:%p",allocator); */ allocator = allocator_creator(ALLOCATOR_TYPE_SYS_MALLOC,0); //ct = container_creator(CONTAINER_TYPE_LIST,allocator); llist = llist_create(allocator,0); llist_init(llist,sizeof(struct test)); llist_push_front(llist,&t1); llist_push_front(llist,&t2); llist_push_front(llist,&t3); llist_push_front(llist,&t4); llist_push_back(llist,&t1); llist_push_back(llist,&t2); llist_push_back(llist,&t3); llist_push_back(llist,&t4); llist_for_each(llist,print_list_data); llist_destroy(llist); return ret; }
void domaininfo_pushurl(domaininfo *domain, urlinfo *url) { llist_push_back(&domain->pages, url); domain->numpages++; }
static inline void pushback(LList* l, int val) { *(int*)llist_push_back(l) = val; }
url_llist *getcache(char *folder, char *searchstring) { char *modifiedstring = tounderline(searchstring); char *path = getpath(folder, modifiedstring); FILE *file = fopen(path, "r"); // return null if unable to open for read (indicating file doesn't exist if (!file) return NULL; // get number of urls int numlinks; fscanf(file, "%d\n", &numlinks); // creat array of urls, and a corresponding array holding indexes of urls each url points to urlinfo *urls[numlinks]; llist outlink_indexes[numlinks]; // initialize output list url_llist *output = malloc(sizeof(url_llist)); url_llist_init(output); // read each url (each is on a separate line) // push to linked list char urlstring[MAXLENGTH]; int numoutlinks; urlinfo *url; // pass 1: index urls unsigned long *outlink_index; unsigned long i, j; while(fscanf(file, "%s %d\n", urlstring, &numoutlinks) != EOF) { // construct url (without outlinks) url = makeURL(urlstring, NULL); // push url and a linked list for its outlinks url_llist_push_back(output, url); urls[i] = url; llist_init(&(outlink_indexes[i]), (void *)comparelong); // read and push each outlink for (j = 0; j < numoutlinks; j++) { outlink_index = malloc(sizeof(unsigned long)); fscanf(file, "%lu ", outlink_index);//outlink_index)) llist_push_back(&(outlink_indexes[i]), outlink_index); } // read in '\n' fscanf(file, "\n"); i++; } lnode *current_node, *prev_node; // pass 2: get outlinks by their indexes for (i = 0; i < numlinks; i++) { url = urls[i]; current_node = outlink_indexes[i].front; while (current_node) { outlink_index = current_node->data; prev_node = current_node; llist_push_back(&urls[i]->outlinks, urls[(long)*outlink_index]); current_node = current_node->next; free(outlink_index); free(prev_node); } } free(path); free(modifiedstring); close(file); return output; }