void Trace::append(const AIRCRAFT_STATE& state) { if (empty()) { task_projection.reset(state.get_location()); task_projection.update_fast(); m_last_point.time = null_time; } else if (trace_tree.size() > 0 && state.Time < fixed(m_last_point.time)) { clear(); return; } TracePoint tp(state); if ((tp.time - m_last_point.time) < 2) return; tp.project(task_projection); tp.last_time = m_last_point.time; TraceTree::const_iterator it_this = trace_tree.insert(tp); m_last_point = tp; // update deltas. Last point is always high delta delta_map[tp.time].distance = null_delta; delta_map[tp.time].time = null_time; TraceTree::const_iterator it_prev = find_prev(tp); if (it_prev != end()) update_delta(find_prev(*it_prev), it_prev, it_this); }
void Trace::erase(TraceTree::const_iterator& rit) { /// @todo merge data for erased point? if (rit == trace_tree.end()) return; TraceTree::const_iterator it_prev = find_prev(*rit); TraceTree::const_iterator it_next = find_next(*rit); // don't erase if last or first point in tree if ((it_prev == trace_tree.end()) || (it_next == trace_tree.end())) return; // create new point representing the next point since this is merged with it TracePoint tp_next = *it_next; tp_next.last_time = it_prev->time; // remove erased point from the delta map delta_map.erase(rit->time); // remove current (deletion), and next (to be replaced) trace_tree.erase(rit); trace_tree.erase(it_next); // insert point replacement it_next = trace_tree.insert(tp_next); // recompute data for previous and replacement point update_delta(find_prev(*it_prev), it_prev, it_next); update_delta(it_prev, it_next, find_next(*it_next)); }
void Trace::erase(TraceTree::const_iterator& rit) { /// @todo merge data for erased point? if (rit == trace_tree.end()) return; TraceTree::const_iterator it_prev = find_prev(*rit); TraceTree::const_iterator it_next = find_next(*rit); if ((it_prev == trace_tree.end()) || (it_next == trace_tree.end())) return; TracePoint tp_next = *it_next; tp_next.last_time = it_prev->time; distance_delta_map.erase(rit->time); time_delta_map.erase(rit->time); trace_tree.erase(rit); trace_tree.erase(it_next); it_next = trace_tree.insert(tp_next); update_delta(find_prev(*it_prev), it_prev, it_next); update_delta(it_prev, it_next, find_next(*it_next)); }
int flist_prev_mismatch(const FileView *view) { return (view->custom.type == CV_DIFF) ? find_prev(view, &is_mismatched_entry) : view->list_pos; }
GSList* g_slist_remove_all (GSList *list, gconstpointer data) { GSList *next = list; GSList *prev = NULL; GSList *current; while (next) { GSList *tmp_prev = find_prev (next, data); if (tmp_prev) prev = tmp_prev; current = prev ? prev->next : list; if (!current) break; next = current->next; if (prev) prev->next = next; else list = next; g_slist_free_1 (current); } return list; }
/* * del_uglymem * * free an uglymem-entry */ static void del_uglymem(UGLYMEM * umem) { UGLYMEM *prev = find_prev(umem); /* unlink from list */ if (prev) { prev->next = umem->next; } else { first = umem->next; } /* check for damaged wall */ if (!ugly_walldamaged(umem)) { /* wall ok: * * fill memory with $DEADBEEF, * free memory */ fill_mem4(umem->lower, umem->size + 2 * UMEM_WALLSIZE, deadbeef); free(umem->lower); } /* free memory structure */ umem->lower = NULL; umem->upper = NULL; umem->size = 0; umem->file = NULL; umem->line = 0; free(umem); }
void insert(int v) { int now = find_prev(v + 1); if(value[now] == v) { ++count[now]; splay(now); } else { int prev = find_prev(v); splay(prev); son[++total][1] = son[prev][1]; fa[son[prev][1]] = total; son[prev][1] = total; fa[total] = prev; count[total] = 1; value[total] = v; splay(total); } }
void delete_elem(struct item **head, item *elem) { if (elem == *head) delete_head(head); else { struct item *p = find_prev(*head, elem); p->next = elem->next; free(elem); } }
//Queue function to add nodes to a ll such that the head is retained void queue (int data) { if (!head) { head = (struct node*) malloc(sizeof(struct node)); head->data = data; head->next = NULL; return; } struct node* tmp = (struct node*) malloc(sizeof(struct node)); struct node* prev = find_prev(head); prev->next = tmp; tmp->data = data; tmp->next = NULL; }
// Same preconditions as 'segregate' // Post: !empty() void add_ordered_block(void * const block, const size_type nsz, const size_type npartition_sz) { // This (slower) version of add_block segregates the // block and merges its free list into our free list // in the proper order // Find where "block" would go in the free list void * const loc = find_prev(block); // Place either at beginning or in middle/end if (loc == 0) add_block(block, nsz, npartition_sz); else nextof(loc) = segregate(block, nsz, npartition_sz, nextof(loc)); }
GSList* g_slist_remove (GSList *list, gconstpointer data) { GSList *prev = find_prev (list, data); GSList *current = prev ? prev->next : list; if (current) { if (prev) prev->next = current->next; else list = current->next; g_slist_free_1 (current); } return list; }
// pre: chunk was previously returned from a malloc() referring to the // same free list // post: !empty() void ordered_free(void * const chunk) { // This (slower) implementation of 'free' places the memory // back in the list in its proper order. // Find where "chunk" goes in the free list void * const loc = find_prev(chunk); // Place either at beginning or in middle/end if (loc == 0) free(chunk); else { nextof(chunk) = nextof(loc); nextof(loc) = chunk; } }
/** * mono_mlist_remove_item: * @list: the managed list * @data: the object to remove from the list * * Remove the list node @item from the managed list @list. * Since managed lists are singly-linked, this operation can take O(n) time. */ MonoMList* mono_mlist_remove_item (MonoMList* list, MonoMList *item) { MonoMList* prev; if (list == item) { list = item->next; item->next = NULL; return list; } prev = find_prev (list, item); if (prev) { MONO_OBJECT_SETREF (prev, next, item->next); item->next = NULL; return list; } else { /* not found */ return list; } }
void format(struct item *head) { struct item *elem1 = head; struct item *elem2 = head->next; while (elem1 != NULL && elem1->next != NULL) { elem2 = elem1->next; while (elem2 != NULL) { if (elem1->power == elem2->power) { elem1->num = elem1->num + elem2->num; struct item *prev = find_prev(head, elem2); delete_elem(&head, elem2); elem2 = prev->next; } else elem2 = elem2->next; } elem1 = elem1->next; } }
void remove(int v) { int prev = find_prev(v + 1); splay(prev); if(count[prev] > 1) { --count[prev]; } else { root = son[prev][0]; fa[root] = 0; int u = root, p = 0; while(u) { p = u; u = son[u][1]; } son[p][1] = son[prev][1]; fa[son[prev][1]] = p; splay(p); } }
void solve() { value[++total] = -99999999; count[total] = 1; root = total; int N; std::scanf("%d", &N); for(int i = 0; i != N; ++i) { int opt, x; std::scanf("%d %d", &opt, &x); switch(opt) { case 1: insert(x); break; case 2: remove(x); break; case 3: std::printf("%d\n", find_rank(x) - 1); break; case 4: std::printf("%d\n", find_kth(x + 1)); break; case 5: opt = find_prev(x); splay(opt); std::printf("%d\n", value[opt]); break; case 6: opt = find_next(x); splay(opt); std::printf("%d\n", value[opt]); break; } } }
int flist_prev_dir(const FileView *view) { return find_prev(view, &fentry_is_dir); }
/* 测试程序: */ int main() { int i; init(); #if 1 // push_front test: puts("push_front test:"); for(i=0; i<MAXN+2; i++) { push_front(2*i+1); show(); } puts("pop_front test:"); for(i=0; i<MAXN+2; i++) { pop_front(); show(); } #endif #if 1 // push_back test: puts("push_back test:"); for(i=0; i<MAXN+2; i++) { push_back((i+1)*10); show(); } puts("pop_back test:"); for(i=0; i<MAXN+1; i++) { pop_back(); show(); } #endif #if 1 // insert test: puts("insert test:"); for(i=0; i<MAXN+2; i++) { insert(idata, (i+1)*10); show(); } puts("clear...\n"); clear(); #endif #if 1 // insert_after test: puts("insert_after test:"); push_back(-99); for(i=0; i<MAXN+1; i++) { insert_after(idata, i+1); show(); } puts("clear...\n"); clear(); #endif #if 1 // find test: puts("find test:"); for(i=0; i<MAXN/2; i++) { push_front(MAXN-i); push_back(MAXN/2-i); //show(); } show(); info(); for(i=0; i<MAXN; i++) { int val = rand()%(2*MAXN); pointer p = find(val); if( p != NPTR ) printf("%3d %3d found at %d\n", val, dataof(p), p); else printf("%3d not found\n", val); } #endif #if 1 puts("\nfind_prev test:"); for(i=0; i<MAXN; i++) { int val = rand()%(2*MAXN); pointer p = find_prev(val); if( p != NPTR ) printf("%3d %3d found at %d's next.\n", val, dataof(nextof(p)), p); else printf("%3d not found\n", val); } #endif #if 1 // find_prev and insert_after test: clear(); puts("\nfind_prev and insert_after test:"); for(i=0; i<MAXN/2; i++) { push_front(MAXN/2-i); } show(); for(i=0; i<MAXN/2; i++) { int val = rand()%(2*MAXN), n=-(i+1); pointer p = find_prev(val); if( p != NPTR ) { printf("insert %d to front of %d:", n, val); insert_after(p, n); show(); } } #endif #if 1 // find and insert test: clear(); puts("\nfind and insert test:"); for(i=0; i<MAXN/2; i++) { push_front(MAXN/2-i); } show(); for(i=0; i<MAXN/2; i++) { int val = rand()%MAXN, n=-(i+1); pointer p = find(val); if( p != NPTR ) { printf("insert %d to after of %d:", n, val); insert_after(p, n); show(); } } #endif puts("end of main()."); return 0; }
void list_unlink(int* first, int* next, int head, int node) { list_unlink_after(first, next, head, node, find_prev(first, next, head, node)); }
int flist_prev_selected(const FileView *view) { return find_prev(view, &is_entry_selected); }
size_t text_find_prev(Text *txt, size_t pos, const char *s) { return find_prev(txt, pos, s, false); }
size_t text_line_find_prev(Text *txt, size_t pos, const char *s) { return find_prev(txt, pos, s, true); }