/** Insere um elemento no final da lista. */ void insertLastList(struct List *list, void *elem) { ListNode *p = (ListNode*) malloc(sizeof (ListNode)); initListNode(p, elem); if (isEmptyList(list)) { list->first = p; list->last = p; } else { list->last->next = p; list->last = p; } }
Way* parseWay (xmlDocPtr doc, xmlNodePtr cur, Tag** refTag){ Way* w = NULL; unsigned long id = -1; char *visible = "T"; ListNode* ln = initListNode(0); Tag* tag = NULL; Tag* t = NULL; int size = 0; char* name = NULL; xmlAttr *node_attr = cur->properties; xmlNodePtr tmpcur = NULL; while(node_attr != NULL){ if( xmlStrcmp(node_attr->name,(const xmlChar *)"id")==0 ){ id = strtoul((const char *)((node_attr->children)->content),NULL,0); } else if( xmlStrcmp(node_attr->name,(const xmlChar *)"visible")==0 ){ visible = (char *)((node_attr->children)->content); } node_attr = node_attr->next; } tmpcur = cur->xmlChildrenNode; while(tmpcur != NULL){ if (tmpcur->type == XML_ELEMENT_NODE) { if( xmlStrcmp(tmpcur->name,(const xmlChar *)"tag")==0){ t=goodTag((char *)xmlGetProp(tmpcur, (const xmlChar *)"k"),(char *) xmlGetProp(tmpcur, (const xmlChar *)"v"), refTag); if( xmlStrcmp( (const xmlChar *) xmlGetProp( tmpcur, (const xmlChar *)"k" ), (const xmlChar *)"name" ) ==0){ name = (char *) xmlGetProp(tmpcur, (const xmlChar *)"v"); } if((t != NULL && tag == NULL) || ( t != NULL && tag != NULL && (t->priority>tag->priority))){ tag = t; } } if( xmlStrcmp(tmpcur->name,(const xmlChar *)"nd")==0 ){ ln=addRefListNode(strtoul((const char *)(xmlGetProp(tmpcur, (const xmlChar *)"ref")),NULL,0), ln); size++; } } tmpcur = tmpcur->next; } if(tag != NULL){ w = initWay(id,visible,ln,tag,size,name); return w; } else{ return NULL; } }
Relation* parseRelation(xmlDocPtr doc, xmlNodePtr cur){ Relation* r = NULL; unsigned long id = -1; char *visible = "T"; ListWay* lw = initListWay(0); ListNode* ln = initListNode(0); Tag* tag = NULL; Tag* t = NULL; xmlAttr *node_attr = cur->properties; xmlNodePtr tmpcur = NULL; while(node_attr != NULL){ if( xmlStrcmp(node_attr->name,(const xmlChar *)"id") ==0 ){ id = strtoul((const char *)((node_attr->children)->content),NULL,0); } else if( xmlStrcmp(node_attr->name,(const xmlChar *)"visible") ==0 ){ visible = (char *)((node_attr->children)->content); } node_attr = node_attr->next; } tmpcur = cur->xmlChildrenNode; while(tmpcur != NULL){ if (tmpcur->type == XML_ELEMENT_NODE) { if( xmlStrcmp(tmpcur->name,(const xmlChar *)"tag") ==0 ){ t = goodTagRelation((char *)xmlGetProp(tmpcur, (const xmlChar *)"k"),(char *) xmlGetProp(tmpcur, (const xmlChar *)"v")); if(t != NULL){ tag = t; } } if( xmlStrcmp(tmpcur->name,(const xmlChar *)"member") ==0 ){ if((strcmp((char *)xmlGetProp(tmpcur, (const xmlChar *)"type"),"way") ==0)){ lw = addRefListWay(strtoul((const char *)(xmlGetProp(tmpcur, (const xmlChar *)"ref")),NULL,0),(char *)xmlGetProp(tmpcur, (const xmlChar *)"role"), lw); } if((strcmp((char *)xmlGetProp(tmpcur, (const xmlChar *)"type"),"node") ==0)){ ln = addRefListNode(strtoul((const char *)(xmlGetProp(tmpcur, (const xmlChar *)"ref")),NULL,0), ln); } } } tmpcur = tmpcur->next; } r = initRelation(id,visible, tag,lw, ln); return r; }
void addElement(Knapsack* knapsack, KnapsackElement* new_element) { ListNode* node = NULL; node = searchKnapsackElement(knapsack, new_element->ID); if (node != NULL) { //if node exists in the Knapsack Element list node->quantity++; knapsack->value += new_element->value; } else { if (knapsack->elements == NULL) { initListHead(&(knapsack->elements)); } //create new Node: initListNode(&node); node->element = new_element; node->quantity = 1; addNode(knapsack->elements, node); } knapsack->value += new_element->value; }