예제 #1
0
파일: test.c 프로젝트: wyt0602/data_struct
void test_queue_out()
{
    CU_ASSERT_PTR_EQUAL_FATAL(queue_out(&queue), p1);
    CU_ASSERT_PTR_EQUAL_FATAL(queue_out(&queue), p2);
    CU_ASSERT_PTR_EQUAL_FATAL(queue_out(&queue), p3);
    CU_ASSERT_PTR_EQUAL_FATAL(queue_out(&queue), p4);
    CU_ASSERT_EQUAL_FATAL(queue.queue_size, 0);
    CU_ASSERT_EQUAL_FATAL(queue.node_count, 4);
}
예제 #2
0
파일: topsort.c 프로젝트: ym65536/algorithm
void topsort(struct graph* g)
{
	int node;
	int v, w;
	int j, k;
	struct queue q;
	queue_init(&q);

	init_indegree(g, indegree);
	for (node = 0; node < g->nnode; node++)
	{
		if (indegree[node] == 0) // indegree is zero
			queue_in(&q, (unsigned int* )&node);
	}

	j = 0;
	while (!queue_empty(&q))
	{
		queue_out(&q, (unsigned int*)&v);
		sort[j] = v;
		j++;
		struct graph_node V = g->nodes[v];
		for (k = 0; k < V.nbrcount; k++)
		{
			w = V.neighbor[k].label;
			indegree[w]--;
			if (indegree[w] == 0) 
				queue_in(&q, (unsigned int* )&w);
		}
	}
}
예제 #3
0
void topsort(struct graph* p_graph)
{
    if(!p_graph)
    {
        return;
    }

    int counter = 0;

    struct vertex* p_vertex = NULL;

    struct node* p_queue_header = NULL;
    struct node* p_queue_tail   = NULL;

    queue_init(&p_queue_header,&p_queue_tail);

    int temp = 0;
    //Attention! Here we start from point 1 but not temp = 0
    for(temp = 1; temp < p_graph->num_vertex; temp++)
    {
        if(p_graph->adjacent[temp].indegree == 0)
        {
            queue_enter(&p_queue_header,
                        &p_queue_tail,
                        temp);
        }
    }

    int vertex_index = 0;

    while(!!p_queue_header)
    {
        vertex_index = queue_out(&p_queue_header,&p_queue_tail);

        printf("\t%d",vertex_index);

        p_vertex = (struct vertex*)(&p_graph->adjacent[vertex_index]);
        p_vertex = p_vertex->next;
        for(; !!p_vertex; p_vertex = p_vertex->next)
        {
            if(--(p_graph->adjacent[p_vertex->value].indegree) == 0)
            {
                queue_enter(&p_queue_header,
                            &p_queue_tail,
                            p_vertex->value);
            }
        }
    }

    printf("\n");
    queue_destory(p_queue_tail);
}
예제 #4
0
파일: Benchmark.cpp 프로젝트: NikTh/ssr
void BenchmarkScale(unsigned int in_w, unsigned int in_h, unsigned int out_w, unsigned int out_h) {

	std::mt19937 rng(12345);
	bool use_ssse3 = (CPUFeatures::HasMMX() && CPUFeatures::HasSSE() && CPUFeatures::HasSSE2() && CPUFeatures::HasSSE3() && CPUFeatures::HasSSSE3());

	// the queue needs to use enough memory to make sure that the CPU cache is flushed
	unsigned int pixels = std::max(in_w * in_h, out_w * out_h);
	unsigned int queue_size = 1 + 20000000 / pixels;
	unsigned int run_size = queue_size * 20;

	// create queue
	std::vector<std::unique_ptr<ImageGeneric> > queue_in(queue_size);
	std::vector<std::unique_ptr<ImageGeneric> > queue_out(queue_size);
	for(unsigned int i = 0; i < queue_size; ++i) {
		queue_in[i] = NewImageBGRA(in_w, in_h, rng);
		queue_out[i] = NewImageBGRA(out_w, out_h, rng);
	}

	// run test
	unsigned int time_fallback = 0, time_ssse3 = 0;
	{
		int64_t t1 = hrt_time_micro();
		for(unsigned int i = 0; i < run_size; ++i) {
			unsigned int ii = i % queue_size;
			Scale_BGRA_Fallback(in_w, in_h, queue_in[ii]->m_data[0], queue_in[ii]->m_stride[0],
								out_w, out_h, queue_out[ii]->m_data[0], queue_out[ii]->m_stride[0]);
		}
		int64_t t2 = hrt_time_micro();
		time_fallback = (t2 - t1) / run_size;
	}
	if(use_ssse3) {
		int64_t t1 = hrt_time_micro();
		for(unsigned int i = 0; i < run_size; ++i) {
			unsigned int ii = i % queue_size;
			Scale_BGRA_SSSE3(in_w, in_h, queue_in[ii]->m_data[0], queue_in[ii]->m_stride[0],
							 out_w, out_h, queue_out[ii]->m_data[0], queue_out[ii]->m_stride[0]);
		}
		int64_t t2 = hrt_time_micro();
		time_ssse3 = (t2 - t1) / run_size;
	}

	// print result
	QString in_size = QString("%1x%2").arg(in_w).arg(in_h);
	QString out_size = QString("%1x%2").arg(out_w).arg(out_h);
	Logger::LogInfo("[BenchmarkScale] " + Logger::tr("BGRA %1 to BGRA %2  |  Fallback %3 ms  |  SSSE3 %4 ms  |  %5%")
					.arg(in_size, 9).arg(out_size, 9).arg(time_fallback, 6).arg(time_ssse3, 6).arg(100 * time_ssse3 / time_fallback, 3));

}
예제 #5
0
int main(){
    queue *Q;
    Q = queue_create();
    int i ;
    for(i = 0;i < 5;i++){
        queue_in(Q,i);
    }
 
    for(i = 0;i < 5;i++){
        int test;
        test = queue_out(Q);
        printf("%d ",test);
        printf("\n");
    }

}
예제 #6
0
파일: Benchmark.cpp 프로젝트: NikTh/ssr
void BenchmarkConvert(unsigned int w, unsigned int h, const QString& in_format, const QString& out_format, NewImageFunc in_image, NewImageFunc out_image, ConvertFunc fallback, ConvertFunc ssse3) {

	std::mt19937 rng(12345);
	bool use_ssse3 = (CPUFeatures::HasMMX() && CPUFeatures::HasSSE() && CPUFeatures::HasSSE2() && CPUFeatures::HasSSE3() && CPUFeatures::HasSSSE3());

	// the queue needs to use enough memory to make sure that the CPU cache is flushed
	unsigned int pixels = w * h;
	unsigned int queue_size = 1 + 20000000 / pixels;
	unsigned int run_size = queue_size * 20;

	// create queue
	std::vector<std::unique_ptr<ImageGeneric> > queue_in(queue_size);
	std::vector<std::unique_ptr<ImageGeneric> > queue_out(queue_size);
	for(unsigned int i = 0; i < queue_size; ++i) {
		queue_in[i] = in_image(w, h, rng);
		queue_out[i] = out_image(w, h, rng);
	}

	// run test
	unsigned int time_fallback = 0, time_ssse3 = 0;
	{
		int64_t t1 = hrt_time_micro();
		for(unsigned int i = 0; i < run_size; ++i) {
			unsigned int ii = i % queue_size;
			fallback(w, h, queue_in[ii]->m_data[0], queue_in[ii]->m_stride[0], queue_out[ii]->m_data.data(), queue_out[ii]->m_stride.data());
		}
		int64_t t2 = hrt_time_micro();
		time_fallback = (t2 - t1) / run_size;
	}
	if(use_ssse3) {
		int64_t t1 = hrt_time_micro();
		for(unsigned int i = 0; i < run_size; ++i) {
			unsigned int ii = i % queue_size;
			ssse3(w, h, queue_in[ii]->m_data[0], queue_in[ii]->m_stride[0], queue_out[ii]->m_data.data(), queue_out[ii]->m_stride.data());
		}
		int64_t t2 = hrt_time_micro();
		time_ssse3 = (t2 - t1) / run_size;
	}

	// print result
	QString size = QString("%1x%2").arg(w).arg(h);
	Logger::LogInfo("[BenchmarkConvert] " + Logger::tr("%1 %2 to %3 %4  |  Fallback %5 ms  |  SSSE3 %6 ms  |  %7%")
					.arg(in_format, 6).arg(size, 9).arg(out_format, 6).arg(size, 9).arg(time_fallback, 6).arg(time_ssse3, 6).arg(100 * time_ssse3 / time_fallback, 3));

}
예제 #7
0
파일: hdata_xml.c 프로젝트: hailongz/c
static data_xpath_tag_t * data_xpath_search_tag(data_xpath_selector_t * selector,hcchar *tagName,hlist_t filters,InvokeTickDeclare){
	data_xpath_tag_t * tag = data_xpath_find_tag(selector,tagName,filters,InvokeTickArg);
	if(tag == NULL){
		data_xpath_search_tag_param_t param = {queue_alloc(),NULL,tagName,filters};
		data_xpath_selector_t * s;
		map_each(selector->child_tags, data_xpath_search_tag_map_each, &param, NULL);
		
		while(param.result==NULL && (s = queue_out(param.queue))){
			map_each(s->child_tags, data_xpath_search_tag_map_each, &param, NULL);
		}
		
		queue_dealloc(param.queue);
		return param.result;
	}
	else{
		return tag;
	}
}
예제 #8
0
int main()
{
    int x;
    pnode queue = NULL;
    init_queue(&queue);
    while (1) {
        scanf("%d", &x);
        queue_in(queue, x);
        show_queue(queue);
        scanf("%d", &x);
        queue_in(queue, x);
        show_queue(queue);

        queue_out(queue);
        show_queue(queue);
        printf("***************************\n");
    }
    return 0;
}
예제 #9
0
파일: horloge.c 프로젝트: Keynub/psys
void tic_PIT()
{
    horloge ++;

    while ((!queue_empty(&sleeping)) && horloge >= (queue_top(&sleeping, sleeping_t, chain))->clock) {
        sleeping_t *sleep = queue_out(&sleeping, sleeping_t, chain);
        process_tab[sleep->pid].state = WAITING;
        queue_add(&process_tab[sleep->pid], &process_queue, process_t, chain, prio);
        mem_free(sleep, sizeof(sleeping_t));

        // ordonnance si prioritaire ? y penser.
    }

if(cmpt==p){
	cmpt=0;	
	ordonnance();
}
else
	cmpt++;


	// TODO table des processus en attente d'un t à parcourir

}
예제 #10
0
파일: Benchmark.cpp 프로젝트: acely/ssr
void BenchmarkScale(unsigned int in_w, unsigned int in_h, unsigned int out_w, unsigned int out_h) {

	std::mt19937 rng(12345);
#if SSR_USE_X86_ASM
	bool use_ssse3 = (CPUFeatures::HasMMX() && CPUFeatures::HasSSE() && CPUFeatures::HasSSE2() && CPUFeatures::HasSSE3() && CPUFeatures::HasSSSE3());
#endif

	// the queue needs to use enough memory to make sure that the CPU cache is flushed
	unsigned int pixels = std::max(in_w * in_h, out_w * out_h);
	unsigned int queue_size = 1 + 20000000 / pixels;
	unsigned int run_size = queue_size * 20;

	// create queue
	std::vector<std::unique_ptr<ImageGeneric> > queue_in(queue_size);
	std::vector<std::unique_ptr<ImageGeneric> > queue_out(queue_size);
	for(unsigned int i = 0; i < queue_size; ++i) {
		queue_in[i] = NewImageBGRA(in_w, in_h, rng);
		queue_out[i] = NewImageBGRA(out_w, out_h, rng);
	}

	// run test
	unsigned int time_swscale = 0, time_fallback = 0, time_ssse3 = 0;
	{
		SwsContext *sws = sws_getCachedContext(NULL,
											   in_w, in_h, AV_PIX_FMT_BGRA,
											   out_w, out_h, AV_PIX_FMT_BGRA,
											   SWS_BILINEAR, NULL, NULL, NULL);
		if(sws == NULL) {
			Logger::LogError("[BenchmarkScale] " + Logger::tr("Error: Can't get swscale context!", "Don't translate 'swscale'"));
			throw LibavException();
		}
		sws_setColorspaceDetails(sws,
								 sws_getCoefficients(SWS_CS_ITU709), 0,
								 sws_getCoefficients(SWS_CS_DEFAULT), 0,
								 0, 1 << 16, 1 << 16);
		int64_t t1 = hrt_time_micro();
		for(unsigned int i = 0; i < run_size / 2; ++i) {
			unsigned int ii = i % queue_size;
			sws_scale(sws, queue_in[ii]->m_data.data(), queue_in[ii]->m_stride.data(), 0, in_h, queue_out[ii]->m_data.data(), queue_out[ii]->m_stride.data());
		}
		int64_t t2 = hrt_time_micro();
		time_swscale = (t2 - t1) / (run_size / 2);
	}
	{
		int64_t t1 = hrt_time_micro();
		for(unsigned int i = 0; i < run_size; ++i) {
			unsigned int ii = i % queue_size;
			Scale_BGRA_Fallback(in_w, in_h, queue_in[ii]->m_data[0], queue_in[ii]->m_stride[0],
								out_w, out_h, queue_out[ii]->m_data[0], queue_out[ii]->m_stride[0]);
		}
		int64_t t2 = hrt_time_micro();
		time_fallback = (t2 - t1) / run_size;
	}
#if SSR_USE_X86_ASM
	if(use_ssse3) {
		int64_t t1 = hrt_time_micro();
		for(unsigned int i = 0; i < run_size; ++i) {
			unsigned int ii = i % queue_size;
			Scale_BGRA_SSSE3(in_w, in_h, queue_in[ii]->m_data[0], queue_in[ii]->m_stride[0],
							 out_w, out_h, queue_out[ii]->m_data[0], queue_out[ii]->m_stride[0]);
		}
		int64_t t2 = hrt_time_micro();
		time_ssse3 = (t2 - t1) / run_size;
	}
#endif

	// print result
	QString in_size = QString("%1x%2").arg(in_w).arg(in_h);
	QString out_size = QString("%1x%2").arg(out_w).arg(out_h);
	Logger::LogInfo("[BenchmarkScale] " + Logger::tr("BGRA %1 to BGRA %2  |  SWScale %3 us  |  Fallback %4 us (%5%)  |  SSSE3 %6 us (%7%)")
					.arg(in_size, 9).arg(out_size, 9)
					.arg(time_swscale, 6)
					.arg(time_fallback, 6).arg(100 * time_fallback / time_swscale, 3)
					.arg(time_ssse3, 6).arg(100 * time_ssse3 / time_fallback, 3));

}
예제 #11
0
파일: Benchmark.cpp 프로젝트: acely/ssr
void BenchmarkConvert(unsigned int w, unsigned int h, PixelFormat in_format, PixelFormat out_format, const QString& in_format_name, const QString& out_format_name, NewImageFunc in_image, NewImageFunc out_image, ConvertFunc fallback
#if SSR_USE_X86_ASM
, ConvertFunc ssse3
#endif
) {

	std::mt19937 rng(12345);
#if SSR_USE_X86_ASM
	bool use_ssse3 = (CPUFeatures::HasMMX() && CPUFeatures::HasSSE() && CPUFeatures::HasSSE2() && CPUFeatures::HasSSE3() && CPUFeatures::HasSSSE3());
#endif

	// the queue needs to use enough memory to make sure that the CPU cache is flushed
	unsigned int pixels = w * h;
	unsigned int queue_size = 1 + 20000000 / pixels;
	unsigned int run_size = queue_size * 20;

	// create queue
	std::vector<std::unique_ptr<ImageGeneric> > queue_in(queue_size);
	std::vector<std::unique_ptr<ImageGeneric> > queue_out(queue_size);
	for(unsigned int i = 0; i < queue_size; ++i) {
		queue_in[i] = in_image(w, h, rng);
		queue_out[i] = out_image(w, h, rng);
	}

	// run test
	unsigned int time_swscale = 0, time_fallback = 0, time_ssse3 = 0;
	{
		SwsContext *sws = sws_getCachedContext(NULL,
											   w, h, in_format,
											   w, h, out_format,
											   SWS_BILINEAR, NULL, NULL, NULL);
		if(sws == NULL) {
			Logger::LogError("[BenchmarkScale] " + Logger::tr("Error: Can't get swscale context!", "Don't translate 'swscale'"));
			throw LibavException();
		}
		sws_setColorspaceDetails(sws,
								 sws_getCoefficients(SWS_CS_ITU709), 0,
								 sws_getCoefficients(SWS_CS_DEFAULT), 0,
								 0, 1 << 16, 1 << 16);
		int64_t t1 = hrt_time_micro();
		for(unsigned int i = 0; i < run_size / 2; ++i) {
			unsigned int ii = i % queue_size;
			sws_scale(sws, queue_in[ii]->m_data.data(), queue_in[ii]->m_stride.data(), 0, h, queue_out[ii]->m_data.data(), queue_out[ii]->m_stride.data());
		}
		int64_t t2 = hrt_time_micro();
		time_swscale = (t2 - t1) / (run_size / 2);
	}
	{
		int64_t t1 = hrt_time_micro();
		for(unsigned int i = 0; i < run_size; ++i) {
			unsigned int ii = i % queue_size;
			fallback(w, h, queue_in[ii]->m_data[0], queue_in[ii]->m_stride[0], queue_out[ii]->m_data.data(), queue_out[ii]->m_stride.data());
		}
		int64_t t2 = hrt_time_micro();
		time_fallback = (t2 - t1) / run_size;
	}
#if SSR_USE_X86_ASM
	if(use_ssse3) {
		int64_t t1 = hrt_time_micro();
		for(unsigned int i = 0; i < run_size; ++i) {
			unsigned int ii = i % queue_size;
			ssse3(w, h, queue_in[ii]->m_data[0], queue_in[ii]->m_stride[0], queue_out[ii]->m_data.data(), queue_out[ii]->m_stride.data());
		}
		int64_t t2 = hrt_time_micro();
		time_ssse3 = (t2 - t1) / run_size;
	}
#endif

	// print result
	QString size = QString("%1x%2").arg(w).arg(h);
	Logger::LogInfo("[BenchmarkConvert] " + Logger::tr("%1 %2 to %3 %4  |  SWScale %5 us  |  Fallback %6 us (%7%)  |  SSSE3 %8 us (%9%)")
					.arg(in_format_name, 6).arg(size, 9).arg(out_format_name, 6).arg(size, 9)
					.arg(time_swscale, 6)
					.arg(time_fallback, 6).arg(100 * time_fallback / time_swscale, 3)
					.arg(time_ssse3, 6).arg(100 * time_ssse3 / time_fallback, 3));

}
예제 #12
0
파일: main.cpp 프로젝트: avoliva/cisp430
int main()
{
    // Testing List
    List<std::string> list;
    std::cout << "Is the list empty? = " << list.empty() << std::endl;
    std::string line;
    std::ifstream myfile ("datain.dat");
    if (myfile.is_open())
    {
        while ( myfile.good() )
        {
            getline (myfile,line);
            list.push_back(line);
        }
        myfile.close();
    }
    list.sort();
    std::ofstream outfile("output.txt");
    outfile << "List in ascending output (strings): " << std::endl << std::endl;
    if (outfile.is_open())
    {
        for (List<std::string>::iterator it = list.begin(); it != list.end(); ++it)
            outfile << *it << std::endl;
    }

    list.sort("desc");
    std::ofstream desc_outfile("output2.txt");
    desc_outfile << "List in descending output (strings): " << std::endl << std::endl;
    if (desc_outfile.is_open())
    {
        for (List<std::string>::iterator it = list.begin(); it != list.end(); ++it)
            desc_outfile << *it << std::endl;
    }

    
    std::cout << "pop back is " << list.pop_back() << std::endl;
    list.remove(list.begin() + 2);
    List<std::string>::iterator iters = list.begin();
    std::cout << " get next is " << iters.get_next() << std::endl;
    list.push_back(*iters);

    std::cout << "size is " << list.size() << std::endl;
    List<std::string> list2 = list;
    for (List<std::string>::iterator iter = list2.begin();
         iter != list2.end(); ++iter)
    {
        std::cout << (*iter) << std::endl;
    }
    std::cout << "search result " << list.search("5") << std::endl;
    std::cout << "get_head() " << list.get_head() << std::endl;
    List<std::string>::iterator it = list.begin() + 1;
    std::cout << "has_next() " << it.has_next() << std::endl;

    // Stack testing
    Stack<std::string> stack;
    std::cout << "stack.empty() (should be 1) " << stack.empty() << std::endl;
    std::ifstream my_stack_file ("datain.dat");
    if (my_stack_file.is_open())
    {
        while ( my_stack_file.good() )
        {
            getline (my_stack_file,line);
            stack.push(line);
        }
        my_stack_file.close();
    }
    stack.pop();
    std::cout << "stack top is " << stack.show_top() << std::endl;
    std::cout << "stack.empty() " << stack.empty() << std::endl;
    std::cout << "stack.is_full() " << stack.is_full() << std::endl;

    std::ofstream stack_out("stack_output.txt");
    stack_out << "Popping stack output ( minus 1): " << std::endl << std::endl;
    while (!stack.empty())
        stack_out << stack.pop() << std::endl;

    // Testing Queue
    Queue<std::string> queue;
    std::cout << "queue.empty() (should be 1) " << queue.empty() << std::endl;
    std::ifstream my_queue_file ("datain.dat");
    if (my_queue_file.is_open())
    {
        while ( my_queue_file.good() )
        {
            getline (my_queue_file,line);
            queue.enqueue(line);
        }
        my_queue_file.close();
    }
    std::cout << "searching queue for '5': " << queue.search("5") << std::endl;
    std::cout << "queue.empty() (should be 0) " << queue.empty() << std::endl;
    std::ofstream queue_out("queue_output.txt");
    queue.sort();
    queue_out << "Dequeue queue output sorted ascending: " << std::endl << std::endl;
    while (!queue.empty())
        queue_out << queue.dequeue() << std::endl;
    if (my_queue_file.is_open())
    {
        while ( my_queue_file.good() )
        {
            getline (my_queue_file,line);
            queue.enqueue(line);
        }
        my_queue_file.close();
    }
    std::ofstream queue_out_desc("queue_output_Desc.txt");
    queue.sort("desc");;
    queue_out_desc << "Dequeue queue output sorted descending: " << std::endl << std::endl;
    while (!queue.empty())
        queue_out_desc << queue.dequeue() << std::endl;

    std::cout << "queue.is_full(): " << stack.is_full() << std::endl;

    std::cin.ignore();
}