int main() { long i; o_t *o; printf("starting \n"); o = create_order(); for(i=100000; i>=0; i-- ) insert_bottom( o, p(i) ); for(i=100001; i< 300007; i+=2 ) { insert_after(o, p(i+1), p(i-1) ); insert_before( o, p(i), p(i+1) ); } printf("inserted 300000 elements. "); for(i = 250000; i < 300007; i++ ) delete_o( o, p(i) ); printf("deleted 50000 elements. "); insert_top( o, p(300006) ); for(i = 250000; i < 300006; i++ ) insert_before( o, p(i) , p(300006) ); printf("reinserted. now testing order\n"); for( i=0; i < 299000; i +=42 ) { if( compare( o, p(i), p(i+23) ) != 1 ) { printf(" found error (1) \n"); exit(0); } } for( i=300006; i >57; i -=119 ) { if( compare( o, p(i), p(i-57) ) != 0 ) { printf(" found error (0) \n"); exit(0); } } printf("finished. no problem found.\n"); }
static void try_add_result(struct list *list, unsigned relevance, char *name) { struct result *result, *r; assert(list != NULL); if (relevance == 0) return; result = new_result(list, relevance, name); if (is_empty(list)) return insert_before(list, NULL, result); /* * We know the list is not empty and therefor list->last is set. * If the list is not full just add the result at the end. */ if (cmp_results(list->last, result) > 0) { if (!is_full(list)) insert_before(list, NULL, result); return; } /* * Insert the result in a sorted manner */ for (r = list->first; r; r = r->next) if (cmp_results(r, result) < 0) break; insert_before(list, r, result); }
void Labels::insert_label(double position) { int exists = 0; Label *old_label = 0; // Check every old label for existence for(old_label = first; old_label; old_label = old_label->next) { if(edl->equivalent(old_label->position, position)) { exists = 1; break; } else if(old_label->position > position) break; } if(!exists) { if(old_label) insert_before(old_label, new Label(edl, this, position)); else append(new Label(edl, this, position)); } }
int ask_position(struct node *newNode) { printf("\nThe linked list is "); int check=display_list(); if(check==1) { printf("\nThe inserted element becomes the first element\n"); head.next=newNode; } else { printf("\nEnter a choice\n1.Insert after an element\n2.Insert before an element\n"); int choice; scanf("%d",&choice); switch(choice) { case 1: { insert_after(newNode); break; } case 2: { insert_before(newNode); break; } default:printf("\nWrong choice.New element not inserted.\n"); } } }
int RecordLabels::toggle_label(double position) { RecordLabel *current; // find label the position is after for(current = first; current && current->position < position; current = NEXT) { ; } if(current) { //printf("position %ld current->position %ld current->original %d\n", position, current->position, current->original); if(EQUIV(current->position, position)) { // remove it remove(current); } else { // insert before it insert_before(current); current->position = position; } } else { // insert after last //printf("position %ld\n", position); append(new RecordLabel(position)); } return 0; }
List_int_Iterator push_back(List_int* list, int p) { list->count++; Node *n = (Node*)malloc(sizeof(Node)); n->p = p; insert_before(&(list->head), n); return List_int_Iterator_new( &(n->link) ); }
void insert_at_beginning(list_t *list, node_t *new_node) { if (!(list->head)) { //If list is empty _initialize_list(list, new_node); } else { //Otherwise, insert before head insert_before(list, list->head, new_node); } }
static bool insert_wildcards_match_entry( list_element **wildcards_table, struct ofp_match *match, uint16_t priority, void *data ) { assert( match != NULL ); list_element *element; for ( element = *wildcards_table; element != NULL; element = element->next ) { match_entry *entry = element->data; if ( entry->priority < priority ) { break; } assert( entry != NULL ); if ( entry->priority == priority && compare_match_strict( &entry->match, match ) ) { char match_string[ MATCH_STRING_LENGTH ]; match_to_string( match, match_string, sizeof( match_string ) ); warn( "wildcards match entry already exists ( match = [%s], priority = %u )", match_string, priority ); return false; } } match_entry *new_entry = allocate_match_entry( match, priority, data ); if ( element == NULL ) { // tail append_to_tail( wildcards_table, new_entry ); } else if ( element == *wildcards_table ) { // head insert_in_front( wildcards_table, new_entry ); } else { // insert before insert_before( wildcards_table, element->data, new_entry ); } return true; }
List_PersonPtr_Iterator push_back(List_PersonPtr* list, PersonPtr p) { list->count++; Node_PersonPtr *n = (Node_PersonPtr*)malloc(sizeof(Node_PersonPtr)); n->p = p; insert_before(&(list->head), n); return List_PersonPtr_Iterator_new( &(n->link) ); }
HistogramPoint* HistogramPoints::insert(float x, float y) { HistogramPoint *current = first; // Get existing point after new point while(current) { if(current->x > x) break; else current = NEXT; } // Insert new point before current point HistogramPoint *new_point = new HistogramPoint; if(current) { insert_before(current, new_point); } else // Append new point to list { append(new_point); } new_point->x = x; new_point->y = y; return new_point; }
List_PersonPtr_Iterator push_front(List_PersonPtr_* list, Person* person) { Node *n = Node_new(person); insert_before(list->head.next, n); List_PersonPtr_Iterator it = List_PersonPtr_it_ctor(list->head.next); list->size = list->size + 1; return it; }
List_PersonPtr_Iterator push_back(List_PersonPtr_* list, Person* person) { Node *n = Node_new(person); insert_before(&list->head, n); List_PersonPtr_Iterator it = List_PersonPtr_it_ctor(list->head.prev); list->size = list->size + 1; return it; }
//add a new node before the given index. FRISO_API void link_list_insert_before( friso_link_t link, uint_t idx, void * value ) { link_node_t node = get_node( link, idx ); if ( node != NULL ) { insert_before( link, node, value ); } }
void AddVarToTable(EEVarTable* table, EEVar* var){ TSStr* str; list_entry *list; str = StrCreate(); StrAppendS(str, var->name); list = &table->table[table->hash(str)]; insert_before(list, &var->vlist); StrDestroy(str); }
int LinkedList::insert_sort(Event *item){ if (item == NULL) { return -1; } // If the list is empty add at first position and initialize pointers if(start == NULL) { printf("Adding first item\n"); start = item; tail = item; cur = item; }else{ // Search the list from last position // Find appropriate location for the new event and place it there printf("Inserting \n"); if(cur->schedTime > item->schedTime) { // Search in backward direction printf("In backward direction \n"); while( (cur != start) && (cur->schedTime > item->schedTime)){ cur = cur->prev; } if((cur == start) && cur->schedTime > item->schedTime){ insert_before(start,item); }else{ insert_after(cur,item); } }else{ // Search in forward direction printf("In forward direction \n"); while( (cur != tail) && (cur->schedTime < item->schedTime)){ cur = cur->next; } if((cur == tail) && cur->schedTime < item->schedTime){ printf("Calling after \n"); insert_after(tail,item); }else{ printf("Calling before \n"); insert_before(cur,item); } } } printf("Insertion done \n"); return 0; }
int Labels::load(FileXML *xml, uint32_t load_flags) { int result = 0; char string1[BCTEXTLEN], string2[BCTEXTLEN]; sprintf(string1, "/%s", xml_tag); strcpy(string2, xml_tag); string2[strlen(string2) - 1] = 0; do{ result = xml->read_tag(); if(!result) { if(xml->tag.title_is(string1)) { result = 1; } else if(xml->tag.title_is(string2)) { double position = xml->tag.get_property("TIME", (double)-1); if(position < 0) position = xml->tag.get_property("SAMPLE", (double)-1); //printf("Labels::load %f\n", position); if(position > -1) { Label *current = label_of(position); current = insert_before(current, new Label(edl, this, position)); } } else if(xml->tag.title_is("INPOINT")) { double position = xml->tag.get_property("TIME", (double)-1); if(position < 0) position = xml->tag.get_property("SAMPLE", (double)-1); if(position > -1) { ; } } else if(xml->tag.title_is("OUTPOINT")) { double position = xml->tag.get_property("TIME", (double)-1); if(position < 0) position = xml->tag.get_property("SAMPLE", (double)-1); if(position > -1) { ; } } } }while(!result); return 0; }
void main() { int opt; clrscr(); do { clrscr(); printf("\npress 1 for insert beg:"); printf("\npress 2 for insert end:"); printf("\npress 3 for insert after:"); printf("\npress 4 for insert before:"); printf("\npress 5 for delete beg:"); printf("\npress 6 for delete end:"); printf("\nlpress 7 for delete after :"); printf("\npress 8 for delete before:"); printf("\npress 9 for deleter that:"); printf("\npress 10 for delete odd:"); printf("\npress 11 for delete even:"); printf("\npress 12 for sorting:"); printf("\npress 13 for reverse:"); printf("\npress 14 for insert in sorted order ;"); printf("\npress 15 for display"); printf("\nenter the option:"); scanf("%d",&opt); switch(opt) { case 1:insert_beg(&ptr); break; case 2:insert_end(&ptr);break; case 3:insert_after(&ptr);break; case 4:insert_before(&ptr);break; case 5:delete_beg(&ptr); break; case 6:delete_end(&ptr);break; case 7:delete_after(&ptr);break; case 8:delete_before(&ptr);break; /**/ case 9:delete_that(&ptr);break; case 10:delete_alter_odd(&ptr);break; case 11:delete_alter_even(&ptr);break; case 12:sort(&ptr);break; case 13:reverse(&ptr);break; /**/ case 14:insert_sort(&ptr);break; case 15:display(&ptr);break; } getch(); }while(opt!=99); getch(); }
void SimpleDLL::add_head_node(DLLNode addition) { if(!head) { head = addition; tail = addition; addition->next = NULL; addition->prev = NULL; ++this->nelems; } else { insert_before(this->head, addition); } }
static PyObject *LinkedList_insertBefore(LinkedListObject* self, PyObject *args) { LinkedListIterObject *iter; PyObject *obj; if(!PyArg_ParseTuple(args, "OO", &iter, &obj)) return NULL; if(!PyObject_TypeCheck(iter, &LinkedListIterType)) { set_iter_type_error(obj); return NULL; } return insert_before(self, iter->node, obj); }
static OFDPE insert_flow_entry( flow_table *table, flow_entry *entry, const uint16_t flags ) { assert( table != NULL ); assert( entry != NULL ); list_element *element = table->entries; while( element != NULL ) { list_element *next = element->next; flow_entry *e = element->data; assert( e != NULL ); if ( e->priority < entry->priority ) { break; } if ( e->priority == entry->priority ) { if ( e->table_miss && !entry->table_miss ) { break; } if ( ( flags & OFPFF_CHECK_OVERLAP ) != 0 && compare_match( e->match, entry->match ) ) { return ERROR_OFDPE_FLOW_MOD_FAILED_OVERLAP; } if ( compare_match_strict( e->match, entry->match ) ) { if ( ( flags & OFPFF_RESET_COUNTS ) != 0 ) { entry->byte_count = e->byte_count; entry->packet_count = e->packet_count; } flow_table *table = get_flow_table( e->table_id ); assert( table != NULL ); delete_flow_entry_from_table( table, e, 0, false ); } } element = next; } if ( element == NULL ) { // tail append_to_tail( &table->entries, entry ); } else if ( element == table->entries ) { // head insert_in_front( &table->entries, entry ); } else { // insert before insert_before( &table->entries, element->data, entry ); } increment_active_count( table->features.table_id ); return OFDPE_SUCCESS; }
// push_front(list, p1) List_int_Iterator push_front(List_int* list, int p) { list->count++; Node *n = (Node*)malloc(sizeof(Node)); n->p = p; insert_before(list->head.next, n); //printf("Test insertion into list: \n"); //printf("inserting %s \n", n->p->name); //printf("%s was inserted\n", ((Node*)(list->head.next))->p->name); // BIG POINT LEARNED: to access nodes' data when you only have a Link // object, cast the Link object to be a Node object. Nodes are constructed // such that Link objects are their first data members, so Links can be cast // to Nodes. Except the 'head' (sentinel) link. return List_int_Iterator_new( &(n->link) ); }
void replace_lap_list(TTBIN_FILE *ttbin, float *distances, unsigned count) { float end_of_lap = 0; float last_distance = 0; uint32_t i; unsigned d = 0; /* remove the current lap records */ if (ttbin->lap_records.count) { for (i = 0; i < ttbin->lap_records.count; ++i) delete_record(ttbin, ttbin->lap_records.records[i]); free(ttbin->lap_records.records); ttbin->lap_records.records = 0; ttbin->lap_records.count = 0; } /* do the check here, so that we can just remove all the laps if we want to */ if (!distances || (count == 0)) return; end_of_lap = distances[d]; for (i = 0; i < ttbin->gps_records.count; ++i) { TTBIN_RECORD *lap_record; /* skip records until we reach the desired lap distance */ if (ttbin->gps_records.records[i]->gps.cum_distance < end_of_lap) continue; /* right, so we need to add a lap marker here */ lap_record = insert_before(ttbin, ttbin->gps_records.records[i]); lap_record->tag = TAG_LAP; lap_record->length = 10; lap_record->lap.total_time = i; lap_record->lap.total_distance = ttbin->gps_records.records[i]->gps.cum_distance; lap_record->lap.total_calories = ttbin->gps_records.records[i]->gps.calories; append_array(&ttbin->lap_records, lap_record); /* get the next lap distance */ if (++d >= count) { d = 0; last_distance = end_of_lap; } end_of_lap = last_distance + distances[d]; } }
Auto* Autos::insert_auto(int64_t position) { Auto *current, *result; // Test for existence for(current = first; current && !edl->equivalent(current->position, position); current = NEXT) { ; } // Insert new if(!current) { // Get first one on or before as a template for(current = last; current && current->position > position; current = PREVIOUS) { ; } if(current) { insert_after(current, result = new_auto()); result->copy_from(current); } else { current = first; if(!current) current = default_auto; insert_before(first, result = new_auto()); if(current) result->copy_from(current); } result->position = position; // Set curve type result->mode = edl->local_session->floatauto_type; } else { result = current; } return result; }
void Labels::insert_labels(Labels *labels, double start, double length, int paste_silence) { Label *new_label; Label *old_label; //printf("Labels::insert_labels 1 %d %d\n", __LINE__, paste_silence); // Insert silence in old labels if(paste_silence) { for(old_label = first; old_label; old_label = old_label->next) { if(old_label->position > start || edl->equivalent(old_label->position, start)) old_label->position += length; } } // Insert one new label at a time for(new_label = labels->first; new_label; new_label = new_label->next) { int exists = 0; //printf("Labels::insert_labels 2 %f\n", new_label->position + start); // Check every old label for existence for(old_label = first; old_label; old_label = old_label->next) { if(edl->equivalent(old_label->position, new_label->position + start)) { exists = 1; break; } else if(old_label->position > new_label->position + start) break; } if(!exists) { if(old_label) insert_before(old_label, new Label(edl, this, new_label->position + start)); else append(new Label(edl, this, new_label->position + start)); } } }
void IRList::replace_opcode(IRInstruction* to_delete, std::vector<IRInstruction*> replacements) { auto it = m_list.begin(); for (; it != m_list.end(); it++) { if (it->type == MFLOW_OPCODE && it->insn == to_delete) { break; } } always_assert_log(it != m_list.end(), "No match found while replacing '%s'", SHOW(to_delete)); for (auto insn : replacements) { insert_before(it, insn); } remove_opcode(it); }
void insert_match_entry( struct ofp_match *ofp_match, uint16_t priority, const char *service_name, const char *entry_name ) { match_entry *new_entry, *entry; list_element *list; pthread_mutex_lock( match_table_head.mutex ); new_entry = allocate_match_entry( ofp_match, priority, service_name, entry_name ); if ( !ofp_match->wildcards ) { entry = lookup_hash_entry( match_table_head.exact_table, ofp_match ); if ( entry != NULL ) { warn( "insert entry exits" ); free_match_entry( new_entry ); pthread_mutex_unlock( match_table_head.mutex ); return; } insert_hash_entry( match_table_head.exact_table, &new_entry->ofp_match, new_entry ); pthread_mutex_unlock( match_table_head.mutex ); return; } // wildcard flags are set for ( list = match_table_head.wildcard_table; list != NULL; list = list->next ) { entry = list->data; if ( entry->priority <= new_entry->priority ) { break; } } if ( list == NULL ) { // wildcard_table is null or tail append_to_tail( &match_table_head.wildcard_table, new_entry ); pthread_mutex_unlock( match_table_head.mutex ); return; } if ( list == match_table_head.wildcard_table ) { // head insert_in_front( &match_table_head.wildcard_table, new_entry ); pthread_mutex_unlock( match_table_head.mutex ); return; } // insert brefore insert_before( &match_table_head.wildcard_table, list->data, new_entry ); pthread_mutex_unlock( match_table_head.mutex ); }
Auto* Autos::insert_auto(int64_t position, Auto *templ) { Auto *current, *result; // Test for existence for(current = first; current && !edl->equivalent(current->position, position); current = NEXT) { ; } // Insert new if(!current) { // Get first one on or before as a template for(current = last; current && current->position > position; current = PREVIOUS) { ; } if(current) { insert_after(current, result = new_auto()); } else { current = first; if(!current) current = default_auto; insert_before(first, result = new_auto()); } // interpolate if possible, else copy from template result->interpolate_from(0, 0, position, templ); } else { result = current; } return result; }
void free(u32int *virt_addr) { list_node_type *used_node = search_used(virt_addr); if (used_node == NULL) { return; } list_node_type *goes_before = search_free_neighbor(used_node); remove(vmm_used, used_node); insert_before(vmm_free, goes_before, used_node); compact_all_free(); }
node_ptr insert_after(element_type e, node_ptr *list) { node_ptr p, tmp_cell; if (*list == NULL) return (*list = insert_before(e, *list)); else { tmp_cell = *list; while (tmp_cell->next) tmp_cell = tmp_cell->next; p = (node_ptr)malloc(sizeof(struct node)); p->element = e; p->next = *list; p->next = NULL; tmp_cell->next = p; return p; } }
void Prio_list::insert(Prio_list_elem *e, unsigned short prio) { assert (e); e->init(prio); Iterator pos = begin(); while (pos != end() && pos->prio() > prio) ++pos; if (pos != end() && pos->prio() == prio) S_list::insert_before(e, S_list::iter(*pos)); else { S_list::self_insert(e); insert_before(e, pos); } }