ATerm lf_2 ( ATerm arg0 , ATerm arg1 ) { { ATerm tmp [ 2 ] ; FUNC_ENTRY ( lf_2sym , ATmakeAppl ( lf_2sym , arg0 , arg1 ) ) ; if ( check_sym ( arg1 , lf_list_1sym ) ) { ( tmp [ 1 ] = arg_0 ( arg1 ) ) ; { ATerm atmp1010 ; ATerm atmp100 [ 2 ] ; ( atmp100 [ 0 ] = tmp [ 1 ] ) ; ( atmp100 [ 1 ] = tmp [ 1 ] ) ; while ( not_empty_list ( tmp [ 1 ] ) ) { ( atmp1010 = list_head ( tmp [ 1 ] ) ) ; ( tmp [ 1 ] = list_tail ( tmp [ 1 ] ) ) ; if ( term_equal ( arg0 , atmp1010 ) ) { FUNC_EXIT_CONST ( constant0 , make_nf0 ( lf_3sym ) ) ; } ( atmp100 [ 1 ] = list_tail ( atmp100 [ 1 ] ) ) ; ( tmp [ 1 ] = atmp100 [ 1 ] ) ; } } } if ( check_sym ( arg1 , lf_list_1sym ) ) { { ATerm atmp10 = arg_0 ( arg1 ) ; FUNC_EXIT_CONST ( constant1 , make_nf0 ( lf_4sym ) ) ; } } FUNC_EXIT ( make_nf2 ( lf_2sym , arg0 , arg1 ) ) ; } }
ATerm lf_8 ( ATerm arg0 ) { { ATerm tmp [ 2 ] ; FUNC_ENTRY ( lf_8sym , ATmakeAppl ( lf_8sym , arg0 ) ) ; if ( check_sym ( arg0 , lf_list_6sym ) ) { ( tmp [ 1 ] = arg_0 ( arg0 ) ) ; { ATerm atmp001110 ; ATerm atmp00110 [ 2 ] ; ATerm atmp0010 ; ATerm atmp000 [ 2 ] ; ( atmp000 [ 0 ] = tmp [ 1 ] ) ; ( atmp000 [ 1 ] = tmp [ 1 ] ) ; while ( not_empty_list ( tmp [ 1 ] ) ) { ( atmp0010 = list_head ( tmp [ 1 ] ) ) ; ( tmp [ 1 ] = list_tail ( tmp [ 1 ] ) ) ; ( atmp00110 [ 0 ] = tmp [ 1 ] ) ; ( atmp00110 [ 1 ] = tmp [ 1 ] ) ; while ( not_empty_list ( tmp [ 1 ] ) ) { ( atmp001110 = list_head ( tmp [ 1 ] ) ) ; ( tmp [ 1 ] = list_tail ( tmp [ 1 ] ) ) ; if ( term_equal ( atmp0010 , atmp001110 ) ) { FUNC_EXIT ( lf_8_recursive ( cons ( slice ( atmp000 [ 0 ] , atmp000 [ 1 ] ) , cons ( make_list ( atmp0010 ) , cons ( slice ( atmp00110 [ 0 ] , atmp00110 [ 1 ] ) , tmp [ 1 ] ) ) ) ) ) ; } ( atmp00110 [ 1 ] = list_tail ( atmp00110 [ 1 ] ) ) ; ( tmp [ 1 ] = atmp00110 [ 1 ] ) ; } ( atmp000 [ 1 ] = list_tail ( atmp000 [ 1 ] ) ) ; ( tmp [ 1 ] = atmp000 [ 1 ] ) ; } } } FUNC_EXIT ( make_nf1 ( lf_8sym , arg0 ) ) ; } }
int set_union(Set *setu, const Set *set1, const Set *set2) { ListElmt *member; void *data; set_init(setu, set1->match, NULL); for (member = list_head(set1); member != NULL; member = list_next(member)) { data = list_data(member); if (list_ins_next(setu, list_tail(setu), data) != 0) { set_destroy(setu); return -1; } } for (member = list_head(set2); member != NULL; member = list_next(member)) { if (set_is_member(set1, list_data(member))) { continue; } else { data = list_data(member); if (list_ins_next(setu, list_tail(setu), data) != 0) { set_destroy(setu); return -1; } } } return 0; }
static void test_list(void) { List *list = make_list(); assert_int(0, list_len(list)); list_push(list, (void *)1); assert_int(1, list_len(list)); list_push(list, (void *)2); assert_int(2, list_len(list)); Iter *iter = list_iter(list); assert_int(1, (long)iter_next(iter)); assert_int(false, iter_end(iter)); assert_int(2, (long)iter_next(iter)); assert_int(true, iter_end(iter)); assert_int(0, (long)iter_next(iter)); assert_int(true, iter_end(iter)); List *copy = list_copy(list); assert_int(2, list_len(copy)); assert_int(1, (long)list_get(copy, 0)); assert_int(2, (long)list_get(copy, 1)); List *rev = list_reverse(list); iter = list_iter(rev); assert_int(2, (long)iter_next(iter)); assert_int(1, (long)iter_next(iter)); assert_int(0, (long)iter_next(iter)); assert_int(2, list_len(rev)); assert_int(1, (long)list_pop(rev)); assert_int(1, list_len(rev)); assert_int(2, (long)list_pop(rev)); assert_int(0, list_len(rev)); assert_int(0, (long)list_pop(rev)); List *list2 = make_list(); list_push(list2, (void *)5); list_push(list2, (void *)6); assert_int(5, (long)list_shift(list2)); assert_int(6, (long)list_shift(list2)); assert_int(0, (long)list_shift(list2)); List *list3 = make_list(); assert_int(0, (long)list_head(list3)); assert_int(0, (long)list_tail(list3)); list_push(list3, (void *)1); assert_int(1, (long)list_head(list3)); assert_int(1, (long)list_tail(list3)); list_push(list3, (void *)2); assert_int(1, (long)list_head(list3)); assert_int(2, (long)list_tail(list3)); List *list4 = make_list(); list_push(list4, (void *)1); list_push(list4, (void *)2); assert_int(1, (long)list_get(list4, 0)); assert_int(2, (long)list_get(list4, 1)); assert_int(0, (long)list_get(list4, 2)); }
linked_list* merge_paths(linked_list* elist, linked_list* vlist) { list_node* enode; list_node* vnode; char* vpath; if (elist && vlist) { for (vnode = list_tail(vlist) ; vnode ; vnode = previous(vnode)) { vpath = (char*) get_value(vnode); for (enode = head(elist) ; enode ; enode = next(enode)) if (!strcmp(vpath, (char*) get_value(enode))) { remove_node(elist, enode, 0); break; } add_to_head(elist, get_value(vnode)); } } else if (vlist && head(vlist)) { return(vlist); } return(elist); }
/** * Apply a function handler to certain SIP Headers * * @param msg SIP Message * @param fwd True to traverse forwards, false to traverse backwards * @param id SIP Header ID * @param h Function handler * @param arg Handler argument * * @return SIP Header if handler returns true, otherwise NULL */ const struct sip_hdr *sip_msg_hdr_apply(const struct sip_msg *msg, bool fwd, enum sip_hdrid id, sip_hdr_h *h, void *arg) { struct list *lst; struct le *le; if (!msg) return NULL; lst = hash_list(msg->hdrht, id); le = fwd ? list_head(lst) : list_tail(lst); while (le) { const struct sip_hdr *hdr = le->data; le = fwd ? le->next : le->prev; if (hdr->id != id) continue; if (!h || h(hdr, msg, arg)) return hdr; } return NULL; }
void pq_enqueue(pq_t * pq, void * obj) { assert(pq != NULL); if (pq->list == NULL || pq->cmp(obj, list_head(pq->list))) { pq->list = list_cons(pq->list, obj); pq->sz_lst++; return; } list_t * tmp = list_init(); list_t * prev = tmp; prev->tail = pq->list; list_t * next = pq->list; while (true) { if (next == NULL || pq->cmp(obj, list_head(next))) { prev->tail = list_cons(next, obj); free(tmp); pq->sz_lst++; return; } prev = next; next = list_tail(next); } }
int postorder(const BiTreeNode *node, List *list) { /***************************************************************************** * * * Load the list with a postorder listing of the tree. * * * *****************************************************************************/ if (!bitree_is_eob(node)) { if (!bitree_is_eob(bitree_left(node))) if (postorder(bitree_left(node), list) != 0) return -1; if (!bitree_is_eob(bitree_right(node))) if (postorder(bitree_right(node), list) != 0) return -1; if (list_ins_next(list, list_tail(list), bitree_data(node)) != 0) return -1; } return 0; }
/** * Apply a function handler to certain unknown SIP Headers * * @param msg SIP Message * @param fwd True to traverse forwards, false to traverse backwards * @param name SIP Header name * @param h Function handler * @param arg Handler argument * * @return SIP Header if handler returns true, otherwise NULL */ const struct sip_hdr *sip_msg_xhdr_apply(const struct sip_msg *msg, bool fwd, const char *name, sip_hdr_h *h, void *arg) { struct list *lst; struct le *le; struct pl pl; if (!msg || !name) return NULL; pl_set_str(&pl, name); lst = hash_list(msg->hdrht, hdr_hash(&pl)); le = fwd ? list_head(lst) : list_tail(lst); while (le) { const struct sip_hdr *hdr = le->data; le = fwd ? le->next : le->prev; if (pl_casecmp(&hdr->name, &pl)) continue; if (!h || h(hdr, msg, arg)) return hdr; } return NULL; }
bool is_list_empty(struct list *list) { assert(list); return (list_begin(list) == list_tail(list) \ && list_end(list) == list_head(list)); }
int list_rem(sllist_t *lst, void **data) { sllistItm_t *ppitm, *pitm; for (ppitm = pitm = list_head(lst); pitm != NULL; ppitm = pitm, pitm = pitm->next) { if (lst->match(pitm->data, *data)) break; } if (pitm == NULL) return -1; // *data is not in the list lst if (pitm == list_head(lst)) lst->head = pitm->next; // Handle removal from the head of the list. else { ppitm->next = pitm->next; if (pitm == list_tail(lst)) lst->tail = ppitm; // Handle removal from the tail of the list. } /* if (lst->destroy != NULL) lst->destroy(data); memset(pitm, 0, sizeof(sllistItm_t)); free(pitm); */ --lst->size; return 0; }
/* set_differece */ int set_differece(Set *setd, const Set *set1, const Set *set2) { ListElmt *member; void *data; /* Initialize the set for the difference. */ set_init(setd, set1->match, NULL); /* Insert the member from set1 not in set2. */ for (member = list_head(set1); member != NULL; member = list_next(member)) { if (!set_is_member(set2, list_data(member))) { data = list_data(member); if (list_ins_next(setd, list_tail(setd), data) != 0) { set_destroy(setd); return -1; } } } return 0; }
int graph_ins_vertex(Graph *graph, const void *data) { ListElmt *element; AdjList *adjlist; int retval; // 不允许插入重复顶点 for (element = list_head(&graph->adjlists); element != NULL; element = list_next(element)) { if (graph->match(data, ((AdjList *)list_data(element))->vertex)) { return 1; } } // 插入顶点 if ((adjlist = (AdjList *)malloc(sizeof(AdjList))) == NULL) { return -1; } adjlist->vertex = (void *)data; set_init(&adjlist->adjacent, graph->match, NULL); if ((retval = list_ins_next(&graph->adjlists, list_tail(&graph->adjlists), adjlist)) != 0) { return retval; } graph->vcount++; return 0; }
void prc_die(){ Process* prc = prc_getCurrentProcess(); prc->i_should_die = TRUE; // change focus if (currFocusedProc == prc){ list_rpop(stackFocused); currFocusedProc = list_tail(stackFocused)->val; // prevous process should take a screen hw_scr_mapScreenBuffer(currFocusedProc->screen->addr); } prc->sync_lock = FALSE; krn_getIdleProcess()->sync_lock = TRUE; if (prc->exist_canvas == FALSE){ free(prc->screen->addr); free(prc->screen); } free(prc->stack); _mem_destroy(prc->heap); free(prc->heap); krn_getIdleProcess()->sync_lock = FALSE; }
/** * Rezerwuje ciągły obszar w danym segmencie. * @param vseg deskryptor segmentu. * @param size rozmiar ciągłego obszaru. * @param _res adres zmiennej, do uzupełnienia przydzielonym adresem. */ int vm_seg_reserve(vm_seg_t *vseg, vm_size_t size, void *_res) { int expand = EXPAND_UP; vm_addr_t *res = _res; size = PAGE_ROUND(size); vm_region_t *region = list_head(&vseg->regions); if (region == NULL) { if (do_first_region(vseg, ®ion)) return -1; } // sprawdzamy czy istnieje dziura pomiędzy początkiem segmentu // a pierwszym regionem if (size < region->begin - vseg->base) { *res = region->begin - size; return expand_region(vseg, region, size, EXPAND_DOWN, _res); } // Ok, no to szukamy dziury za regionem region = list_find(&vseg->regions, has_hole_after_reg, size); if (region == NULL) { if (vseg->flags & VM_SEG_EXPDOWN) { expand = EXPAND_DOWN; region = list_head(&vseg->regions); *res = region->begin - size; } else { region = list_tail(&vseg->regions); *res = region->end; } } else { *res = region->end; } return expand_region(vseg, region, size, expand, _res); }
void * queue_tail(queue_type *queue) { if(!queue) return NULL; return list_tail(queue->qlist); }
static struct link_entry *context_get_entry(HlinkBCImpl *ctxt, ULONG hlid) { struct list *entry; switch (hlid) { case HLID_PREVIOUS: entry = list_prev(&ctxt->links, &ctxt->current->entry); break; case HLID_NEXT: entry = list_next(&ctxt->links, &ctxt->current->entry); break; case HLID_CURRENT: entry = &ctxt->current->entry; break; case HLID_STACKBOTTOM: entry = list_tail(&ctxt->links); break; case HLID_STACKTOP: entry = list_head(&ctxt->links); break; default: WARN("unknown id 0x%x\n", hlid); entry = NULL; } return entry ? LIST_ENTRY(entry, struct link_entry, entry) : NULL; }
plist correct_composition_tail(plist factorization, char *genomic_sequence, char *est_sequence){ my_assert(genomic_sequence != NULL); my_assert(est_sequence != NULL); my_assert(factorization != NULL); my_assert(!list_is_empty(factorization)); pfactor tail=list_tail(factorization); size_t i=tail->EST_end+1; size_t j=tail->GEN_end+1; const size_t est_length=strlen(est_sequence); const size_t gen_length=strlen(genomic_sequence); while((i < est_length) && (j < gen_length) && (genomic_sequence[j] == est_sequence[i])) { DEBUG("Tail correction: added one base"); i++; j++; } tail->EST_end=i-1; tail->GEN_end=j-1; return factorization; }
static void slice_allocator_garbage_collect(slice_allocator_t *sa) { sa_hrtime_t now = osif_gethrtime(); int done = 0; lck_spin_lock(sa->spinlock); do { if (!list_is_empty(&sa->free)) { slice_t *slice = list_tail(&sa->free); #ifdef SA_CHECK_SLICE_SIZE if (sa != slice->sa) { REPORT0("slice_allocator_free - slice not owned by sa detected.\n") } #endif /* SA_CHECK_SLICE_SIZE */ if (now - slice->time_freed > SA_MAX_SLICE_FREE_MEM_AGE) { list_remove_tail(&sa->free); lck_spin_unlock(sa->spinlock); slice_fini(slice); osif_free(slice, sa->slice_size); lck_spin_lock(sa->spinlock); } else { done = 1; } } else { done = 1; } } while (!done);
static void test_empty(void) { struct list_node *spos, *ssafe; struct node *pos, *safe; check(!slist_is_empty(&slist), "slist is empty but slist_is_empty returned false"); check(!list_is_empty(&list), "list is empty but list_is_empty returned false"); check(slist_head(&slist) != &slist, "slist is empty but slist_head returned non-self"); check(list_head(&list) != NULL, "list is empty but list_head returned non-NULL"); check(slist_tail(&slist) != &slist, "slist is empty but slist_tail returned non-self"); check(list_tail(&list) != NULL, "list is empty but list_tail returned non-NULL"); check_loop_never(slist_for_each(spos, &slist), "slist is empty, but slist_for_each looped"); check_loop_never(list_for_each(pos, &list), "list is empty, but list_for_each looped"); check_loop_never(slist_for_each_safe(spos, ssafe, &slist), "slist is empty, but slist_for_each_safe looped"); check_loop_never(list_for_each_safe(pos, safe, &list), "list is empty, but list_for_each_safe looped"); check_loop_never(slist_for_each_entry(pos, &slist, node), "slist is empty, but slist_for_each_entry looped"); check_loop_never(slist_for_each_entry_safe(pos, safe, &slist, node), "slist is empty, but slist_for_each-entry_safe looped"); }
list * list_append(list * x, list * y) { if(!x) { return 0; } if(!y) { return x; } x = list_tail(x); x->next = y; return list_head(y->prev = x); }
/* -------------------------------------------------------------------- Description: traverses the web of the condition variable list. We go through each semphore_elem in the list, and then consult each semaphore->waiters list for the highest priority thread. We track the sema_elem with the highest priority thread waiting on it, and return this. -------------------------------------------------------------------- */ struct semaphore* get_semaphore_to_signal(struct condition* cond) { struct list_elem* curr = list_head(&(cond->waiters)); struct list_elem* tail = list_tail(&(cond->waiters)); int curr_highest_priority = PRI_MIN; struct semaphore_elem* toSignal = NULL; struct semaphore_elem* currSemaElem; struct thread* curr_t; while (true) { curr = list_next(curr); if (curr == tail) break; currSemaElem = list_entry(curr, struct semaphore_elem, elem); ASSERT(currSemaElem != NULL); curr_t = get_highest_priority_thread(&(currSemaElem->semaphore.waiters), false); if (curr_t->priority > curr_highest_priority || toSignal == NULL) { curr_highest_priority = curr_t->priority; toSignal = currSemaElem; } } list_remove(&(toSignal->elem)); return &(toSignal->semaphore); }
machine_t *prelude__release(machine_t *machine) { object_t x; x = list_head(machine->retain); machine->retain = list_tail(machine->retain); prelude_push(machine, x); return machine; }
int set_difference(Set *setd, const Set *set1, const Set *set2) { ListElmt *member; void *data; /* * Initialize set */ set_init(setd, set1->match, NULL); /* * Insert elements that are in set1 but not set2 */ member = list_head(set1); for ( ; member != NULL; member = list_next(member)) { if (!set_is_member(set2, list_data(member))) { data = list_data(member); if (list_ins_next(setd, list_tail(setd), data) != 0) { set_destroy(setd); return -1; } } } return 0; }
/* * Find the struct objaddr for an attribute. */ static struct objaddr get_objaddr_attr( objtype_e objtype, struct list* objname, struct relation** relp, lockmode_t lockmode) { struct objaddr address; struct list* relname; oid_t reloid; struct relation* relation; const char *attname; /* Extract relation name and open relation. */ attname = str_value(lfirst(list_tail(objname))); relname = list_truncate(list_copy(objname), list_length(objname) - 1); relation = relation_openrv(nl_to_range_var(relname), lockmode); reloid = REL_ID(relation); /* Look up attribute and construct return value. */ address.classId = RelationRelationId; address.objectId = reloid; address.objectSubId = get_attnum(reloid, attname); if (address.objectSubId == INVALID_ATTR_NR) { ereport(ERROR, ( errcode(E_UNDEFINED_COLUMN), errmsg("column \"%s\" of relation \"%s\" does not exist", attname, REL_NAME(relation)))); } *relp = relation; return address; }
int set_insert(Set *set, const void *data) { if (set_is_member(set, data)) return 1; return list_ins_next(set, list_tail(set), data); }
/** * 前序遍历二叉树 */ int preorder(const BiTreeNode *node, List *list) { if (!bitree_is_eob(node)) { if (list_ins_next(list, list_tail(list), bitree_data(node)) != 0) { printf("%s\n", "preorder() insert node into list fail."); return -1; } //不是没有下级节点的节点 if (!bitree_is_eob(bitree_left(node))) { if (preorder(bitree_left(node), list) != 0) { //递归调用 printf("%s\n", "preorder() left tree order fail."); return -1; } if(!bitree_is_eob(bitree_right(node))) { if(preorder(bitree_right(node), list) != 0) {//递归调用 printf("%s\n", "preorder() right tree order end."); return -1; } } } } return 0; }
int set_intersection(Set *seti, const Set *set1, const Set *set2) { ListElmt *member; void *data; /* * Initialize set */ set_init(seti, set1->match, NULL); /* * Insert elements that are in both sets */ member = list_head(set1); for ( ; member != NULL; member = list_next(member)) { if (set_is_member(set2, list_data(member))) { data = list_data(member); if (list_ins_next(seti, list_tail(seti), data) != 0) { set_destroy(seti); return -1; } } } return 0; }
int test(struct IridiumContext * context) { struct list * l = list_new(5); assertEqual(list_tail(list_cons(l, 7)), l); return 0; }
/* * Find the ObjectAddress for an attribute. */ static ObjectAddress get_object_address_attribute(ObjectType objtype, List *objname, Relation *relp, LOCKMODE lockmode) { ObjectAddress address; List *relname; Oid reloid; Relation relation; const char *attname; /* Extract relation name and open relation. */ attname = strVal(lfirst(list_tail(objname))); relname = list_truncate(list_copy(objname), list_length(objname) - 1); relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode); reloid = RelationGetRelid(relation); /* Look up attribute and construct return value. */ address.classId = RelationRelationId; address.objectId = reloid; address.objectSubId = get_attnum(reloid, attname); if (address.objectSubId == InvalidAttrNumber) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_COLUMN), errmsg("column \"%s\" of relation \"%s\" does not exist", attname, RelationGetRelationName(relation)))); *relp = relation; return address; }