int cgm_solver(uint32_t a, uint32_t b, uint32_t c, uint32_t** matches, struct db* database) { int sections, secLength, aLength, bLength, cLength; int double1, double2, double3; int triple; int count; uint32_t* dubMatches1 = NULL; uint32_t* dubMatches2 = NULL; uint32_t* dubMatches3 = NULL; uint32_t* tripMatches = NULL; uint32_t* temp; int keySize = 16; uint32_t* aList = NULL; uint32_t* bList = NULL; uint32_t* cList = NULL; aLength = db_query(database, a, &aList); bLength = db_query(database, b, &bList); cLength = db_query(database, c, &cList); double1 = doubleMatch(aList, bList, aLength, bLength, keySize, &dubMatches1, 0, 0); double2 = doubleMatch(aList, cList, aLength, cLength, keySize, &dubMatches2, keySize, 0); double3 = doubleMatch(bList, cList, bLength, cLength, keySize, &dubMatches3, 0, keySize); triple = doubleMatch(dubMatches1, dubMatches2, double1, double2, 0, &tripMatches, 0, 0); if(triple > 0){ *matches = tripMatches; count = triple; } else if(double1 + double2 + double3 > 0) { count = mergeLists(dubMatches1, dubMatches2, dubMatches3, double1, double2, double3, &temp); *matches = temp; } else { count = mergeLists(aList, bList, cList, aLength, bLength, cLength, &temp); *matches = temp; } /* free any allocated memory and return the number items in matches */ free(aList); free(bList); free(cList); free(dubMatches1); free(dubMatches2); free(dubMatches3); if(triple == 0) free(tripMatches); return count; }
void updateTrees(int groupBase, int multiplyFactor, Tree<DataByID>& appsByIDtree, Tree<DataByDowns>& appsByDLtree) { UpdateDL updateDL(groupBase, multiplyFactor); appsByIDtree.inOrder(updateDL); List<DataByDowns> list1, list2, allElements; PredicateTree prediacteTree(&list1, &list2, groupBase, multiplyFactor); appsByDLtree.inOrder(prediacteTree); mergeLists(list1, list2, allElements); FillTree fillTree(allElements); appsByDLtree.inOrder(fillTree); }
void NodeListEvent::process(NetConnection* conn) { if (mNodeList) { NodeListManager::NodeList* oldList = NULL; gClientNodeListManager->findListById(mNodeList->mId, &oldList, false); mergeLists(oldList); gClientNodeListManager->addNodeList(mNodeList); mNodeList = NULL; } }
static listnode_t *doMergeSort(listnode_t *list, comparefunc funcCompare) { listnode_t *p; if(list->next) { p = splitList(list); // Sort both halves and merge them back. list = mergeLists(doMergeSort(list, funcCompare), doMergeSort(p, funcCompare), funcCompare); } return list; }
void RKValueSelector::availablePropertyChanged () { RK_TRACE (PLUGIN); const QStringList &vals = available->values (); for (int i = vals.size () - 1; i >= 1; --i) { if (vals.lastIndexOf (vals[i], i - 1) >= 0) { RK_DEBUG (PLUGIN, DL_WARNING, "Duplicate value index in value selector: %s", qPrintable (vals[i])); } } model->setStringList (mergeLists (labels->values (), available->values ())); if (!purged_selected_indexes.isEmpty ()) { // This is to handle the case that the "selected" property was updated externally, *before* the "available" property got the corresponding change. // In this case, try to re-apply any selected strings that could not be matched, before purged_selected_indexes.append (selected->values ()); selected->setValueList (purged_selected_indexes); // side effect updating selected items purged_selected_indexes.clear (); } else { selectionPropertyChanged (); // To update selected items purged_selected_indexes.clear (); } }
void RKValueSelector::labelsPropertyChanged () { RK_TRACE (PLUGIN); model->setStringList (mergeLists (labels->values (), available->values ())); selectionPropertyChanged (); // To update selected items }
bool Msg3a::gotAllSplitReplies ( ) { // if any of the split requests had an error, give up and set m_errno // but don't set if for non critical errors like query truncation if ( m_errno ) { g_errno = m_errno; return true; } // also reset the finalbuf and the oldNumTopDocIds if ( m_finalBuf ) { mfree ( m_finalBuf, m_finalBufSize, "Msg3aF" ); m_finalBuf = NULL; m_finalBufSize = 0; } // update our estimated total hits m_numTotalEstimatedHits = 0; for ( long i = 0; i < m_numHosts ; i++ ) { // get that host that gave us the reply //Host *h = g_hostdb.getHost(i); // . get the reply from multicast // . multicast should have destroyed all slots, but saved reply // . we are responsible for freeing the reply // . we need to call this even if g_errno or m_errno is // set so we can free the replies in Msg3a::reset() // . if we don't call getBestReply() on it multicast should // free it, because Multicast::m_ownReadBuf is still true Multicast *m = &m_mcast[i]; bool freeit = false; long replySize = 0; long replyMaxSize; char *rbuf; Msg39Reply *mr; // . only get it if the reply not already full // . if reply already processed, skip // . perhaps it had no more docids to give us or all termlists // were exhausted on its disk and this is a re-call // . we have to re-process it for count m_numTotalEstHits, etc. rbuf = m->getBestReply ( &replySize , &replyMaxSize , &freeit , true ); //stealIt? // cast it mr = (Msg39Reply *)rbuf; // in case of mem leak, re-label from "mcast" to this so we // can determine where it came from, "Msg3a-GBR" relabel( rbuf, replyMaxSize , "Msg3a-GBR" ); // . we must be able to free it... we must own it // . this is true if we should free it, but we should not have // to free it since it is owned by the slot? if ( freeit ) { log(LOG_LOGIC,"query: msg3a: Steal failed."); char *xx = NULL; *xx=0; } // bad reply? if ( ! mr ) { log(LOG_LOGIC,"query: msg3a: Bad NULL reply."); m_reply [i] = NULL; m_replyMaxSize[i] = 0; // it might have been timd out, just ignore it!! continue; // if size is 0 it can be Msg39 giving us an error! g_errno = EBADREPLYSIZE; m_errno = EBADREPLYSIZE; // all reply buffers should be freed on reset() return true; } // how did this happen? if ( replySize < 29 && ! mr->m_errno ) { // if size is 0 it can be Msg39 giving us an error! g_errno = EBADREPLYSIZE; m_errno = EBADREPLYSIZE; log(LOG_LOGIC,"query: msg3a: Bad reply size of %li.", replySize); // all reply buffers should be freed on reset() return true; } // can this be non-null? we shouldn't be overwriting one // without freeing it... if ( m_reply[i] ) // note the mem leak now log("query: mem leaking a 0x39 reply"); // cast it and set it m_reply [i] = mr; m_replyMaxSize[i] = replyMaxSize; // deserialize it (just sets the ptr_ and size_ member vars) //mr->deserialize ( ); deserializeMsg ( sizeof(Msg39Reply) , &mr->size_docIds, &mr->size_clusterRecs, &mr->ptr_docIds, mr->m_buf ); // sanity check if ( mr->m_nqt != m_q->getNumTerms() ) { g_errno = EBADREPLY; m_errno = EBADREPLY; log("query: msg3a: Split reply qterms=%li != %li.", (long)mr->m_nqt,(long)m_q->getNumTerms() ); return true; } // return if split had an error, but not for a non-critical // error like query truncation if ( mr->m_errno && mr->m_errno != EQUERYTRUNCATED ) { g_errno = mr->m_errno; m_errno = mr->m_errno; log("query: msg3a: Split had error: %s", mstrerror(g_errno)); return true; } // skip down here if reply was already set //skip: // add of the total hits from each split, this is how many // total results the lastest split is estimated to be able to // return // . THIS should now be exact since we read all termlists // of posdb... m_numTotalEstimatedHits += mr->m_estimatedHits; // debug log stuff if ( ! m_debug ) continue; // cast these for printing out long long *docIds = (long long *)mr->ptr_docIds; score_t *scores = (score_t *)mr->ptr_scores; // print out every docid in this split reply for ( long j = 0; j < mr->m_numDocIds ; j++ ) { // print out score_t logf( LOG_DEBUG, "query: msg3a: [%lu] %03li) " "split=%li docId=%012llu domHash=0x%02lx " "score=%lu" , (unsigned long)this , j , i , docIds [j] , (long)g_titledb.getDomHash8FromDocId(docIds[j]), (long)scores[j] ); } } // this seems to always return true! mergeLists ( ); if ( ! m_r->m_useSeoResultsCache ) return true; // now cache the reply SafeBuf cr; long dataSize = 4 + 4 + 4 + m_numDocIds * (8+4+4); long need = sizeof(key_t) + 4 + dataSize; bool status = cr.reserve ( need ); // sanity if ( ( m_ckey.n0 & 0x01 ) == 0x00 ) { char *xx=NULL; *xx=0; } // ignore errors g_errno = 0; // return on error with g_errno cleared if cache add failed if ( ! status ) return true; // add to buf otherwise cr.safeMemcpy ( &m_ckey , sizeof(key_t) ); cr.safeMemcpy ( &dataSize , 4 ); long now = getTimeGlobal(); cr.pushLong ( now ); cr.pushLong ( m_numDocIds ); cr.pushLong ( m_numTotalEstimatedHits );//Results ); long max = m_numDocIds; // then the docids for ( long i = 0 ; i < max ; i++ ) cr.pushLongLong(m_docIds[i] ); for ( long i = 0 ; i < max ; i++ ) cr.pushFloat(m_scores[i]); for ( long i = 0 ; i < max ; i++ ) cr.pushLong(getSiteHash26(i)); // sanity if ( cr.length() != need ) { char *xx=NULL; *xx=0; } // make these key_t startKey; key_t endKey; startKey = m_ckey; // clear delbit startKey.n0 &= 0xfffffffffffffffeLL; // end key is us endKey = m_ckey; // that is the single record m_seoCacheList.set ( cr.getBufStart() , cr.length(), cr.getBufStart(), // alloc cr.getCapacity(), // alloc size (char *)&startKey, (char *)&endKey, -1, // fixeddatasize true, // owndata? false,// use half keys? sizeof(key_t) ); // do not allow cr to free it, msg1 will cr.detachBuf(); // note it //log("seopipe: storing ckey=%s q=%s" // ,KEYSTR(&m_ckey,12) // ,m_r->ptr_query // ); //log("msg1: sending niceness=%li",(long)m_r->m_niceness); // this will often block, but who cares!? it just sends a request off if ( ! m_msg1.addList ( &m_seoCacheList , RDB_SERPDB,//RDB_CACHEDB, m_r->ptr_coll, this, // state gotSerpdbReplyWrapper, // callback false, // forcelocal? m_r->m_niceness ) ) { //log("blocked"); return false; } // we can safely delete m_msg17... just return true return true; }
int main(void) { //First Linked List struct node *first=NULL; int arr1[]={1,1,3,5,7,9}; int size1=sizeof(arr1)/sizeof(arr1[0]); int j; for(j=0;j<size1;j++) { first=append(first,arr1[j]); } printf("First Linked List contains : \n"); print(first); printf("\n\n"); //Second Linked List struct node *second=NULL; int arr2[]={2,4,5,6,6,7,9}; int size2=sizeof(arr2)/sizeof(arr2[0]); int k; for(k=0;k<size2;k++) { second=append(second,arr2[k]); } printf("\nSecond Linked List contains :\n"); print(second); printf("\n\n"); //Merge Linked lists first and second struct node *merge=NULL; merge=mergeLists(first,second); printf("\nMerged Linked List contains :\n"); print(merge); printf("\n\n"); //Reverse the merged list struct node *reverse=NULL; reverse=reverseList(merge); printf("\nReverse of Merged Linked List contains :\n"); print(reverse); printf("\n\n"); //Inserting into a doubly linked list struct dnode *dlist=NULL; int arr3[]={2,4,5,6,6,7,9}; int size3=sizeof(arr3)/sizeof(arr3[0]); int l; for(l=0;l<size3;l++) { dlist=SortedInsert(dlist,arr3[l]); } printf("\nDoubly Linked List contains :\n"); printDoublyList(dlist); printf("\n\n"); //Reversing the doubly linked list struct dnode *reverseDoubleList=NULL; reverseDoubleList=reverseDoublyList(dlist); printf("\nReverse of Doubly Linked List contains :\n"); printDoublyList(reverseDoubleList); printf("\n\n"); return 0; }
void list_test() { int comps, mergecomps; list_t *list_a, *list_b, *list_c; test_t *ptr_a, *ptr_b, *ptr_c, *ptr_d, *ptr_e, *ptr_f; /* createList () Test */ fprintf(stdout, "TEST: createList () \t\t... \t"); list_a = createList(5); (list_a != NULL && list_a->size == 5) ? fprintf(stdout, "OK\n") : fprintf(stdout, "ERROR\n"); /* destroyList () Test */ fprintf(stdout, "TEST: destroyList () \t\t... \t"); destroyList(list_a); (list_a == NULL) ? fprintf(stdout, "OK\n") : fprintf(stdout, "ERROR: List of size %d still exists\n", list_a->size); /* insert() Test */ list_b = createList(3); fprintf(stdout, "LIST: size : %d, items : %d, lock : %d\n", list_b->size, list_b->items, list_b->lock); ptr_a = (test_t*)safe_malloc(sizeof(test_t)); ptr_a->value = 8; strcpy(ptr_a->name, "Tester1"); ptr_b = (test_t*)safe_malloc(sizeof(test_t)); ptr_b->value = 2; strcpy(ptr_b->name, "Tester2"); insertItem(list_b, ptr_a); insertItem(list_b, ptr_b); fprintf(stdout, "LIST: size : %d, items : %d, lock : %d\n", list_b->size, list_b->items, list_b->lock); fprintf(stdout, "TEST: insertItem () \t\t... \t"); (list_b->items == 2) ? fprintf(stdout, "OK\n") : fprintf(stdout, "ERROR\n"); fprintf(stdout, "STATUS: struct from list \n" "Struct 1 : %d, %s\n" "Struct 2 : %d, %s\n", ((test_t*)list_b->data[0])->value, ((test_t*)list_b->data[0])->name, ((test_t*)list_b->data[1])->value, ((test_t*)list_b->data[1])->name); /* removeItem () Test */ fprintf(stdout, "TEST: removeItem () \t\t... \t"); removeItem(list_b, 1); (list_b->items == 1) ? fprintf(stdout, "OK\n") : fprintf(stdout, "ERROR\n"); /* sortList () Test */ fprintf(stdout, "TEST: sortList () \t\t... \t"); ptr_b = (test_t*)safe_malloc(sizeof(test_t)); ptr_b->value = 2; strcpy(ptr_b->name, "Tester2"); ptr_c = (test_t*)safe_malloc(sizeof(test_t)); ptr_c->value = 1; strcpy(ptr_c->name, "Tester3"); insertItem(list_b, ptr_b); insertItem(list_b, ptr_c); comps = sortList(list_b, &compareTest); (comps > 0) ? fprintf(stdout, "OK Comparisons : %d\n", comps) : fprintf(stdout, "ERROR\n"); fprintf(stdout, "STATUS: struct from list \n" "Struct 1 : %d, %s\n" "Struct 2 : %d, %s\n" "Struct 3 : %d, %s\n", ((test_t*)list_b->data[0])->value, ((test_t*)list_b->data[0])->name, ((test_t*)list_b->data[1])->value, ((test_t*)list_b->data[1])->name, ((test_t*)list_b->data[2])->value, ((test_t*)list_b->data[2])->name); /* mergeLists () Test */ fprintf(stdout, "TEST: mergeLists () \t\t... \t"); list_a = createList(3); list_c = createList(3); ptr_d = (test_t*)safe_malloc(sizeof(test_t)); ptr_d->value = 9; strcpy(ptr_d->name, "Tester4"); ptr_e = (test_t*)safe_malloc(sizeof(test_t)); ptr_e->value = 3; strcpy(ptr_e->name, "Tester5"); ptr_f = (test_t*)safe_malloc(sizeof(test_t)); ptr_f->value = 1; strcpy(ptr_f->name, "Tester6"); insertItem(list_a, ptr_d); insertItem(list_a, ptr_e); insertItem(list_a, ptr_f); comps = sortList(list_a, &compareTest); mergecomps = mergeLists(list_a, list_b, list_c, &compareTest); (list_a->items < 3 && list_b->items < 3) ? fprintf(stdout, "OK Sort Comparisons : %d, Merge Comparisons: %d\n", comps, mergecomps) : fprintf(stdout, "ERROR\n"); fprintf(stdout, "STATUS: Output from merge \n" "Struct 1 : %d, %s\n" "Struct 2 : %d, %s\n" "Struct 3 : %d, %s\n", ((test_t*)list_c->data[0])->value, ((test_t*)list_c->data[0])->name, ((test_t*)list_c->data[1])->value, ((test_t*)list_c->data[1])->name, ((test_t*)list_c->data[2])->value, ((test_t*)list_c->data[2])->name); destroyList(list_c); list_c = createList(3); fprintf(stdout, "LIST: size : %d, items : %d, lock : %d\n", list_c->size, list_c->items, list_c->lock); mergecomps = mergeLists(list_a, list_b, list_c, &compareTest); fprintf(stdout, "LIST: size : %d, items : %d, lock : %d\n", list_c->size, list_c->items, list_c->lock); fprintf(stdout, "STATUS: Output from merge \n" "Struct 1 : %d, %s\n" "Struct 2 : %d, %s\n" "Struct 3 : %d, %s\n", ((test_t*)list_c->data[0])->value, ((test_t*)list_c->data[0])->name, ((test_t*)list_c->data[1])->value, ((test_t*)list_c->data[1])->name, ((test_t*)list_c->data[2])->value, ((test_t*)list_c->data[2])->name); }
int cgm(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t** matches, struct db* database) { int sections, secLength, aLength, bLength, cLength, dLength; int double1, double2, double3, double4, double5, double6; int quad, triple1, triple2, triple3, triple4; int itempA, itempB; int count; struct timeval t1, t2; double elapsedTime; uint32_t* dubMatches1 = NULL; uint32_t* dubMatches2 = NULL; uint32_t* dubMatches3 = NULL; uint32_t* dubMatches4 = NULL; uint32_t* dubMatches5 = NULL; uint32_t* dubMatches6 = NULL; uint32_t* tripMatches1 = NULL; uint32_t* tripMatches2 = NULL; uint32_t* tripMatches3 = NULL; uint32_t* tripMatches4 = NULL; uint32_t* quadMatches = NULL; uint32_t* tempA; uint32_t* tempB; uint32_t* tempC; int keySize = 16; uint32_t* aList = NULL; uint32_t* bList = NULL; uint32_t* cList = NULL; uint32_t* dList = NULL; aLength = db_query(database, a, &aList); bLength = db_query(database, b, &bList); cLength = db_query(database, c, &cList); dLength = db_query(database, d, &dList); gettimeofday(&t1, NULL); double1 = doubleMatch(aList, bList, aLength, bLength, keySize, &dubMatches1, 0, 0); double2 = doubleMatch(aList, cList, aLength, cLength, keySize, &dubMatches2, keySize, 0); double3 = doubleMatch(aList, dList, aLength, dLength, keySize, &dubMatches3, keySize*2, 0); double4 = doubleMatch(bList, cList, bLength, cLength, keySize, &dubMatches4, 0, keySize); double5 = doubleMatch(bList, dList, bLength, dLength, keySize, &dubMatches5, keySize, keySize); double6 = doubleMatch(cList, dList, cLength, dLength, keySize, &dubMatches6, 0, keySize*2); quad = doubleMatch(dubMatches1, dubMatches6, double1, double6, 0, &quadMatches, 0, 0); triple1 = doubleMatch(dubMatches1, dubMatches2, double1, double2, 0, &tripMatches1, 0, 0); triple2 = doubleMatch(dubMatches1, dubMatches3, double1, double3, 0, &tripMatches2, 0, 0); triple3 = doubleMatch(dubMatches2, dubMatches3, double2, double3, 0, &tripMatches3, 0, 0); triple4 = doubleMatch(dubMatches4, dubMatches5, double4, double5, 0, &tripMatches4, 0, 0); if(quad > 0){ *matches = quadMatches; count = quad; } else if(triple1 + triple2 + triple3 + triple4 > 0) { itempA = mergeLists(tripMatches1, tripMatches2, NULL, triple1, triple2, 0, &tempA); itempB = mergeLists(tripMatches3, tripMatches4, NULL, triple3, triple4, 0, &tempB); count = mergeLists(tempA, tempB, NULL, itempA, itempB, 0, &tempC); *matches = tempC; free(tempA); free(tempB); } else if(double1 + double2 + double3 + double4 + double5 + double6 > 0) { itempA = mergeLists(dubMatches1, dubMatches2, dubMatches3, double1, double2, double3, &tempA); itempB = mergeLists(dubMatches4, dubMatches5, dubMatches6, double4, double5, double6, &tempB); count = mergeLists(tempA, tempB, NULL, itempA, itempB, 0, &tempC); *matches = tempC; free(tempA); free(tempB); } else { itempA = mergeLists(aList, bList, NULL, aLength, bLength, 0, &tempA); itempB = mergeLists(cList, dList, NULL, cLength, dLength, 0, &tempB); count = mergeLists(tempA, tempB, NULL, itempA, itempB, 0, &tempC); *matches = tempC; free(tempA); free(tempB); } /* free any allocated memory and return the number items in matches */ free(aList); free(bList); free(cList); free(dList); free(tripMatches1); free(tripMatches2); free(tripMatches3); free(tripMatches4); free(dubMatches1); free(dubMatches2); free(dubMatches3); free(dubMatches4); free(dubMatches5); free(dubMatches6); if(quad == 0) free(quadMatches); gettimeofday(&t2, NULL); elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms seq += elapsedTime; // printf("Time: %f\n", elapsedTime); return count; }
void ArrayInfo::mergeInfo(const TNode a, const TNode b){ // can't have assertion that find(b) = a ! TimerStat::CodeTimer codeTimer(d_mergeInfoTimer); ++d_callsMergeInfo; Trace("arrays-mergei")<<"Arrays::mergeInfo merging "<<a<<"\n"; Trace("arrays-mergei")<<" and "<<b<<"\n"; CNodeInfoMap::iterator ita = info_map.find(a); CNodeInfoMap::iterator itb = info_map.find(b); if(ita != info_map.end()) { Trace("arrays-mergei")<<"Arrays::mergeInfo info "<<a<<"\n"; if(Trace.isOn("arrays-mergei")) (*ita).second->print(); if(itb != info_map.end()) { Trace("arrays-mergei")<<"Arrays::mergeInfo info "<<b<<"\n"; if(Trace.isOn("arrays-mergei")) (*itb).second->print(); CTNodeList* lista_i = (*ita).second->indices; CTNodeList* lista_st = (*ita).second->stores; CTNodeList* lista_inst = (*ita).second->in_stores; CTNodeList* listb_i = (*itb).second->indices; CTNodeList* listb_st = (*itb).second->stores; CTNodeList* listb_inst = (*itb).second->in_stores; mergeLists(lista_i, listb_i); mergeLists(lista_st, listb_st); mergeLists(lista_inst, listb_inst); /* sketchy stats */ //FIXME int s = 0;//lista_i->size(); d_maxList.maxAssign(s); if(s!= 0) { d_avgIndexListLength.addEntry(s); ++d_listsCount; } s = lista_st->size(); d_maxList.maxAssign(s); if(s!= 0) { d_avgStoresListLength.addEntry(s); ++d_listsCount; } s = lista_inst->size(); d_maxList.maxAssign(s); if(s!=0) { d_avgInStoresListLength.addEntry(s); ++d_listsCount; } /* end sketchy stats */ } } else { Trace("arrays-mergei")<<" First element has no info \n"; if(itb != info_map.end()) { Trace("arrays-mergei")<<" adding second element's info \n"; (*itb).second->print(); CTNodeList* listb_i = (*itb).second->indices; CTNodeList* listb_st = (*itb).second->stores; CTNodeList* listb_inst = (*itb).second->in_stores; Info* temp_info = new Info(ct, bck); mergeLists(temp_info->indices, listb_i); mergeLists(temp_info->stores, listb_st); mergeLists(temp_info->in_stores, listb_inst); info_map[a] = temp_info; } else { Trace("arrays-mergei")<<" Second element has no info \n"; } } Trace("arrays-mergei")<<"Arrays::mergeInfo done \n"; }
void View::sortView() { Feature *base = _rootNode; Feature *next = base->_next; Feature *otherRoot = NULL; Feature *otherBase = NULL; Feature *objectRoot = NULL; Feature *objectBase = NULL; Feature *staticRoot = NULL; Feature *staticBase = NULL; // Remove all features. base->_next = NULL; // Iterate through all the previous features, placing them in the appropriate list. while (next) { Feature *curr = next; next = next->_next; if (curr->_flags & kFeatureSortBackground) { // These are behind everything else (e.g. stars, drop spot highlights), // so we insert this node directly after the current base. base->_next = curr; curr->_prev = base; curr->_next = NULL; base = base->_next; } else if (curr->_flags & kFeatureSortStatic) { // Insert this node into the list of static objects. if (staticBase) { staticBase->_next = curr; curr->_prev = staticBase; curr->_next = NULL; staticBase = curr; } else { staticBase = curr; staticRoot = curr; curr->_prev = NULL; curr->_next = NULL; } } else if (curr->_flags & kFeatureObjectMask) { // This is == 1 or == 2 in old code. // Insert this node into the list of objects. if (objectRoot) { objectBase->_next = curr; curr->_prev = objectBase; curr->_next = NULL; objectBase = curr; } else { objectBase = curr; objectRoot = curr; curr->_prev = NULL; curr->_next = NULL; } } else { if (!(curr->_flags & kFeatureOldSortForeground)) curr->_flags |= kFeatureSortStatic; // Insert this node into the list of other features. if (otherRoot) { otherBase->_next = curr; curr->_prev = otherBase; curr->_next = NULL; otherBase = curr; } else { otherBase = curr; otherRoot = curr; curr->_prev = NULL; curr->_next = NULL; } } } // Add the static features after the background ones. Feature *curr = staticRoot; while (curr) { Feature *prev = curr; curr = curr->_next; base->_next = prev; prev->_prev = base; base = base->_next; base->_next = NULL; } // Add the other features on top.. _rootNode = mergeLists(_rootNode, sortOneList(otherRoot)); // Then finally, add the objects. _rootNode = mergeLists(_rootNode, sortOneList(objectRoot)); }