void levelQueueReader() { Keyword current; KeywordQueue kQueue = getKWQueue(NULL); current = kQueue->start; while(current != NULL) { switch(current->lCommand) { case wave: //! only expands waves into create enemies commands if it is at the start of the queue if(kQueue->start == current && getWave(getGame(NULL)) == returnPropertyValue(current,waveID)) { increaseEnemyNumbersThisWave(returnPropertyValue(current,numberOfEnemies)); waveCreatorCommand(current); current = removeLink(current); } else { current = current->prev; } break; case makeEnemy: if(createEnemyCommand(current)) { current = removeLink(current); return; } else { return; } break; case delay: setCreateEnemyGroupDelay(returnPropertyValue(current,dTime)); current = removeLink(current); return; break; default: break; } } }
/** * This function completely unlinks the node from all other nodes. */ void EditorChunkItemLinkable::unlink() { while (links_.size() != 0) { removeLink(links_.front()); } }
void blFinderAdminSectionsLinksTable::emitRemove(int id1, int id2){ int reponse = QMessageBox::question(this, tr("Delete link"), tr("Delete this link ?"), QMessageBox::Yes | QMessageBox::No); if (reponse == QMessageBox::Yes){ emit removeLink(id1, id2); } }
// Remove the designated object by equality. UtlContainable* UtlSList::remove(const UtlContainable* object) { UtlLink* listNode; UtlLink* found; UtlContainable* foundObject = NULL; OsLock take(mContainerLock); LIST_SANITY_CHECK; for (listNode = head(), found = NULL; listNode && !found; listNode = listNode->next()) { UtlContainable* visitNode = (UtlContainable*) listNode->data; if(visitNode && visitNode->compareTo(object) == 0) { found = listNode; } } if (found) { foundObject = (UtlContainable*)found->data; removeLink(found); } LIST_SANITY_CHECK; return foundObject; }
/* deleteList: delete all links from the list as well as the list pre: list is not null param1: list - the list post: all links are deallocated post: list is deallocated */ void deleteList(struct skipList *list) { while(list->size){ removeLink(list,list->sentinel->next[1]->value); printf("removed\n"); } free(list); }
/** * Removes the link at the back of the deque. */ void circularListRemoveBack(struct CircularList* list) { // FIXME: you must write this assert(list != 0); assert(list->size != 0); removeLink(list, list->sentinel->prev); }
OCStackResult PDMUnlinkDevices(const OicUuid_t *UUID1, const OicUuid_t *UUID2) { CHECK_PDM_INIT(TAG); if (NULL == UUID1 || NULL == UUID2) { OC_LOG(ERROR, TAG, "Invalid PARAM"); return OC_STACK_INVALID_PARAM; } int id1 = 0; if (OC_STACK_OK != getIdForUUID(UUID1, &id1)) { OC_LOG(ERROR, TAG, "Requested value not found"); return OC_STACK_INVALID_PARAM; } int id2 = 0; if (OC_STACK_OK != getIdForUUID(UUID2, &id2)) { OC_LOG(ERROR, TAG, "Requested value not found"); return OC_STACK_INVALID_PARAM; } ASCENDING_ORDER(id1, id2); return removeLink(id1, id2); }
/** * Removes the link at the back of the deque. */ void linkedListRemoveBack(struct LinkedList* list) { // FIXME: you must write this assert(list->size); removeLink(list, list->backSentinel->prev); }
/** * Removes the link at the front of the deque. */ void linkedListRemoveFront(struct LinkedList* list) { // FIXME: you must write this assert(list->size); removeLink(list, list->frontSentinel->next); }
/** * This function unlinks this node from other. * * @param other The node to unlink from. */ void EditorChunkItemLinkable::removeLink(EditorChunkItemLinkable* other) { if (other == NULL) return; ChunkLinkPtr link = findLink(other); if (link != NULL) removeLink(link); }
// at the moment No topological order is maintained! bool DAGraph::removeUnusedLinks(){ bool wasDeleted = false; for(std::list<int>::iterator it = linkIndexes_.begin(); it != linkIndexes_.end(); ++it){ if (removeLink(*it)) { it = linkIndexes_.erase(it); wasDeleted = true; --it; } } return wasDeleted; };
void Node::disconnect(const spNode& child) { if(!isInitialised_) throw std::logic_error("Node::disconnect"); if(!child) throw std::invalid_argument("Node::disconnect"); auto l = getLink(child->getID()); child->parents_.removeOne(id_); removeLink(l); changed(); }
void LinkProperties::accept() { linkText = ui.ELinkText -> text(); linkLocation = ui.ELinkLocation -> text(); validProperties = true; if ( ui.ELinkLocation -> text().isEmpty() ) emit removeLink(); else emit updateLink(linkText, linkLocation); QWidget::hide(); //close dialog }
//:Inserts "rResource" into the flow graph upstream of the //:designated "rDownstreamResource" resource. // The new resource will be inserted on the "inPortIdx" input // link of "rDownstreamResource". // If the flow graph is not "started", this call takes effect // immediately. Otherwise, the call takes effect at the start of the // next frame processing interval. // Returns OS_SUCCESS if the resource was successfully inserted. Returns // OS_INVALID_ARGUMENT if the caller specified an invalid port index. OsStatus MpFlowGraphBase::insertResourceBefore(MpResource& rResource, MpResource& rDownstreamResource, int inPortIdx) { MpResource *pUpstreamResource; int upstreamOutPortIdx; OsStatus res; // Get information about the downstream end of the link rDownstreamResource.getInputInfo(inPortIdx, pUpstreamResource, upstreamOutPortIdx); // Add the new resource to the flow graph res = addResource(rResource); if (res != OS_SUCCESS) return res; if (pUpstreamResource != NULL) { // Remove the link between the upstream and downstream resources res = removeLink(*pUpstreamResource, upstreamOutPortIdx); if (res != OS_SUCCESS) { // recover from remove link failure removeResource(rResource); return res; } // Add the link between output port 0 the new resource and the // downstream resource res = addLink(rResource, 0, rDownstreamResource, inPortIdx); if (res != OS_SUCCESS) { // recover from add link failure removeResource(rResource); addLink(*pUpstreamResource, upstreamOutPortIdx, rDownstreamResource, inPortIdx); return res; } } // Add the link between the upstream resource and input port 0 of // the new resource res = addLink(*pUpstreamResource, upstreamOutPortIdx, rResource, 0); if (res != OS_SUCCESS) { // recover from add link failure removeResource(rResource); if (pUpstreamResource != NULL) { addLink(*pUpstreamResource, upstreamOutPortIdx, rDownstreamResource, inPortIdx); } } return res; }
/** * Removes the first occurrence of a link with the given value. */ void linkedListRemove(struct LinkedList* list, TYPE value) { // FIXME: you must write this struct Link *link = list->frontSentinel->next; while(link != list->backSentinel) { TYPE val = link->value; if(val == value) { removeLink(list,link); } link = link->next; } }
/** * Removes the first occurrence of a link with the given value. */ void linkedListRemove(struct LinkedList* list, TYPE value) { // FIXME: you must write this struct Link *cur = list->frontSentinel; for (int i = 0; i < list->size; i++) { cur = cur->next; if (cur->value == value) { removeLink(list, cur); return; } } }
bool DAGraph::removeUnusedLinks(const std::list<StarLink*> &links){ int index = -1; bool wasDeleted = false; for(std::list<StarLink*>::const_iterator it = links.begin(); it != links.end(); ++it){ index = (*it)->getIndex(); if (removeLink(index)) { wasDeleted = true; linkIndexes_.remove(index); } } return wasDeleted; };
void initialQueueReader() { Keyword current; KeywordQueue kQueue = getKWQueue(NULL); current = kQueue->start; while(current != NULL) { switch(current->lCommand) { case makeTowerP: makeTowerCommand(current); current = removeLink(current); break; case totalWaves: setWaveTotalCommand(current); current = removeLink(current); break; case path: pathCommand(current); current = removeLink(current); break; default: current = current->next; break; } } }
void Structure::Graph::removeNode( QString nid ) { // node index int idx = getNodeIndex(nid); if (idx == -1) return; // remove incident links foreach (Link* l , links) { if (l->hasNode(nid)) removeLink(l); } // remove delete nodes[idx]; nodes.remove(idx); }
// Remove the designated object by equality UtlContainable* UtlSortedList::remove(const UtlContainable* obj) { UtlLink* listNode; UtlContainable* removed = NULL; OsLock take(mContainerLock); listNode = findNode(head(), EXACTLY, obj); if (listNode) { removed = (UtlContainable*)listNode->data; removeLink(listNode); } return removed; }
void PersonView::slotLinkClicked( const QUrl &url ) { qDebug() << "CLICKED" << url; if ( url.scheme() == "polka" ) { QStringList path = url.path().split("/"); QString action = path.first(); qDebug() << "ACTION" << action; if ( action == "editName" ) editName(); else if ( action == "addEmail" ) addEmail(); else if ( action == "editEmail" ) editEmail( path.value( 1 ) ); else if ( action == "removeEmail" ) removeEmail( path.value( 1 ) ); else if ( action == "commentEmail" ) commentEmail( path.value( 1 ) ); else if ( action == "addPhone" ) addPhone(); else if ( action == "editPhone" ) editPhone( path.value( 1 ) ); else if ( action == "removePhone" ) removePhone( path.value( 1 ) ); else if ( action == "commentPhone" ) commentPhone( path.value( 1 ) ); else if ( action == "addLink" ) addLink(); else if ( action == "editLink" ) editLink( path.value( 1 ) ); else if ( action == "removeLink" ) removeLink( path.value( 1 ) ); else if ( action == "commentLink" ) commentLink( path.value( 1 ) ); else if ( action == "addAddress" ) addAddress(); else if ( action == "editAddress" ) editAddress( path.value( 1 ) ); else if ( action == "removeAddress" ) removeAddress( path.value( 1 ) ); else if ( action == "commentAddress" ) commentAddress( path.value( 1 ) ); else if ( action == "addComment" ) addComment(); else if ( action == "editComment" ) editComment( path.value( 1 ) ); else if ( action == "removeComment" ) removeComment( path.value( 1 ) ); else if ( action == "close" ) requestClose(); else if ( action == "magic" ) debugHtml(); else qDebug() << "unknown action" << action; } else { new KRun( QUrl( url ), this ); } }
void BrokenLinksModel::tileImageSourceChanged(Tile *tile) { auto matchesTile = [tile](const BrokenLink &link) { return link.type == TilesetTileImageSource && link._tile == tile; }; QVector<BrokenLink>::iterator it = std::find_if(mBrokenLinks.begin(), mBrokenLinks.end(), matchesTile); if (!tile->imageSource().isEmpty() && !tile->imageLoaded()) { if (it != mBrokenLinks.end()) { int linkIndex = it - mBrokenLinks.begin(); emit dataChanged(index(linkIndex, 0), index(linkIndex, 1)); } else { refresh(); // lazy way of adding an entry for this tile } } else if (it != mBrokenLinks.end()) { removeLink(it - mBrokenLinks.begin()); } }
/** * This creates a link from this object to 'other' of the given 'linkType'. * * @param linkType The type of the link. * @param other The node to link to. * * @return The link between this and other. */ ChunkLinkPtr EditorChunkItemLinkable::createLink( ChunkLink::Direction linkType, EditorChunkItemLinkable* other) { MF_ASSERT( other ); MF_ASSERT( other != this ); MF_ASSERT( chunkItem()->pOwnSect() ); MF_ASSERT( other->chunkItem()->pOwnSect() ); ChunkLinkPtr result = NULL; switch (linkType) { case ChunkLink::DIR_NONE: if (isLinkedTo( other->guid() )) removeLink( other ); if (other->isLinkedTo( guid() )) other->removeLink( this ); result = NULL; break; case ChunkLink::DIR_START_END: result = setLink( other, true ); other->setLink( this, false ); break; case ChunkLink::DIR_END_START: result = setLink( other, false ); other->setLink( this, true ); break; case ChunkLink::DIR_BOTH: result = setLink( other, true ); other->setLink( this, true ); break; } return result; }
MYBOOL crash_basis(lprec *lp) { int i; MATrec *mat = lp->matA; MYBOOL ok = TRUE; /* Initialize basis indicators */ if(lp->basis_valid) lp->var_basic[0] = FALSE; else default_basis(lp); /* Set initial partial pricing blocks */ if(lp->rowblocks != NULL) lp->rowblocks->blocknow = 1; if(lp->colblocks != NULL) lp->colblocks->blocknow = ((lp->crashmode == CRASH_NONE) || (lp->colblocks->blockcount == 1) ? 1 : 2); /* Construct a basis that is in some measure the "most feasible" */ if((lp->crashmode == CRASH_MOSTFEASIBLE) && mat_validate(mat)) { /* The logic here follows Maros */ LLrec *rowLL = NULL, *colLL = NULL; int ii, rx, cx, ix, nz; REAL wx, tx, *rowMAX = NULL, *colMAX = NULL; int *rowNZ = NULL, *colNZ = NULL, *rowWT = NULL, *colWT = NULL; REAL *value; int *rownr, *colnr; report(lp, NORMAL, "crash_basis: 'Most feasible' basis crashing selected\n"); /* Tally row and column non-zero counts */ ok = allocINT(lp, &rowNZ, lp->rows+1, TRUE) && allocINT(lp, &colNZ, lp->columns+1, TRUE) && allocREAL(lp, &rowMAX, lp->rows+1, FALSE) && allocREAL(lp, &colMAX, lp->columns+1, FALSE); if(!ok) goto Finish; nz = mat_nonzeros(mat); rownr = &COL_MAT_ROWNR(0); colnr = &COL_MAT_COLNR(0); value = &COL_MAT_VALUE(0); for(i = 0; i < nz; i++, rownr += matRowColStep, colnr += matRowColStep, value += matValueStep) { rx = *rownr; cx = *colnr; wx = fabs(*value); rowNZ[rx]++; colNZ[cx]++; if(i == 0) { rowMAX[rx] = wx; colMAX[cx] = wx; colMAX[0] = wx; } else { SETMAX(rowMAX[rx], wx); SETMAX(colMAX[cx], wx); SETMAX(colMAX[0], wx); } } /* Reduce counts for small magnitude to preserve stability */ rownr = &COL_MAT_ROWNR(0); colnr = &COL_MAT_COLNR(0); value = &COL_MAT_VALUE(0); for(i = 0; i < nz; i++, rownr += matRowColStep, colnr += matRowColStep, value += matValueStep) { rx = *rownr; cx = *colnr; wx = fabs(*value); #ifdef CRASH_SIMPLESCALE if(wx < CRASH_THRESHOLD * colMAX[0]) { rowNZ[rx]--; colNZ[cx]--; } #else if(wx < CRASH_THRESHOLD * rowMAX[rx]) rowNZ[rx]--; if(wx < CRASH_THRESHOLD * colMAX[cx]) colNZ[cx]--; #endif } /* Set up priority tables */ ok = allocINT(lp, &rowWT, lp->rows+1, TRUE); createLink(lp->rows, &rowLL, NULL); ok &= (rowLL != NULL); if(!ok) goto Finish; for(i = 1; i <= lp->rows; i++) { if(get_constr_type(lp, i)==EQ) ii = 3; else if(lp->upbo[i] < lp->infinite) ii = 2; else if(fabs(lp->rhs[i]) < lp->infinite) ii = 1; else ii = 0; rowWT[i] = ii; if(ii > 0) appendLink(rowLL, i); } ok = allocINT(lp, &colWT, lp->columns+1, TRUE); createLink(lp->columns, &colLL, NULL); ok &= (colLL != NULL); if(!ok) goto Finish; for(i = 1; i <= lp->columns; i++) { ix = lp->rows+i; if(is_unbounded(lp, i)) ii = 3; else if(lp->upbo[ix] >= lp->infinite) ii = 2; else if(fabs(lp->upbo[ix]-lp->lowbo[ix]) > lp->epsmachine) ii = 1; else ii = 0; colWT[i] = ii; if(ii > 0) appendLink(colLL, i); } /* Loop over all basis variables */ for(i = 1; i <= lp->rows; i++) { /* Select row */ rx = 0; wx = -lp->infinite; for(ii = firstActiveLink(rowLL); ii > 0; ii = nextActiveLink(rowLL, ii)) { tx = rowWT[ii] - CRASH_SPACER*rowNZ[ii]; if(tx > wx) { rx = ii; wx = tx; } } if(rx == 0) break; removeLink(rowLL, rx); /* Select column */ cx = 0; wx = -lp->infinite; for(ii = mat->row_end[rx-1]; ii < mat->row_end[rx]; ii++) { /* Update NZ column counts for row selected above */ tx = fabs(ROW_MAT_VALUE(ii)); ix = ROW_MAT_COLNR(ii); #ifdef CRASH_SIMPLESCALE if(tx >= CRASH_THRESHOLD * colMAX[0]) #else if(tx >= CRASH_THRESHOLD * colMAX[ix]) #endif colNZ[ix]--; if(!isActiveLink(colLL, ix) || (tx < CRASH_THRESHOLD * rowMAX[rx])) continue; /* Now do the test for best pivot */ tx = my_sign(lp->orig_obj[ix]) - my_sign(ROW_MAT_VALUE(ii)); tx = colWT[ix] + CRASH_WEIGHT*tx - CRASH_SPACER*colNZ[ix]; if(tx > wx) { cx = ix; wx = tx; } } if(cx == 0) break; removeLink(colLL, cx); /* Update row NZ counts */ ii = mat->col_end[cx-1]; rownr = &COL_MAT_ROWNR(ii); value = &COL_MAT_VALUE(ii); for(; ii < mat->col_end[cx]; ii++, rownr += matRowColStep, value += matValueStep) { wx = fabs(*value); ix = *rownr; #ifdef CRASH_SIMPLESCALE if(wx >= CRASH_THRESHOLD * colMAX[0]) #else if(wx >= CRASH_THRESHOLD * rowMAX[ix]) #endif rowNZ[ix]--; } /* Set new basis variable */ set_basisvar(lp, rx, lp->rows+cx); } /* Clean up */ Finish: FREE(rowNZ); FREE(colNZ); FREE(rowMAX); FREE(colMAX); FREE(rowWT); FREE(colWT); freeLink(&rowLL); freeLink(&colLL); } /* Construct a basis that is in some measure the "least degenerate" */ else if((lp->crashmode == CRASH_LEASTDEGENERATE) && mat_validate(mat)) { /* The logic here follows Maros */ LLrec *rowLL = NULL, *colLL = NULL; int ii, rx, cx, ix, nz, *merit = NULL; REAL *value, wx, hold, *rhs = NULL, *eta = NULL; int *rownr, *colnr; report(lp, NORMAL, "crash_basis: 'Least degenerate' basis crashing selected\n"); /* Create temporary arrays */ ok = allocINT(lp, &merit, lp->columns + 1, FALSE) && allocREAL(lp, &eta, lp->rows + 1, FALSE) && allocREAL(lp, &rhs, lp->rows + 1, FALSE); createLink(lp->columns, &colLL, NULL); createLink(lp->rows, &rowLL, NULL); ok &= (colLL != NULL) && (rowLL != NULL); if(!ok) goto FinishLD; MEMCOPY(rhs, lp->orig_rhs, lp->rows + 1); for(i = 1; i <= lp->columns; i++) appendLink(colLL, i); for(i = 1; i <= lp->rows; i++) appendLink(rowLL, i); /* Loop until we have found enough new bases */ while(colLL->count > 0) { /* Tally non-zeros matching in RHS and each active column */ nz = mat_nonzeros(mat); rownr = &COL_MAT_ROWNR(0); colnr = &COL_MAT_COLNR(0); ii = 0; MEMCLEAR(merit, lp->columns + 1); for(i = 0; i < nz; i++, rownr += matRowColStep, colnr += matRowColStep) { rx = *rownr; cx = *colnr; if(isActiveLink(colLL, cx) && (rhs[rx] != 0)) { merit[cx]++; ii++; } } if(ii == 0) break; /* Find maximal match; break ties with column length */ i = firstActiveLink(colLL); cx = i; for(i = nextActiveLink(colLL, i); i != 0; i = nextActiveLink(colLL, i)) { if(merit[i] >= merit[cx]) { if((merit[i] > merit[cx]) || (mat_collength(mat, i) > mat_collength(mat, cx))) cx = i; } } /* Determine the best pivot row */ i = mat->col_end[cx-1]; nz = mat->col_end[cx]; rownr = &COL_MAT_ROWNR(i); value = &COL_MAT_VALUE(i); rx = 0; wx = 0; MEMCLEAR(eta, lp->rows + 1); for(; i < nz; i++, rownr += matRowColStep, value += matValueStep) { ix = *rownr; hold = *value; eta[ix] = rhs[ix] / hold; hold = fabs(hold); if(isActiveLink(rowLL, ix) && (hold > wx)) { wx = hold; rx = ix; } } /* Set new basis variable */ if(rx > 0) { /* We have to update the rhs vector for the implied transformation in order to be able to find the new RHS non-zero pattern */ for(i = 1; i <= lp->rows; i++) rhs[i] -= wx * eta[i]; rhs[rx] = wx; /* Do the exchange */ set_basisvar(lp, rx, lp->rows+cx); removeLink(rowLL, rx); } removeLink(colLL, cx); } /* Clean up */ FinishLD: FREE(merit); FREE(rhs); freeLink(&rowLL); freeLink(&colLL); } return( ok ); }
/** * Removes and frees the link at the front of the deque. Also decrements the * size of the deque. * @param deque */ void dequePopFront(Deque* deque) { assert(deque->size > 0); removeLink(deque->sentinel->next); --(deque->size); }
void LinkProperties::RemoveLink() { emit removeLink(); QWidget::hide(); //close dialog }
bool Structure::Graph::removeLink(Link* link) { if (!link) return false; return removeLink(link->nid1, link->nid2); }
void stepEdges(ActiveEdgeList *ael, const rb_red_blk_tree* activePrims){ static int scanLine; const static Comparator leftToRight = {(CompareF)(&leftToRightF), &scanLine}; LinkN **aelHead = &(ael->activeEdges); scanLine = ++(ael->scanLine); { LinkN *i, *p, *nextP; for(p = NULL, i = ael->activeEdges; i; (p = i),(i = nextP)){ const EdgeListEntry *const entry = i->data; Point **const edge = entry->edge; const float ys = edge[START]->y, ye = edge[END]->y, edgeEnd = max(ys, ye); nextP = i->tail; if(edgeEnd < scanLine){ #ifndef NDEBUG { const char* msg = "Deactivating %s with y-span: %f -> %f with x-span: %f -> %f(true: %f -> %f)\n", *color = fmtColor(entry->owner->color); const float lowEnd = min(ys, ye), mnX = getMinXForLine(entry, scanLine), mxX = getMaxXForLine(entry, scanLine), sX = edge[START]->x, eX = edge[END]->x; dPrintf((msg, color, lowEnd, edgeEnd, mnX, mxX, sX, eX)); } #endif /* Entries don't own the primitives they point to, * so we can get away with a simple free */ freeLink(removeLink(aelHead, i, p), &free); i = p; /* We don't want to advance p into garbage data */ } } } { const rb_red_blk_node *i; for(i = activePrims->first; i != activePrims->sentinel; i = TreeSuccessor(activePrims, i)){ Primitive *const prim = i->key; const size_t jMax = prim->arity; size_t j; for(j = 0; j < jMax; ++j){ Point **const e = prim->boundary + j; const float sy = e[START]->y, ey = e[END]->y, mnY = min(sy, ey), mxY = max(sy, ey); const bool singleton = prim->arity == 1; if((roundOwn(mnY) == scanLine && (!CLOSE_ENOUGH(sy,ey) || (singleton /* newEdge.isSingleton() */))) || (scanLine == 0 && mnY < 0 && mxY > 0)){ LinkN* newEdge = makeLinkEZ(e, prim); #ifndef NDEBUG { const char* msg = "Activating %s with y-span: %f -> %f with x-span: %f -> %f(true: %f -> %f)\n", *color = fmtColor(prim->color); const float mnX = getMinXForLine(newEdge->data, scanLine), mxX = getMaxXForLine(newEdge->data, scanLine), sX = e[START]->x, eX = e[END]->x; dPrintf((msg, color, mnY, mxY, mnX, mxX, sX, eX)); } #endif linkFront(aelHead, newEdge); if (singleton) { dPrintf(("\t->Activating dummy end\n")); linkFront(aelHead, makeLink(e, prim, true)); } } } } } mergeSort(&(ael->activeEdges), &leftToRight); }
static void updateBlock(CRDS *crds, CODE new_code, uint target_pos) { SEQ *seq = crds->seq; uint l_pos, r_pos, rr_pos, nx_pos; CODE c_code, r_code, l_code, rr_code; PCODE c_pcode, r_pcode, l_pcode; PAIR *l_pair, *c_pair, *r_pair; l_pos = leftPos(crds, target_pos); r_pos = rightPos(crds, target_pos); rr_pos = rightPos(crds, r_pos); c_code = seq[target_pos].code; c_pcode = seq[target_pos].pcode; r_code = seq[r_pos].code; r_pcode = seq[r_pos].pcode; nx_pos = seq[target_pos].next; if (nx_pos == r_pos) { nx_pos = seq[nx_pos].next; } assert(c_code != DUMMY_CODE); assert(r_code != DUMMY_CODE); if (l_pos != DUMMY_POS) { l_code = seq[l_pos].code; l_pcode = seq[l_pos].pcode; assert(seq[l_pos].code != DUMMY_CODE); removeLink(crds, l_pos); if ((l_pair = locatePair(crds, l_pcode, l_code, c_code)) != NULL) { if (l_pair->f_pos == l_pos) { l_pair->f_pos = seq[l_pos].next; } decrementPair(crds, l_pair); } if ((l_pair = locatePair(crds, l_pcode, l_code, new_code)) == NULL) { seq[l_pos].prev = DUMMY_POS; seq[l_pos].next = DUMMY_POS; createPair(crds, l_pcode, l_code, new_code, l_pos); } else { seq[l_pos].prev = l_pair->b_pos; seq[l_pos].next = DUMMY_POS; seq[l_pair->b_pos].next = l_pos; l_pair->b_pos = l_pos; incrementPair(crds, l_pair); } } removeLink(crds, target_pos); removeLink(crds, r_pos); seq[target_pos].code = new_code; seq[r_pos].code = DUMMY_CODE; if (rr_pos != DUMMY_POS) { rr_code = seq[rr_pos].code; assert(rr_code != DUMMY_CODE); if ((r_pair = locatePair(crds, r_pcode, r_code, rr_code)) != NULL) { if (r_pair->f_pos == r_pos) { r_pair->f_pos = seq[r_pos].next; } decrementPair(crds, r_pair); } if (target_pos + 1 == rr_pos - 1) { seq[target_pos+1].prev = rr_pos; seq[target_pos+1].next = target_pos; } else { seq[target_pos+1].prev = rr_pos; seq[target_pos+1].next = DUMMY_POS; seq[rr_pos-1].prev = DUMMY_POS; seq[rr_pos-1].next = target_pos; } if (nx_pos > rr_pos) { if ((c_pair = locatePair(crds, c_pcode, new_code, rr_code)) == NULL) { seq[target_pos].prev = seq[target_pos].next = DUMMY_POS; createPair(crds, c_pcode, new_code, rr_code, target_pos); } else { seq[target_pos].prev = c_pair->b_pos; seq[target_pos].next = DUMMY_POS; seq[c_pair->b_pos].next = target_pos; c_pair->b_pos = target_pos; incrementPair(crds, c_pair); } } else { seq[target_pos].next = seq[target_pos].prev = DUMMY_POS; } } else if (target_pos < crds->txt_len - 1) { assert(seq[target_pos+1].code == DUMMY_CODE); seq[target_pos+1].prev = DUMMY_POS; seq[target_pos+1].next = target_pos; seq[r_pos].prev = seq[r_pos].next = DUMMY_POS; } }
/** * Removes and frees the link at the back of the deque. Also decrements the * size of the deque. * @param deque */ void dequePopBack(Deque* deque) { assert(deque->size > 0); removeLink(deque->sentinel->prev); --(deque->size); }