//变长结构体版本 //类的概念:数据和方法都放入头节点 int main(int argc, const char *argv[]) { int i, ret; LLIST *handler; SCORE_ST tmp, *tmp_p; handler = llist_creat(sizeof(SCORE_ST)); for (i = 0; i < 7; i++) { tmp.id = i; snprintf(tmp.name, NAMESIZE, "middle school student%d", i); tmp.math = rand() %100; tmp.chinese = rand() %100; //myprint(&tmp); llist_insert(handler, &tmp, LLIST_FORWARD); } llist_travel(handler, myprint); printf("-----------------------------------\n"); char *name = "stu3"; tmp_p = llist_find(handler, name, cmp_name); if (tmp_p) { myprint(tmp_p); }else{ printf("not find\n"); } printf("-----------------------------------\n"); int id = 2; ret = llist_fetch(handler, &id, cmp_id, &tmp); if (ret) { printf("fetch "); myprint(&tmp); } printf("-----------------------------------\n"); name ="stu0"; ret = llist_delete(handler, name, cmp_name); if (ret) { printf("delete %s\n", name); } printf("-----------------------------------\n"); llist_travel(handler, myprint); printf("-----------------------------------\n"); name = malloc(NAMESIZE); for (i = 1; i < 7; i++) { snprintf(name, NAMESIZE, "stu%d", i); ret = llist_delete(handler, name, cmp_name); if (ret) { printf("delete %s\n", name); } } llist_travel(handler, myprint); llist_destroy(handler); return 0; }
void xacml_obligation_delete(xacml_obligation_t * obligation) { if (obligation == NULL) return; if (obligation->id != NULL) free(obligation->id); llist_delete_elements(obligation->assignments,(delete_element_func)xacml_attributeassignment_delete); llist_delete(obligation->assignments); free(obligation); obligation= NULL; }
void xacml_response_delete(xacml_response_t * response) { if (response == NULL) return; if (response->request != NULL) xacml_request_delete(response->request); llist_delete_elements(response->results,(delete_element_func)xacml_result_delete); llist_delete(response->results); free(response); response= NULL; }
int create_testcols_table( Arb_connection *conn) { int rc; int col; COLUMN_DEF *colp; ARBOR_LLIST *columns; rc = llist_create( &columns, LLIST_COMPARISON_FUNC, column_cmp, LLIST_DELETE_ITEM_FUNC, free, LLIST_DUPLICATE_STRATEGY, LLIST_DUPLICATES_NOT_ALLOWED, LLIST_SORT_STRATEGY, LLIST_UNORDERED_LIST, LLIST_NO_MORE_ARGS); if( rc != SUCCESS) abort(); for( col = 0; col < WIDGET_TABLE_NUM_COLS; ++col) { colp = (COLUMN_DEF *) calloc (1, sizeof (COLUMN_DEF)); assert( colp != NULL); colp->row_position = col; switch(col) { case 0: initcol_id(colp); break; case 1: initcol_quantity(colp); break; case 2: initcol_category(colp); break; case 3: initcol_langcode(colp); break; case 4: initcol_shortdesc(colp); break; case 5: initcol_wdesc(colp); break; case 6: initcol_opcode(colp); break; case 7: initcol_inceptdate(colp); break; case 8: initcol_termdate(colp); break; case 9: initcol_weight(colp); break; case 10: initcol_volume(colp); break; case 11: initcol_bitflags(colp); break; case 12: initcol_license(colp); break; default: abort(); } rc = llist_insert( columns, colp); if( rc != SUCCESS) abort(); } /* loop */ rc = arb_create_table( conn, TABLENAME, columns); if( rc != SUCCESS) abort(); llist_delete( columns); return 0; }
/* * We don't want to use this - it just takes more space that doind it by * hand time after time. */ void llist_empty(llist_list *list, void (* action) (void *)) { llist_node *node = list->head; llist_node *nextnode; while (node != NULL) { nextnode = node->next; action(node->data); llist_delete(node, list); node = nextnode; } } /* void llist_empty(llist_list *list, void (* action) (void *) */
int streambuf_delete(streambuf_t *p) { struct streambuf_iov_st *iov; struct streambuf_st *buf=p; if (buf->nr_bytes > 0) { while (streambuf_read_nb(p, &iov) ==0) { streambuf_iov_free(iov); } } pthread_mutex_destroy(&buf->mut); pthread_cond_destroy(&buf->cond); llist_delete(buf->ringbuf); free(buf); return 0; }
void multi_thread_test() { llist_t *ll; ll = llist_new(2000); pthread_t pid[10]; /* * test 4 */ int i; for (i=0; i < 6; i++) { pthread_create(&pid[i], NULL, producer, ll); } for (i=6; i<10; i++) { pthread_create(&pid[i], NULL, consumer, ll); } for (i=0; i<10; i++) { pthread_join(pid[i], NULL); } printf("nodes is %d\n", ll->nr_nodes); llist_delete(ll); printf("%stest4 successful%s\n", COR_BEGIN, COR_END); }
int main(int argc, char* argv[]) { int i; node * m; /* obligatory */ printf("Hello, World\r\n"); printf("\r\n---\r\n"); /* Node stuff */ printf("Creating and destroying 10000 nodes\r\n"); for (i = 0; i < 10000 ; i++) { int data = i; node * n = build_node(&data); destroy_node(n); } printf("Done\r\n"); printf("\r\n---\r\n"); printf("Building a queue, adding 10000 nodes. Printing out every 1000\r\n"); queue * q = build_queue(); for (i = 0; i < 10000 ; i++) { int data = i; node * n = build_node(&data); queue_push(q, n); } printf("Queue has the size %d\r\n", q->size); for (i = 0; i < 10000 ; i++) { node * n = queue_pop(q); if((i%1000)==0) { printf("Node has the data %d\r\n", *(int*)n->data); } destroy_node(n); } printf("Queue has the size %d\r\n", q->size); destroy_queue(q); printf("\r\n---\r\n"); printf("Building a stack, adding 10000 nodes. Printing out every 1000\r\n"); stack * s = build_stack(); for (i = 0; i < 10000 ; i++) { int data = i; node * n = build_node(&data); stack_push(s, n); } printf("Stack has the size %d\r\n", s->size); for (i = 0; i < 10000 ; i++) { node * n = stack_pop(s); if((i%1000)==0) { printf("Node has the data %d\r\n", *(int*)n->data); } destroy_node(n); } printf("Stack has the size %d\r\n", s->size); destroy_stack(s); printf("\r\n---\r\n"); printf("Building a linked list, adding 10000 nodes. Printing out every 1000\r\n"); llist * l = build_llist(); for (i = 0; i < 10000 ; i++) { int data = i; node * n = build_node(&data); llist_add(l, n); } printf("llist has the size %d\r\n", l->size); printf("Testing arbitrary access...\r\n"); m = llist_get(l, 87); printf("Node has the data %d\r\n", *(int*)m->data); m = llist_get(l, 3487); printf("Node has the data %d\r\n", *(int*)m->data); m = llist_get(l, 287); printf("Node has the data %d\r\n", *(int*)m->data); printf("Testing arbitrary delete...\r\n"); m = llist_get(l, 299); printf("Node has the data %d\r\n", *(int*)m->data); llist_delete(l, 299); m = llist_get(l, 299); printf("Node has the data %d\r\n", *(int*)m->data); printf("Testing mass delete...\r\n"); destroy_llist(l); printf("\r\n---\r\n"); printf("Creating and destroying 10000 single trees\r\n"); for (i = 0; i < 10000 ; i++) { int data = i; tree * n = build_tree(&data); destroy_tree(n); } printf("Done\r\n"); printf("\r\n---\r\n"); printf("Testing add/delete for trees\r\n"); int data = 2; tree * root = build_tree(&data); //for (i = 0; i < 3 ; i++) // { // int data = i; // tree * n = build_tree(&data); // destroy_tree(n); // add_leaf(&root, n, &tree_int_comp); // } data = 1; tree * leaf1 = build_tree(&data); add_leaf(&root, leaf1, &tree_int_comp); data = 0; tree * leaf2 = build_tree(&data); add_leaf(&root, leaf2, &tree_int_comp); printf("Root node has value %d before deletion\r\n", *(int*)root->data); delete_node(&(root)); printf("Root node has value %d after deletion\r\n", *(int*)root->data); destroy_tree(leaf1); destroy_tree(leaf2); printf("Done\r\n"); return 0; }
static void schan_members_leave(struct llist_header *head, char *nick) { Assert(head); llist_delete(head, (void *)nick); }
void func_test() { char *s = "this is a test"; char *s2 = "x"; void *b; int i, j; llist_t *ll; /* * test 1 */ ll = llist_new(20); for (i = 0; i < 4; i++) { if (i%3 == 0) { llist_append(ll, &s2[0]); } llist_append(ll, &s[i]); } llist_travel(ll, &show); printf("\n"); for (i = 0; i < 4; i++) { llist_prepend(ll, &s[0]); } llist_travel(ll, &show); printf("\n"); for (i = 0; i < 4; i++) { llist_prepend_nb(ll, &s[1]); } llist_travel(ll, &show); printf("\n"); llist_fetch_head(ll, &b); llist_travel(ll, &show); printf("\n"); llist_fetch_head(ll, &b); llist_travel(ll, &show); printf("\n"); llist_delete(ll); printf("%stest1 successful%s\n", COR_BEGIN, COR_END); /* * test 2 */ ll = llist_new(1000); for (j = 0; j < 100; j++) { for (i = 0; i < 10; i++) { llist_append_nb(ll, &s[i]); } } printf("append done.\n"); for (i = 0; i< 100; i++) { llist_fetch_head_nb(ll, &b); printf("%c", *(char *)b); } printf("\nthere are %d nodes\n", ll->nr_nodes); for (i = 0; i< 100; i++) { llist_get_head_nb(ll, &b); printf("%c", *(char *)b); } printf("\n"); printf("%stest2 successful%s\n", COR_BEGIN, COR_END); printf("there are %d nodes\n", ll->nr_nodes); /* * test 3 */ void *ptr, *ptr2; llist_get_head_node_nb(ll, &ptr); for (i = 0; i< 100; i++) { printf("%c", *(char *)(((llist_node_t *)ptr)->ptr)); ptr = llist_get_next_nb(ll, ptr); } printf("\nthere are %d nodes\n", ll->nr_nodes); llist_delete(ll); printf("%stest3 successful%s\n", COR_BEGIN, COR_END); return; }
/** * Move QE process out from CGroup after resource enforcement. */ int MoveOutCGroup(uint32 find_pid, const char *cgroup_name) { Assert(cgroup_name); GSimpStringPtr pkey = stringToGSimpString(cgroup_name); if (pkey == NULL) { write_log("%s Prepare CGroup name %s failed with out of memory", ENFORCER_MESSAGE_HEAD, cgroup_name); return RESENFORCER_ERROR_INSUFFICIENT_MEMORY; } Pair cgroup = getGHashNode(g_ghash_cgroup, (void *)pkey); if (cgroup == NULL) { write_log("%s Failed to move PID %u out from non-exist cgroup %s", ENFORCER_MESSAGE_HEAD, find_pid, cgroup_name); return RESENFORCER_FAIL_FIND_CGROUP_HASH_ENTRY; } else { #ifdef DEBUG_GHASH write_log("%s ########## Before remove PID %d from CGroup %s in hash in MoveOutCGroup ##########", ENFORCER_MESSAGE_HEAD, find_pid, cgroup_name); dumpGHash(g_ghash_cgroup); #endif CGroupInfo *cgi = (CGroupInfo *)(cgroup->Value); lnode *pid = llist_delete(cgi->pids, &find_pid, CGroupPidCmp); #ifdef DEBUG_GHASH write_log("%s ########## After remove PID %d from CGroup %s in hash in MoveOutCGroup ##########", ENFORCER_MESSAGE_HEAD, find_pid, cgroup_name); dumpGHash(g_ghash_cgroup); #endif if (pid) { free((int *)pid->data); free(pid); if (cgi->pids->size == 0) { cgi->to_be_deleted = 1; } } else { write_log("%s Failed to move non-exist PID %u out from CGroup %s", ENFORCER_MESSAGE_HEAD, find_pid, cgroup_name); return RESENFORCER_FAIL_FIND_CGROUP_HASH_ENTRY; } } return FUNC_RETURN_OK; }
int delete_oper(t_operlist **l, t_oper *m, t_oper_cmp cmp) { return (llist_delete((t_llist **)l, (void *)m, (t_llist_cmp)cmp)); }
int main(void) { int n, ret; void *ret1; LLIST *handle = NULL; LLIST *find = NULL; handle = llist_create(sizeof(int), NULL, NULL, NULL); while (1) { printf("please input num : "); scanf("%d", &n); if (n == -1) break; llist_insert(&n, APPEND, handle); } llist_travel(printf_s, NULL, handle); printf("\n"); printf("insert num : "); scanf("%d", &n); llist_insert(&n, 3, handle); llist_travel(printf_s, NULL, handle); printf("\n"); printf("delete num : "); scanf("%d", &n); llist_delete(&n, cmp, handle); llist_travel(printf_s, NULL, handle); printf("\n"); printf("find num : "); scanf("%d", &n); ret1 = llist_find(&n, cmp, handle); if(ret1 != NULL) printf("find = %d\n", *(int*)ret1); printf("\n"); printf("findall num : "); scanf("%d", &n); find = llist_findall(&n, cmp, handle); llist_travel(printf_s, find, handle); printf("\n"); llist_sort(cmp, handle); printf("sort:"); llist_travel(printf_s, NULL, handle); printf("\n"); ret = llist_store("./db", handle); if(ret == 0) printf("存储成功!\n"); llist_destroy(&handle); return 0; }