Ejemplo n.º 1
0
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);
		}
	}
}
Ejemplo n.º 2
0
void test_queue_in()
{
    p1 = (Person*)malloc(sizeof(Person));
    char *name1 = (char*)malloc(16);
    strcpy(name1, "tom");
    p1->name = name1;
    p1->age = 22;

    p2 = (Person*)malloc(sizeof(Person));
    char *name2 = (char*)malloc(16);
    strcpy(name2, "jack");
    p2->name = name2;
    p2->age = 23;

    p3 = (Person*)malloc(sizeof(Person));
    char *name3 = (char*)malloc(16);
    strcpy(name3, "jim");
    p3->name = name3;
    p3->age = 24;


    p4 = (Person*)malloc(sizeof(Person));
    char *name4 = (char*)malloc(16);
    strcpy(name4, "fitz");
    p4->name = name4;
    p4->age = 25;

    CU_ASSERT_EQUAL_FATAL(queue_in(&queue, p1), 0);
    CU_ASSERT_EQUAL_FATAL(queue_in(&queue, p2), 0);
    CU_ASSERT_EQUAL_FATAL(queue_in(&queue, p3), 0);
    CU_ASSERT_EQUAL_FATAL(queue_in(&queue, p4), 0);
    CU_ASSERT_EQUAL_FATAL(queue.queue_size, 4);
    CU_ASSERT_EQUAL_FATAL(queue.node_count, 4);
}
Ejemplo n.º 3
0
/* 清除风杖的效果函数 */
static int clean_eul_buff(LIFE_S *self, LIFE_S *owner)
{
    unsigned short damage = 0;

    DOTA_RETURN_IF_NULL(self, ERR_NULL_POINTER);
    DOTA_RETURN_IF_NULL(owner, ERR_NULL_POINTER);

    CLEAN_EUL_EFFECT(self);
    TRACE_BATTLE("%s is clean EUL effect.\n", self->name);

    /* 若不是对自己释放,而是对敌人释放,则落地后会有50点伤害 */
    if (self == owner)
        return DOTA_OK;

    damage = HERO_MAGIC_DAMAGE(EUL_DAMAGE, self->ms.spell_rst);
    TRACE_BATTLE("%s's EUL make %hu damage to %s.\n",
                 owner->name, damage, self->name);

    if (self->cur_hmaa.health <= damage) {
        self->life_state = LIFE_ZOMBIE;
        self->murderer = owner;
        queue_in(owner->kill_queue, self);
        return DOTA_OK;
    }
    self->cur_hmaa.health -= damage;
    return DOTA_OK;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
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));

}
Ejemplo n.º 6
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");
    }

}
Ejemplo n.º 7
0
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));

}
Ejemplo n.º 8
0
/***********************************************************************************************************************
* Function name: Axe_C
* Skill name: 淘汰之刃
* Describe: 清除斧王视线范围内的弱者,伤害并不高,但能瞬间斩杀生命值不足的敌人。
*           瞬间斩杀判断无视魔法免疫。造成300点伤害,瞬间斩杀生命值少于400的敌人。
* Mana Cost: 180点
* Cold Down: 55秒
* Author: xiaomaoshi
* Date: 2015/05/20
* History:
***********************************************************************************************************************/
int axe_c(LIFE_S *self)
{
    unsigned short damage = 0;
    LIFE_S *target = NULL;

    DOTA_RETURN_IF_NULL(self, ERR_NULL_POINTER);

    target = self->target;
    DOTA_RETURN_IF_NULL(target, ERR_NULL_POINTER);

    /* 血量低于400的话,瞬间斩杀,不管是不是魔法免疫 */
    if (target->cur_hmaa.health <= AXE_C_DAMAGE_UPPER_LIMIT) {
        TRACE_BATTLE("%s use AXE_C make %u damage to %s.\n",
                     self->name,
                     AXE_C_DAMAGE_UPPER_LIMIT,
                     target->name);
        target->life_state = LIFE_ZOMBIE;
        target->murderer = self;
        queue_in(self->kill_queue, target);
        return SUC_IGNORE_CD;
    }

    /* 
     * 若对方血量很多不能斩杀,并且对方处于魔法免疫的状态,
     * 则不会造成伤害,但技能也会CD,相当于已经放出技能
     */
    if (IS_MAIGC_IMMUNITY(target)) {
        TRACE_BATTLE("%s use AXE_C make %u damage to %s.\n",
                     self->name, 0, target->name);
        return DOTA_SUCCESS;
    }

    /* 血量高于400,且不处于魔免状态时,会造成300的伤害 */
    damage = HERO_PHYSICAL_DAMAGE(AXE_C_DAMAGE_LOWER_LIMIT,
                                  target->cur_hmaa.armor);
    TRACE_BATTLE("%s use AXE_C make %u damage to %s.\n",
                 self->name, damage, target->name);
    target->cur_hmaa.health -= damage;
    return DOTA_SUCCESS;
}
Ejemplo n.º 9
0
/***********************************************************************************************************************
* Function name: axe_x
* Skill name: 反击螺旋
* Describe: 在受到攻击时,斧王有20%的几率抓住敌人,粗暴地甩开,对附近300范围内的
*           敌方单位造成205点伤害,伤害无视魔法免疫。
* Mana Cost: 0点
* Cold Down: 0.3秒
* Author: xiaomaoshi
* Date: 2015/05/20
* History:
***********************************************************************************************************************/
int axe_x(LIFE_S *self)
{
    int rand_num = 0;
    unsigned short damage = 0;
    unsigned short armor = 0;
    LIFE_S **enemy = NULL;
    LIFE_S **all_enemy = NULL;
    unsigned int dis = 0;

    DOTA_RETURN_IF_NULL(self, ERR_NULL_POINTER);

    rand_num = (rand() % 100) + 1;
    if (rand_num > AXE_X_POSSIBILITY)
        return ERR_TRIGGER_FAILED;

    dis = self->skills[AXE_X].attr.dis;
    all_enemy = find_enemy_area(self, dis);
    if (!all_enemy)
        return DOTA_SUCCESS;

    enemy = all_enemy;
    while (*enemy) {
        armor = (*enemy)->cur_hmaa.armor;
        damage = HERO_PHYSICAL_DAMAGE(AXE_X_DAMAGE, armor);
        TRACE_BATTLE("%s use AXE_X make %u damage to %s.\n",
                     self->name, damage, (*enemy)->name);

        if ((*enemy)->cur_hmaa.health <= damage) {
            (*enemy)->life_state = LIFE_ZOMBIE;
            (*enemy)->murderer = self;
            queue_in(self->kill_queue, *enemy);
            enemy++;
            continue;
        }
        (*enemy)->cur_hmaa.health -= damage;
        enemy++;
    }
    DOTA_FREE(all_enemy);
    return DOTA_SUCCESS;
}
Ejemplo n.º 10
0
/* 受到30点/秒的伤害,持续16秒 */
int axe_r_buff(LIFE_S *self, LIFE_S *owner)
{
    unsigned short damage = 0;
    unsigned short spell  = 0;

    DOTA_RETURN_IF_NULL(self, ERR_NULL_POINTER);
    DOTA_RETURN_IF_NULL(owner, ERR_NULL_POINTER);

    spell = self->ms.spell_rst;
    damage = HERO_MAGIC_DAMAGE(AXE_R_DAMAGE_PER_SECOND, spell);
    TRACE_BATTLE("%s's buff AXE_R make %u damage to %s.\n",
                 owner->name, damage, self->name);

    if (self->cur_hmaa.health <= damage) {
        self->life_state = LIFE_ZOMBIE;
        self->murderer = owner;
        queue_in(owner->kill_queue, self);
        return DOTA_SUCCESS;
    }
    self->cur_hmaa.health -= damage;
    return DOTA_SUCCESS;
}
Ejemplo n.º 11
0
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));

}
Ejemplo n.º 12
0
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));

}