/* * Insert asserts at various points in the IR. * TODO: t2137231 Insert DbgAssertPtr at points that use or produces a GenPtr */ static void insertAsserts(IRTrace* trace, IRFactory& factory) { forEachTraceBlock(trace, [&](Block* block) { for (auto it = block->begin(), end = block->end(); it != end; ) { IRInstruction& inst = *it; ++it; if (inst.op() == SpillStack) { insertSpillStackAsserts(inst, factory); continue; } if (inst.op() == Call) { SSATmp* sp = inst.dst(); IRInstruction* addr = factory.gen(LdStackAddr, inst.marker(), Type::PtrToGen, StackOffset(0), sp); insertAfter(&inst, addr); insertAfter(addr, factory.gen(DbgAssertPtr, inst.marker(), addr->dst())); continue; } if (!inst.isBlockEnd()) insertRefCountAsserts(inst, factory); } }); }
int main(){ Element* head = (Element*)malloc(sizeof(Element)); memset(head, 0, sizeof(Element)); head->data = 0; head->next = NULL; insertHead(&head, 1); insertHead(&head, 2); insertHead(&head, 3); // Test to insert in front of head insertAfter(&head, NULL, 4); insertAfter(&head, head, 5); printHeadData(&head); printLinkedList(&head); // deleteHead(&head); // deleteHead(&head); // deleteHead(&head); // deleteHead(&head); Element* select = findMToLastElement(&head, 2); printf("lastMElem: %d\n", select->data); deleteHead(&head); deleteList(&head); printHeadData(&head); printLinkedList(&head); return 0; }
void BasicBlock::insertTail(Instruction *inst) { assert(inst->next == 0 && inst->prev == 0); if (inst->op == OP_PHI) { if (entry) { insertBefore(entry, inst); } else if (exit) { assert(phi); insertAfter(exit, inst); } else { assert(!phi); phi = exit = inst; inst->bb = this; ++numInsns; } } else { if (exit) { insertAfter(exit, inst); } else { assert(!phi); entry = exit = inst; inst->bb = this; ++numInsns; } } }
static short BWLimiterProcess(PacketNode *head, PacketNode *tail) { int dropped = 0; DWORD currentTime = timeGetTime(); PacketNode *pac = tail->prev; // pick up all packets and fill in the current time while (pac != head) { if (checkDirection(pac->addr.Direction, BWLimiterInbound, BWLimiterOutbound)) { if ( bufSizeByte >= ((DWORD)BWQueueSizeValue*1024)) { LOG("droped with chance, direction %s", BOUND_TEXT(pac->addr.Direction)); freeNode(popNode(pac)); ++dropped; } else { insertAfter(popNode(pac), bufHead)->timestamp = timeGetTime(); ++bufSize; bufSizeByte += pac->packetLen; pac = tail->prev; } } else { pac = pac->prev; } } while (!isBufEmpty() && canSendPacket(currentTime)) { PacketNode *pac = bufTail->prev; bufSizeByte -= pac->packetLen; recordSentPacket(currentTime, pac->packetLen); insertAfter(popNode(bufTail->prev), head); --bufSize; } if (bufSize > 0) { LOG("Queued buffers : %d", bufSize); } return (bufSize>0) || (dropped>0); }
/** * Inserts a node in the list, sorted using compFcn */ void List::insertSorted(Node *pNode) { Node *p; // if no priority function, assume FIFO and insert node last in list if (compFcn == NULL) { appendNode(pNode); return; } p = pTail; // insertion sort, starting from end of list if (p==NULL) { appendNode(pNode); return; } while (p!=NULL) { if (!compFcn(pNode,p)) { // if pNode does not beat p, insert after p insertAfter(pNode,p); return; } p = p->pPrev; } insertBefore(pNode,pHead); // strictly lowest priority value, insert first }
Poly polyMultiply2( Poly A, Poly B){ Poly l = newPoly(); if (NULL == l) return l; Position a = first( A ); while ( NULL != a) { Position b = first( B ); Position pl = l; while (NULL != b) { int exp = a->exp * b->exp; while ( NULL != pl->next && pl->next->exp > exp) //start position for this round of insertion pl = pl->next; if ( NULL != pl->next && pl->next->exp == exp) pl->next->coeff += a->coeff * b->coeff; else insertAfter( a->coeff * b->coeff, exp, l, pl); b = b->next; } a = a->next; } return l; }
int main() { int count = 0; int total = 0; int largest = INT_MIN; Element i; Vector vector = createVector(); V_Iterator it = getEnd(&vector); while( (scanf("%d",&i) == 1 ) ) { if(vector.size == 0 ) prepend(&vector,i); else { insertAfter(&it,i); moveNext(&it); } if( i > largest) largest = i; } printf( "Valor máximo: %d\n", largest); it = getBegin(&vector); while( it.index < vector.size ) { i = getElement(&it); // if( largest % i == 0 ) { total += i; count++; // } moveNext(&it); } if(count != 0) printf( "Média: %d\n", (total/count)); }
void *batch(void* arg) { int execution = (int)arg; Linked_list *threads, *node; int ret, matches, req_count=0; unsigned long delay; pthread_t *t1; threads = createList(NULL, NULL); do { req_count++; //fprintf(stderr, "will scanf\n"); matches = fscanf(fd, "%lu\n", &delay); fprintf(stderr, "%lu waiting %ld\n", time_millis(), delay); usleep(delay); t1 = malloc(sizeof(pthread_t)); ret = pthread_create(t1, NULL, request, (void *) &delay); if (ret != 0) fprintf(stderr, "ERROR creating request thread %i\n", ret); else insertAfter(t1, threads); } while (matches != EOF && req_count < MAX_REQ); hasnext = matches != EOF; sem_post(sem); for(node = threads->next; node != NULL; node = node->next) { fprintf(stderr, "%lu join request %d ", time_millis(), execution); t1 = (pthread_t*)(node->value); fprintf(stderr, "%ld\n", t1); pthread_join(*t1, NULL); } return (void*)&matches; }
// inserts the point p, which must ly on the boarder of the polygon, between the two points p1 and p2 // returns the index to that point, which is inserted only once ListIterator<DPoint> DPolygon::insertPoint( const DPoint &p, ListIterator<DPoint> p1, ListIterator<DPoint> p2) { ListIterator<DPoint> i = p1; do { DSegment seg = segment(i); if (seg.contains(p)) { if (seg.start() == p) return i; else if (seg.end() == p) { i = cyclicSucc(i); return i; } else return insertAfter(p, i); } i = cyclicSucc(i); } while (i != p2); OGDF_ASSERT(false); // Point not in polygon, should not be reached! return i; }
int main() { struct node* head = NULL; append(&head, 6); push(&head, 7); push(&head, 1); append(&head, 4); insertAfter(head->next, 8); printf("\n Created DLL is: "); printList(head); getchar(); return 0; }
//helper recursive function for DFS int visit(Graph G, List S, int u, int* time, int k){ *time = *time + 1; G->vdiscover[u] = *time; G->vcolor[u]= 'g'; G->vcc[u]=k; moveTo(G->vneighbor[u],0); while (getIndex(G->vneighbor[u]) > -1) { int v; v = getElement(G->vneighbor[u]); if (G->vcolor[v] == 'w') { G->vparent[v] = u; visit(G, S, v, time, k); } moveNext(G->vneighbor[u]); } G->vcolor[u]='b'; *time = *time + 1; G->vfinish[u] = *time; if (getIndex(S) > -1) { insertAfter(S, u); } else { prepend(S, u); } return *time; }
//CSLL void traverse(node temp) { if(temp != NULL) { Node curr = temp; do{ curr = curr.next; } while(curr != temp); } void insertAfter(Node node, Node newNode) { if(node == NULL) newNode.next = newNode; else { newNode.next = node.next; node.next = newNode; } } void insertBack(Node tail, Node newNoe) { insertAfter(tail, newNode); tail = newNode; }
void addinterval(void *space, List *list, Uint a, Uint b) { PairUint *range; range = ALLOCMEMORY(space, NULL, PairUint, 1); range->a=a; range->b=b; if (list->length == 0) { insertAfter(space, list, LISTNILVALUE, range); } else { insertAfter(space, list, list->lastNode, range); } return; }
void insertEnd(LIST_HEAD *list, NODE *newNode) { if (list->tail == NULL) { insertFirst(list, newNode); } else { insertAfter(list, list->tail, newNode); } }
void putFileinList(list_ref list, FILE *input, char *filename, int after) { char buffer[1024]; int linenr = 1; for (; ; ++linenr) { char *linepos = fgets (buffer, sizeof buffer, input); if (linepos == NULL) break; linepos = strchr (buffer, '\n'); if (linepos == NULL) { fflush (NULL); fprintf (stderr, "%s: %s[%d]: unterminated line\n", Exec_Name, filename, linenr); fflush (NULL); Exit_Status = EXIT_FAILURE; } else { *linepos = '\0'; } linepos = strdup (buffer); assert (linepos != NULL); if(after == 1) { insert_list (list, linepos); } else { insertAfter(list, linepos, last); } } if(after == 1) { printf("%s: %d lines read from %s.\n", Exec_Name, counter(list, last), filename); } else { printf("%s: %d lines read from %s.\n", Exec_Name, linenr-1, filename); } }
void Enqueue(Queue *Q, void* element) { pthread_mutex_lock(&(Q->mutex)); insertAfter(element, Q->rear); Q->rear = Q->rear->next; pthread_mutex_unlock(&(Q->mutex)); sem_post(Q->sem); return; }
void addItem( int coeff, int exp, Poly L ){ Position p = findPreviousNode( exp, L ); if( !isLast(p,L) && p->next->exp == exp ) p->next->coeff += coeff; else insertAfter( coeff, exp, L, p); }
/* * Insert a DbgAssertRefCount instruction after each place we produce * a refcounted value. The value must be something we can safely dereference * to check the _count field. */ static void insertRefCountAsserts(IRInstruction& inst, IRUnit& unit) { for (SSATmp& dst : inst.dsts()) { Type t = dst.type(); if (t <= (Type::Counted | Type::StaticStr | Type::StaticArr)) { insertAfter(&inst, unit.gen(DbgAssertRefCount, inst.marker(), &dst)); } } }
void insertFront(Node tail, Node newNode) { insertAfter(tail, newNode); if(tail == NULL) { tail = newNode; } }
static void clearBufPackets(PacketNode *tail) { PacketNode *oldLast = tail->prev; LOG("Cap end, send all %d packets. Buffer at max: %s", bufSize, bufSize); while (!isBufEmpty()) { insertAfter(popNode(bufTail->prev), oldLast); --bufSize; } }
/* * Insert a DbgAssertRefCount instruction after each place we produce * a refcounted value. The value must be something we can safely dereference * to check the _count field. */ static void insertRefCountAsserts(IRInstruction& inst, IRFactory& factory) { for (SSATmp& dst : inst.dsts()) { Type t = dst.type(); if (t.subtypeOf(Type::Counted | Type::StaticStr | Type::StaticArr)) { insertAfter(&inst, factory.gen(DbgAssertRefCount, inst.marker(), &dst)); } } }
ListN& ListN::operator=(const ListN& l) { Node* temp = head = l.head; while(temp != NULL) { insertAfter(temp->data); temp = temp->next; } }
/*! insert a layer at the end of list */ void DoubleLinkedList::insertBack (Layer * l){ if(this->botlayer==NULL){ //std::cout<<"insert at back"; insertFront(l); } else { //std::cout<<"insert at back"; insertAfter(l,this->botlayer); } };
/* * Allocate a new point and initialize it to x,y. Then * add that point to the SortedPoints list. Return * 1 on success and 0 on error (e.g., out of memory). */ int sp_addNewPoint(SortedPoints *sp, double x, double y) { Point ORIGIN; ORIGIN.x = 0; ORIGIN.y = 0; // Local iterator node Node *curr; // Allocate memory for the new node Node *n; n = (Node *)malloc(sizeof(Node)); if (!n) return 0; // malloc() returns a NULL pointer if not enough memory. // Initializing the new node 'n' n->p.x = x; n->p.y = y; // Inserting the new node in the correct place in the linked list // If the list is empty, add the point as the head. if (sp->head == NULL) { sp->head = n; return 1; } curr = sp->head; while (curr != NULL) { if (point_distance(&n->p, &ORIGIN) < point_distance(&curr->p, &ORIGIN)) { insertBefore(sp, n, curr); return 1; } if(point_distance(&n->p, &ORIGIN) == point_distance(&curr->p, &ORIGIN)) { if(n->p.x < curr->p.x) { insertBefore(sp, n, curr); return 1; } if(n->p.x == curr->p.x && n->p.y < curr->p.y) { insertBefore(sp, n, curr); return 1; } } curr = curr->next; } // If we reach this point, n is not less than any of the other nodes and // we add it to the end of the list curr = sp->head; while (curr->next != NULL) curr = curr->next; insertAfter(n, curr); return 1; }
/* Insert a node somewhere in the linked list * * node The node to insert * * @discussion If the node matches one already in the list, then "node" is * freed. */ void insertNode(InDel *node, int k) { int direction; //Deal with the first node if(lastTargetNode == firstTargetNode && firstTargetNode->next == NULL) { insertAfter(node, firstTargetNode); lastTargetNode = node; return; } direction = TargetNodeCmp(node, lastTargetNode, k); //Always come from the left while(direction>=0 && lastTargetNode->next != NULL) { lastTargetNode = lastTargetNode->next; direction = TargetNodeCmp(node, lastTargetNode, k); } if(direction > 0) { insertAfter(node, lastTargetNode); lastTargetNode = node; return; } else if(direction == 0) { mergeNodes(node, k); destroyNode(node); return; } assert(direction < 0); while(lastTargetNode->prev != NULL && direction < 0) { lastTargetNode = lastTargetNode->prev; direction = TargetNodeCmp(node, lastTargetNode, k); } if(direction != 0) { insertAfter(node, lastTargetNode); lastTargetNode = node; return; } else if(direction == 0) { mergeNodes(node, k); destroyNode(node); return; } assert(1==0); }
static LinkedNode *insertBack(LinkedList *list, void *value) { if (list->front == NULL) { return insertFront(list, value); } else { return insertAfter(list, list->back, value); } }
void LWPGradient::addNewKey(double frac) { LWPGradientKey * k = new LWPGradientKey; k->frac = frac; k->col = evaluateColor(k->frac); LWPGradientKey * before; for (before = head; before->next->frac <= frac; before = before->next); insertAfter(before, k); sel = k; }
static void clearBufPackets(PacketNode *tail) { PacketNode *oldLast = tail->prev; LOG("Throttled end, send all %d packets. Buffer at max: %s", bufSize, bufSize == KEEP_AT_MOST ? "YES" : "NO"); while (!isBufEmpty()) { bufSizeByte -= bufTail->prev->packetLen; insertAfter(popNode(bufTail->prev), oldLast); --bufSize; } BWLimiterStartTick = 0; }
/* * Insert asserts at various points in the IR. * TODO: t2137231 Insert DbgAssertPtr at points that use or produces a GenPtr */ static void insertAsserts(Trace* trace, IRFactory* factory) { forEachTraceBlock(trace, [=](Block* block) { for (auto it = block->begin(), end = block->end(); it != end; ) { IRInstruction& inst = *it; ++it; if (inst.getOpcode() == SpillStack) { insertSpillStackAsserts(inst, factory); continue; } if (inst.getOpcode() == Call) { SSATmp* sp = inst.getDst(); IRInstruction* addr = factory->gen(LdStackAddr, sp, factory->defConst(0)); insertAfter(&inst, addr); insertAfter(addr, factory->gen(DbgAssertPtr, addr->getDst())); continue; } if (!inst.isBlockEnd()) insertRefCountAsserts(inst, factory); } }); }
ListN::ListN(const ListN& l) { Node* temp = head = l.head; int i; cout << head->data << endl; while(temp != NULL) { insertAfter(temp->data); i++; temp = temp->next; } }