void sorted_merge(Node **list1 , Node **list2 ,Node **list3 ) { Node * list3_tail = NULL; while (*list1 && *list2) { if ((*list1)->data == (*list2)->data) { /* Remove both from respective list and add to list3 */ list_append(list3, &list3_tail,list_pop(list1)); list_append(list3, &list3_tail,list_pop(list2)); } else if ((*list1)->data < (*list2)->data) { list_append(list3,&list3_tail,list_pop(list1)); } else { list_append(list3,&list3_tail,list_pop(list2)); } } if (*list1) { if (list3_tail) { list3_tail->next = *list1; } else { list3_tail = *list1; } *list1 = NULL; } else if (*list2) { if (list3_tail) { list3_tail->next = *list2; } else { list3_tail = *list2; } *list2 = NULL; } }
/*---------------------------------------------------------------------------*/ void uaodv_rt_flush_all(void) { struct uaodv_rt_entry *e; while (1) { e = list_pop(route_table); if(e != NULL) memb_free(&route_mem, e); else break; } }
static void remove_position_townRemoved(void **state) { list_t *list = list_new(); town tw, tw1; list_status_t *status; tw1.place.x = 5; tw1.place.y = 5; list_put(list, tw, 0); list_put(list, tw1, 1); list_pop(list, 0, status); assert_int_equal(list_getCount(list), 0); list_delete(list); }
void _lmst_nodelist_reconstruct() { // clean list while(list_length(list_nodelist) > 0) { node_t *item = list_pop(list_nodelist); networkaddr_reference_free(item->address); memb_free(&memb_nodelist, item); } // add all nodes to list neighbor_t *item_neighbor; for(item_neighbor = list_head(component_neighbordiscovery_neighbors()); item_neighbor != NULL; item_neighbor = list_item_next(item_neighbor)) { node_t *item_node; bool found; // check for node1 found = false; for(item_node = list_head(list_nodelist); item_node != NULL; item_node = list_item_next(item_node)) { if(networkaddr_equal(item_neighbor->node1, item_node->address)) { found = true; break; } } if(!found) { if((item_node = memb_alloc(&memb_nodelist)) == NULL) { printf("ERROR[topologycontrol-lmst]: nodelist is full\n"); } else { item_node->address = networkaddr_reference_alloc(item_neighbor->node1); item_node->edge = NULL; list_add(list_nodelist, item_node); } } // check for node2 found = false; for(item_node = list_head(list_nodelist); item_node != NULL; item_node = list_item_next(item_node)) { if(networkaddr_equal(item_neighbor->node2, item_node->address)) { found = true; break; } } if(!found) { if((item_node = memb_alloc(&memb_nodelist)) == NULL) { printf("ERROR[topologycontrol-lmst]: nodelist is full\n"); } else { item_node->address = networkaddr_reference_alloc(item_neighbor->node2); item_node->edge = NULL; list_add(list_nodelist, item_node); } } } }
/*---------------------------------------------------------------------------*/ void c_route_flush_all(struct pipe* p) { struct c_route_entry *e; while(1) { e = list_pop(p->route_table); if(e != NULL) { memb_free(&p->route_mem, e); } else { break; } } }
/**@brief Funcion que libera todo los recursos alocados en memoria de una lista. @param linklist: Punteor a la lista que quiero liberar.*/ void list_free(LinkedList* linklist){ int size = linklist->nroCollection; int i; //TODO: change this for(i=0; i < (size-1); i++){ Data* aux = NULL; list_pop(linklist, aux); data_print(aux); data_free(aux); } free(linklist->front); linklist->front = 0; }
int Comms::BLPop(Context& ctx, RedisCommandFrame& cmd) { uint32 timeout; if (!string_touint32(cmd.GetArguments()[cmd.GetArguments().size() - 1], timeout)) { fill_error_reply(ctx.reply, "timeout is not an integer or out of range"); return 0; } bool lpop = cmd.GetType() == REDIS_CMD_BLPOP; for (uint32 i = 0; i < cmd.GetArguments().size() - 1; i++) { std::string v; int err = lpop ? m_kv_store->LPop(ctx.currentDB, cmd.GetArguments()[i], v) : m_kv_store->RPop(ctx.currentDB, cmd.GetArguments()[i], v); if (0 == err && !v.empty()) { RedisReply& r1 = ctx.reply.AddMember(); RedisReply& r2 = ctx.reply.AddMember(); fill_str_reply(r1, cmd.GetArguments()[i]); fill_str_reply(r2, v); FireKeyChangedEvent(ctx, ctx.currentDB, cmd.GetArguments()[i]); RedisCommandFrame list_pop(lpop ? "lpop" : "rpop"); list_pop.AddArg(cmd.GetArguments()[i]); RewriteClientCommand(ctx, list_pop); return 0; } if (err != 0 && err != mmkv::ERR_ENTRY_NOT_EXIST && err != mmkv::ERR_DB_NOT_EXIST) { FillErrorReply(ctx, err); return 0; } } if (NULL != ctx.client) { ctx.client->DetachFD(); ctx.GetBlockContext().lpop = cmd.GetType() == REDIS_CMD_BLPOP; if (timeout > 0) { ctx.block->blocking_timer_task_id = ctx.client->GetService().GetTimer().ScheduleHeapTask( new BlockListTimeout(&ctx), timeout, -1, SECONDS); } } for (uint32 i = 0; i < cmd.GetArguments().size() - 1; i++) { AddBlockKey(ctx, cmd.GetArguments()[i]); } return 0; }
/*---------------------------------------------------------------------------*/ void route_flush_all(void) { struct route_entry *e; while(1) { e = list_pop(route_table); if(e != NULL) { memb_free(&route_mem, e); } else { break; } } }
PROCESS_THREAD(can_drv_process, ev, data) { static can_cmd_t * cmd; static uint8_t mob_handle; uint8_t do_create_recv_buf = 0; PROCESS_BEGIN(); for(;;) { // wait on polling or timer event PROCESS_WAIT_EVENT(); // Post event about completed commands and free the mob for(mob_handle = 0; mob_handle < NB_MOB; ++mob_handle) { cmd = can_mob[mob_handle]; do_create_recv_buf = 0; if(cmd != NULL) { if(cmd->status != MOB_PENDING) { if(cmd->status & MOB_TX_COMPLETED) { ftimer_unregister_func(cmd->ftimer_id); can_send_callback(CAN_DRV_RC_NORM, cmd->frame, cmd->context); } else if(cmd->status & MOB_RX_COMPLETED) { can_recv_callback(cmd->frame); do_create_recv_buf = 1; } can_mob[mob_handle] = NULL; free(cmd); CAN_SET_MOB(mob_handle); CAN_MOB_ABORT(); } } if(do_create_recv_buf) { create_recv_buf(); } } // If waiting queue not empty, try to schedule waiting commands while( list_head(can_cmd_list) != 0 ) { if(can_get_mob_free() != NO_MOB) { cmd = list_pop(can_cmd_list); post_cmd(cmd); } else { break; } } } PROCESS_END(); }
void list_destroy (List *l) { Element *e; if (l != NULL) { while (l->list_size > 0) { e = list_pop (l); free (e); } } free (l); }
extern void bg_status_process_kill_job_list(List kill_job_list) { kill_job_struct_t *freeit = NULL; if (!kill_job_list) return; /* kill all the jobs from unexpectedly freed blocks */ while ((freeit = list_pop(kill_job_list))) { debug2("Trying to requeue job %u", freeit->jobid); bg_requeue_job(freeit->jobid, 0); _destroy_kill_struct(freeit); } }
static void remove_position_townIsOk(void **state) { list_t *list = list_new(); town tw, tw1, check; list_status_t *status; check.place.x = tw1.place.x = 5; check.place.y= tw1.place.y = 5; list_put(list, tw, 0); list_put(list, tw1, 1); check = list_pop(list, 1, status); assert_int_equal(tw1.place.x, check.place.x); assert_int_equal(tw1.place.y, check.place.y); list_delete(list); }
} END_TEST // Ensure a single value can be appended then popped off of a list // ✔ Data should be as expected // ✔ Size should be 0 START_TEST (test_append_2_pop_2_list) { kld_list_t * list = (kld_list_t *) new_list(); char * buf = "test data"; char * buf2 = "test data2"; list_append(list, buf); list_append(list, buf2); kld_list_node_t * tmp = (kld_list_node_t *) list_pop(list); kld_list_node_t * tmp2 = (kld_list_node_t *) list_pop(list); fail_if(tmp == NULL, "Returned value is null"); fail_if(tmp->data != "test data2", "Unexpected data value for returned list node"); fail_if(tmp2->data != "test data", "Unexpected data value for returned list node"); fail_if(list->size != 0, "Unexpected list size"); fail_if(!list_is_empty(list), "List does not report itself as empty"); } END_TEST
/* parse symbols out of tokens */ int semanter_reduce(list_t *stack, list_t *partial) { size_t funcparams = 0; token_t *op; while ((op = (token_t*)list_pop(stack))) { switch (op->lexcomp) { /* binary operators */ case tokPlus : case tokMinus : case tokTimes : case tokDivide : case tokModulo : case tokPower : case tokUnaryMinus : case tokRShift : case tokLShift : case tokBitAnd : case tokBitOr : case tokBitXor : case tokBitNot : case tokAnd : case tokOr : case tokNot : case tokEq : case tokNe : case tokGt : case tokLt : case tokGe : case tokLe : list_push(partial, symbol_operator(op->lexcomp)); break; case tokNumber: list_push(partial, symbol_number(strtold(op->lexem, NULL))); break; case tokTrue: list_push(partial, symbol_number(1.0)); break; case tokFalse: list_push(partial, symbol_number(0.0)); break; case tokId: list_push(partial, symbol_variable(op->lexem)); break; case tokFunction: list_push(partial, symbol_function(op->lexem, funcparams)); break; /* ignore these, no semantic value */ case tokComma : case tokStackEmpty : case tokNoMatch : case tokCMango : case tokOParen : case tokCParen : case tokAsign : case tokText: break; case tokEMango: funcparams++; break; /* reduction done */ case tokOMango: return 0; } } return 0; }
/* * Frees all allocated timers, and timer queues */ void timer_free_all(void) { while (!is_list_empty(passive_timers)) { Any_Type a = list_pop(passive_timers); free(a.vp); } list_free(passive_timers); passive_timers = NULL; while (!is_list_empty(active_timers)) { Any_Type a = list_pop(active_timers); free(a.vp); } list_free(active_timers); active_timers = NULL; while (!is_list_empty(persistent_timers)) { Any_Type a = list_pop(persistent_timers); free(a.vp); } list_free(persistent_timers); persistent_timers = NULL; }
static int close_subshell(ParserContext *ctx) { CommandNode *subshell; if (ctx->expr_stack == NULL) return 0; subshell = cmdnode_subshell(list_reverse(ctx->current_expr)); ctx->current_expr = list_push(list_head_list(ctx->expr_stack), subshell); ctx->expr_stack = list_pop(ctx->expr_stack); ctx->current_command = subshell; return 1; }
void* list_removeFrom(list l, int index) { if (l->len == 0) return 0; list_node n = __list_getNthNode(l, index); if (n == l->HEAD) return list_rpop(l); else if (n == l->TAIL) return list_pop(l); else { __node_remove(n); void* val = n->value; free(n); l->len -= 1; return val; } }
int launch_action(t_actions *action, t_player *player, t_kernel *kernel) { int i; i = 0; while (action->av[0] && g_functions[i].name && strcmp(action->av[0], g_functions[i].name)) ++i; if (action->av[0] && g_functions[i].name) if (g_functions[i].function(action->av, player->client, kernel)) return (-1); freetab(action->av); list_pop(&(player->actions), action); return (0); }
void Comms::WakeBlockedList(Context& ctx, const std::string& key) { std::string v; int err = ctx.GetBlockContext().lpop ? m_kv_store->LPop(ctx.currentDB, key, v) : m_kv_store->RPop(ctx.currentDB, key, v); if (0 == err && !v.empty()) { if (ctx.GetBlockContext().push_key.empty()) { RedisReply& r1 = ctx.reply.AddMember(); RedisReply& r2 = ctx.reply.AddMember(); fill_str_reply(r1, key); fill_str_reply(r2, v); if (!ctx.flags.no_wal) { RedisCommandFrame list_pop(ctx.GetBlockContext().lpop ? "lpop" : "rpop"); list_pop.AddArg(key); m_repl.WriteWAL(ctx.currentDB, list_pop); } } else { err = m_kv_store->RPush(ctx.currentDB, ctx.GetBlockContext().push_key, v); if (err < 0) { ctx.GetBlockContext().lpop ? m_kv_store->LPush(ctx.currentDB, key, v) : m_kv_store->RPush(ctx.currentDB, key, v); FillErrorReply(ctx, err); } else { fill_str_reply(ctx.reply, v); if (!ctx.flags.no_wal) { RedisCommandFrame rpoplpush("rpoplpush"); rpoplpush.AddArg(key); m_repl.WriteWAL(ctx.currentDB, rpoplpush); } } } ctx.client->Write(ctx.reply); ctx.client->AttachFD(); ClearBlockKeys(ctx); } }
void merge(List *lst, List *lst1, int (*compare)(const void *data1, const void *data2)){ Node *pNode=NULL, *pNode1=NULL; pNode = list_head(lst); pNode1 = list_head(lst1); List temp; list_init(&temp, NULL, NULL); while(pNode != NULL && pNode1 != NULL) { int cmpval = compare(list_node_data(pNode), list_node_data(pNode1)); if(cmpval < 0){ list_push(&temp, list_node_data(pNode)); pNode = list_node_next(pNode); } else{ list_push(&temp, list_node_data(pNode1)); pNode1 = list_node_next(pNode1); } } if(pNode != NULL){ while(pNode){ list_push(&temp, list_node_data(pNode)); pNode = list_node_next(pNode); } } if(pNode1 != NULL){ while(pNode1){ list_push(&temp, list_node_data(pNode1)); pNode1 = list_node_next(pNode1); } } void *data = NULL; while(list_pop(lst, &data) == 0){ /* nothing */ } pNode = list_head(&temp); while(pNode){ list_push(lst, list_node_data(pNode)); pNode = list_node_next(pNode); } list_destroy(&temp); return 0; }
/* * Deregisters previously registered custom commands and loaded extensions. */ VOID deregister_dispatch_routines( Remote * remote ) { while( TRUE ) { EXTENSION * extension = list_pop( extension_list ); if( !extension ) break; extension->deinit( remote ); free( extension ); } command_deregister_all( customCommands ); list_destroy( extension_list ); }
static int check(char *text) { int i, rc = 0, len = strlen(text); node_t *head = NULL; for (i = 0; i <= len; i++) { if (text[i] == '(' || text[i] == '[' ||text[i] == '{') head = list_push(head, text[i]); else if (text[i] == ')' || text[i] == ']' ||text[i] == '}') rc |= (list_pop(&head) != convert(text[i])); } rc |= list_size(head); list_free(&head); return rc; }
CommandNode *parser_buildtree(List tokens, Diagnostic *diag) { ParserContext ctx = {NULL, NULL, NULL, NULL}; ParserState state = ST_COMMAND; /* Open top-level subshell */ state = parser_process_token(&ctx, state, "("); while (tokens != NULL && state != ST_ERROR) { state = parser_process_token(&ctx, state, list_head_str(tokens)); tokens = tokens->next; } /* Close top-level subshell */ if (state != ST_ERROR) state = parser_process_token(&ctx, state, ")"); /* Check result status */ if (state != ST_ERROR && state != ST_REDIRECT_FILENAME && ctx.expr_stack == NULL && ctx.current_expr != NULL && ctx.current_expr->next==NULL) { /* success */ list_free(ctx.current_expr); fix_arguments_order(ctx.current_command); diag->error = 0; return ctx.current_command; } else { /* failure */ List stack; /* free all CommandNode entities */ free_command_list(ctx.current_expr); stack = ctx.expr_stack; while (stack != NULL) { free_command_list(list_head_list(stack)); stack = list_pop(stack); } diag->error = 1; diag->error_message = "Syntax error"; return NULL; } }
/* * Get the next token. */ struct t_token * scanner_next(struct t_scanner *scanner) { struct t_token *token; struct t_char *c; if (list_size(&scanner->t_pushback) > 0) { token = (struct t_token *) list_pop(&scanner->t_pushback); return token; } c = scanner_c(scanner); if (scanner_skip_whitespace(scanner)) return NULL; c = scanner_c(scanner); if (c->c_class == CC_EOF) { token = scanner_create_token(scanner, TT_EOF); scanner_token_char(scanner); } else if (c->c_class == CC_EOL) { token = scanner_parse_eol(scanner); } else if (c->c_class == CC_DIGIT) { token = scanner_parse_num(scanner); } else if (c->c_class == CC_ALPHA || c->c == '_') { token = scanner_parse_name(scanner); } else if (c->c_class == CC_OP) { token = scanner_parse_op(scanner); } else if (c->c_class == CC_DELIM) { token = scanner_parse_delim(scanner); } else if (c->c_class == CC_QUOTE) { token = scanner_parse_string(scanner); } else { token = scanner_create_token(scanner, TT_UNKNOWN); scanner_token_char(scanner); if (!scanner_nextc(scanner)) return NULL; if (scanner->debug) { scanner_print(scanner); } } return token; }
} END_TEST // Ensure popping from a list returns the expected value // ✔ Data should be as expected // ✔ Size should be 0 START_TEST (test_pop_list) { kld_list_t * list = (kld_list_t *) new_list(); char * buf = "test data"; char * buf2 = "test data2"; list_prepend(list, buf2); list_prepend(list, buf); kld_list_node_t * tmp = (kld_list_node_t *) list_pop(list); fail_if(tmp == NULL, "Returned value is null"); fail_if(tmp->data != "test data2", "Unexpected data value for returned list node"); } END_TEST
void DeleteInvalidOutputChn(){ int i = 0, j = 0, k = 0, m = 0; ChannelProgramSt *pst = NULL; Dev_prgInfo_st *inprg = NULL; for(i=0;i<list_len(clsGlobal.ucIpDestDb);i++){ UcIpDestDbSt3_st *eachChn = NULL; list_get(clsGlobal.ucIpDestDb, i, &eachChn); if(eachChn->prgList != NULL){ UcIpDestPrgMuxInfoSt_st *prg = NULL; for(j=0;j<list_len(eachChn->prgList);){ list_get(eachChn->prgList, j, &prg); if(&clsProgram.inPrgList == NULL || list_len(&clsProgram.inPrgList) <= 0){ freeUcIpDestPrg(eachChn->prgList); free(eachChn->prgList); eachChn->prgList = NULL; break; } int isInValidPrg = 1; for(k=0;k<list_len(&clsProgram.inPrgList);k++){ list_get(&clsProgram.inPrgList, k, &pst); if(pst->channelId == prg->inChn){ if(&pst->prgNodes != NULL){ for(m=0;m<list_len(&pst->prgNodes);m++){ list_get(&pst->prgNodes, m, &inprg); if(inprg->prgNum == prg->prgId) { isInValidPrg = 0; break; } } } break; } } if(isInValidPrg){ list_pop(eachChn->prgList, j); printf("===DeleteInvalidOutputChn===del\n"); }else{ j++; } } } } }
int main(void) { struct arr_list *arr; int r; arr = create_arr_list(3); printf("list push: 5, 6, 7\n"); list_push(arr, 5); list_push(arr, 6); list_push(arr, 7); print_arr_list(arr); printf("list push: 8, will auto expand\n"); list_push(arr, 8); print_arr_list(arr); printf("list remove at 2\n"); list_removeat(arr, 2); print_arr_list(arr); printf("list pop \n"); list_pop(arr); print_arr_list(arr); printf("list insert 0\n"); list_insert(arr, 0, 3); print_arr_list(arr); r = list_index(arr, 3); printf("list index 3:%d\n", r); r = list_index(arr, 7); printf("list index 7:%d\n", r); printf("list remove 3\n"); list_remove(arr, 3); print_arr_list(arr); printf("list set index 0 = 3\n"); list_set(arr, 0, 3); print_arr_list(arr); free_arr_list(arr); return 0; }
int vmm_blockdev_unregister(struct vmm_blockdev *bdev) { int rc; struct dlist *l; struct vmm_blockdev *child_bdev; struct vmm_blockdev_event event; struct vmm_classdev *cd; if (!bdev) { return VMM_EFAIL; } /* Unreg & free child block devices */ vmm_mutex_lock(&bdev->child_lock); while (!list_empty(&bdev->child_list)) { l = list_pop(&bdev->child_list); child_bdev = list_entry(l, struct vmm_blockdev, head); if ((rc = vmm_blockdev_unregister(child_bdev))) { vmm_mutex_unlock(&bdev->child_lock); return rc; } __blockdev_free(child_bdev, FALSE); } vmm_mutex_unlock(&bdev->child_lock); /* Broadcast unregister event */ event.bdev = bdev; event.data = NULL; vmm_blocking_notifier_call(&bdev_notifier_chain, VMM_BLOCKDEV_EVENT_UNREGISTER, &event); cd = vmm_devdrv_find_classdev(VMM_BLOCKDEV_CLASS_NAME, bdev->name); if (!cd) { return VMM_EFAIL; } rc = vmm_devdrv_unregister_classdev(VMM_BLOCKDEV_CLASS_NAME, cd); if (!rc) { vmm_free(cd); } return rc; }
indigo_error_t ft_hash_flow_add(ft_instance_t ft, indigo_flow_id_t id, of_flow_add_t *flow_add, ft_entry_t **entry_p) { ft_entry_t *entry; list_links_t *links; indigo_error_t rv; INDIGO_ASSERT(ft->magic == FT_HASH_MAGIC_NUMBER); LOG_TRACE("Adding flow " INDIGO_FLOW_ID_PRINTF_FORMAT, id); if (flow_add->version != OF_VERSION_1_0) { /* @fixme */ LOG_ERROR("ERROR: bad version in ft_hash_flow_add"); return INDIGO_ERROR_VERSION; } /* If flow ID already exists, error. */ if (ft_id_lookup(ft, id) != NULL) { return INDIGO_ERROR_EXISTS; } /* Grab an entry from the free list */ if ((links = list_pop(&ft->free_list)) == NULL) { ++(ft->status.table_full_errors); return INDIGO_ERROR_RESOURCE; } entry = FT_ENTRY_CONTAINER(links, table); if ((rv = ft_entry_setup(entry, id, flow_add)) < 0) { return rv; } ft_entry_link(ft, entry); ft->status.adds += 1; ft->status.current_count += 1; if (entry_p != NULL) { *entry_p = entry; } return INDIGO_ERROR_NONE; }
/** * Convenience function for completely destroying an item in the list. If the end * flag is LIST_FRONT, an item will be polled from the front of the list and its data * freed. If the end flag is set to LIST_BACK, an item will be popped off the end of * the list and the data freed. * * \param list pointer to a list * \param end indicator where to remove */ static void list_remove(list_p list, char end) { container_p cont; if(end == LIST_FRONT) { cont = list_poll(list); } else if (end == LIST_BACK) { cont = list_pop(list); } else { return; } if(cont != NULL) { if(cont->pointer == 0 && cont->data != NULL) { list->destructor(cont->data); } free(cont); } }