Exemple #1
0
int test_list(void)
{
	int ret = 0;
	allocator_t *allocator;
	iterator_t it,next;
	container_t *ct;

	/*
	 *allocator = allocator_creator(ALLOCATOR_TYPE_SYS_MALLOC);
	 */
	allocator = allocator_creator(ALLOCATOR_TYPE_CDS_MALLOC);
	allocator_cds_init(allocator, 0, 0, 1024);

	dbg_str(DBG_CONTAINER_DETAIL,"list allocator addr:%p",allocator);

	ct = container_creator(CONTAINER_TYPE_LIST,allocator);

	container_list_init(ct,sizeof(struct test));
	/*
	 *container_push_front(ct,&test);
	 *container_push_front(ct,&test2);
	 *container_push_front(ct,&test3);
	 */
	dbg_str(DBG_CONTAINER_DETAIL,"run at here");
	container_push_back(ct,&test);
	container_push_back(ct,&test2);
	container_push_back(ct,&test3);


	dbg_str(DBG_CONTAINER_DETAIL,"iter ordinal");
	for(	it = container_begin(ct); 
			!iterator_equal(it,container_end(ct));
			it = iterator_next(it))
	{
		print_test((struct test *)iterator_get_pointer(it));
	}

	dbg_str(DBG_CONTAINER_DETAIL,"iter insert test");
	int i = 0;
	for(	it = container_begin(ct); 
			!iterator_equal(it,container_end(ct));
			it = iterator_next(it),i++)
	{
		if(i == 1){
			break;
		}
	}
	dbg_str(DBG_CONTAINER_DETAIL,"it list_head:%p",it.pos.list_head_p);
	container_insert(ct,it,&test4);

	dbg_str(DBG_CONTAINER_DETAIL,"iter delte test");
	container_for_each_safe(it,next,ct){
		//container_delete(ct,it);
		print_test((struct test *)iterator_get_pointer(it));
	}
Exemple #2
0
int test_container_list(void)
{
	int ret = 0;
	allocator_t *allocator;
	iterator_t it,next,end;
	container_t *ct;

	allocator = allocator_creator(ALLOCATOR_TYPE_SYS_MALLOC,0);
	/*
	 *allocator = allocator_creator(ALLOCATOR_TYPE_CTR_MALLOC,0);
	 *allocator_ctr_init(allocator, 0, 0, 1024);
	 */

	dbg_str(DBG_CONTAINER_DETAIL,"list allocator addr:%p",allocator);

	ct = container_creator(CONTAINER_TYPE_LIST,allocator,0);

	container_init(ct,sizeof(struct test));
	/*
	 *container_push_front(ct,&test);
	 *container_push_front(ct,&test2);
	 *container_push_front(ct,&test3);
	 */
	container_push_back(ct,&test);
	container_push_back(ct,&test2);
	container_push_back(ct,&test3);

	dbg_str(DBG_CONTAINER_DETAIL,"iter ordinal");
	for(	container_begin(ct,&it),iterator_next(&it,&next);
			!iterator_equal(&it,container_end(ct,&end));
			it= next,iterator_next(&it,&next))
	{
		print_test((struct test *)iterator_get_pointer(&it));
	}

	container_insert(ct,&it,&test4);

	dbg_str(DBG_CONTAINER_DETAIL,"iter delte test");
	container_for_each_safe(it,next,ct){
		print_test((struct test *)iterator_get_pointer(&it));
	}