SList* listConcatUnique(SList* list1, SList* list2, int(*cmp)(void*, void*)) { if(!list1 || listEmpty(list1)) { list1->head = list2->head; list1->curr = list2->curr; } else if(!list2 || listEmpty(list2)) { return list1; } else { listHead(list2); do { int found = 0; listHead(list1); do { found = cmp(listCurrent(list1), listCurrent(list2)); }while(!found && listNext(list1)); if(!found) { listAdd(list1, listCurrent(list2)); } }while(listNext(list2)); } return list1; }
ECouleur determineCouleurTerritoire(SPlateau* plateau, STerritoire* territoire, ECouleur couleur) { ECouleur couleur_de_comparaison = couleur; SPosition* position_territoire = listCurrent(listEnsembleColore(territoire)); if(listEmpty(listEnsembleColore(territoire))) return BORD; return compareCouleur(couleur_de_comparaison, determineCouleurTerritoire(plateau, listNext(listEnsembleColore(territoire)), couleurVoisin(plateau,position_territoire))); }
/* This routine returns the previous element in the list or NULL if * none is available. It also sets the current meta data to the * previous element. */ void *listPrevious(list_t *list) { if((list->current!=NULL)&&(list->current->previous!=NULL)) { list->current=list->current->previous; return(listCurrent(list)); } else { return(NULL); } }
/* This routine returns the next element in the list or NULL if * none is available. It also advances the current meta data to the * next element. */ void *listNext(list_t *list) { if((list->current!=NULL)&&(list->current->next!=NULL)) { list->current=list->current->next; return(listCurrent(list)); } else { return(NULL); } }
void KeyCache::addKeys(const QString &dir) { if (!mNewKeys.contains(dir)) { mNewKeys.insert(dir, listNew(dir)); //qCDebug(LIBMAILDIR_LOG) << "Added new keys for: " << dir; } if (!mCurKeys.contains(dir)) { mCurKeys.insert(dir, listCurrent(dir)); //qCDebug(LIBMAILDIR_LOG) << "Added cur keys for: " << dir; } }
int listFind(SList* list, void* elem) { listHead(list); while(listCurrent(list) != elem) { if(!listNext(list)) { return 0; } } return 1; }
int listSearch(SList* list, void* elem, int(*cmp)(void*, void*)) { int found = 0; if(list && elem && cmp && !listEmpty(list)) { listHead(list); do { found = cmp(listCurrent(list), elem); }while(!found && listNext(list)); } return found; }
void* listGetElement(SList* list, int index) { void* res = NULL; if(list && index > -1 && index < listSize(list)) { int i; for(i = 0 ; i < index ; ++i) { listNext(list); } res = listCurrent(list); } return res; }
void plateau_realiser_capture(SPlateau* plateau, SChaines* chaines, SChaine* chaine) { if(chaine) { SList* list = listEnsembleColore(chaine); listHead(list); do { SPosition* pos = listCurrent(list); plateau_set(plateau, pos, VIDE); }while(listNext(list)); //listDelete(list); listRemoveElement(chaines, chaine); //free(chaine); } }
void* listRemoveElement(SList* list, void* elem) { void* res = NULL; if(!listEmpty(list)) { SListNode* prev = NULL; SListNode* curr = NULL; listHead(list); int found = 0; do { prev = curr; curr = list->curr; if(listCurrent(list) == elem) { found = 1; if(curr == list->head) { list->head = list->head->next; list->curr = list->head; } else { prev->next = curr->next; list->curr = prev; } res = curr->data; free(curr); } }while(!found && listNext(list)); } return res; }
/* This routine returns the last element in the list or NULL if * none is available. It also sets the current meta data to be the * last element in the list. */ void *listLast(list_t *list) { list->current=list->last; return(listCurrent(list)); }
/* This routine returns the first element in the list or NULL if * none is available. It also sets the current meta data to be the * first element in the list. */ void *listFirst(list_t *list) { list->current=list->first; return(listCurrent(list)); }