Exemple #1
0
/*
 * heap_down:  Given an array of cam_pinfo* elements with the
 * Heap(index + 1, num_entries) property with index containing
 * an unsorted entry, output Heap(index, num_entries).
 */
static void
heap_down(cam_pinfo **queue_array, int index, int num_entries)
{
	int child;
	int parent;
	
	parent = index;
	child = parent << 1;
	for (; child <= num_entries; child = parent << 1) {

		if (child < num_entries) {
			/* child+1 is the right child of parent */
			if (queue_cmp(queue_array, child + 1, child) < 0)
				child++;
		}
		/* child is now the least child of parent */
		if (queue_cmp(queue_array, parent, child) <= 0)
			break;
		swap(queue_array, child, parent);
		parent = child;
	}
}
Exemple #2
0
/*
 * heap_up:  Given an array of cam_pinfo* elements with the
 * Heap(1, new_index-1) property and a new element in location
 * new_index, output Heap(1, new_index).
 */
static void
heap_up(cam_pinfo **queue_array, int new_index)
{
	int child;
	int parent;

	child = new_index;

	while (child != 1) {

		parent = child >> 1;
		if (queue_cmp(queue_array, parent, child) <= 0)
			break;
		swap(queue_array, parent, child);
		child = parent;
	}
}
Exemple #3
0
int genbinop(int op, int p1, int p2)
{

    binopchk(op, p1, p2);

    switch (op)
    {

    case PLUS:
        return genadd(p1, p2, 1);

    case MINUS:
        return gensub(p1, p2, 1);

    case STAR:
        genmul();

        break;

    case SLASH:
        gendiv(1);

        break;

    case MOD:
        genmod(1);

        break;

    case LSHIFT:
        genshl(1);

        break;

    case RSHIFT:
        genshr(1);

        break;

    case AMPER:
        genand();

        break;

    case CARET:
        genxor();

        break;

    case PIPE:
        genior();

        break;

    case EQUAL:
        queue_cmp(equal);

        break;

    case NOTEQ:
        queue_cmp(not_equal);

        break;

    case LESS:
        queue_cmp(less);

        break;

    case GREATER:
        queue_cmp(greater);

        break;

    case LTEQ:
        queue_cmp(less_equal);

        break;

    case GTEQ:
        queue_cmp(greater_equal);

        break;

    }

    return PINT;

}