Esempio n. 1
0
File: mb.c Progetto: yqingp/testness
/*
 * EFFECTS:
 *  - iterate the whole pma with backward direction
 * RETURNS:
 *  - 0 means invalid
 *  - 1 means valid
 */
int mb_iter_prev(struct mb_iter *iter)
{
    struct pma *pma = iter->pma;
    int chain_idx = iter->chain_idx;
    int array_idx = iter->array_idx;

    if (mb_iter_valid(iter))
    {
        iter->base = pma->chain[chain_idx]->elems[array_idx];
        if (array_idx == 0)
        {
            iter->chain_idx--;
            iter->array_idx = pma->chain[chain_idx]->used - 1;
        }
        else
        {
            iter->array_idx--;
        }

        return 1;
    }
    else
    {
        return 0;
    }
}
Esempio n. 2
0
File: mb.c Progetto: BohuTANG/nessDB
/*
 * EFFECTS:
 *	- iterate the whole pma with forward direction
 * RETURNS:
 *	- 0 means invalid
 *	- 1 means valid
 */
int mb_iter_next(struct mb_iter *iter)
{
	struct pma *pma = iter->pma;
	int slot_idx = iter->slot_idx;
	int array_idx = iter->array_idx;

	if (mb_iter_valid(iter)) {
		iter->base = pma->slots[slot_idx]->elems[array_idx];
		if (array_idx == (pma->slots[slot_idx]->used - 1)) {
			iter->slot_idx++;
			iter->array_idx = 0;
		} else {
			iter->array_idx++;
		}

		return 1;
	} else {
		return 0;
	}
}
Esempio n. 3
0
File: mb.c Progetto: yqingp/testness
/*
 * EFFECTS:
 *  - iterate the whole pma with forward direction
 * RETURNS:
 *  - 0 means invalid
 *  - 1 means valid
 */
int mb_iter_next(struct mb_iter *iter)
{
    struct pma *pma = iter->pma;
    int chain_idx = iter->chain_idx;
    int array_idx = iter->array_idx;
    /* printf("%d, %d next==\n", chain_idx, array_idx); */

    if (mb_iter_valid(iter))
    {
        iter->base = pma->chain[chain_idx]->elems[array_idx];
        if (array_idx == (pma->chain[chain_idx]->used - 1))
        {
            iter->chain_idx++;
            iter->array_idx = 0;
        }
        else
        {
            iter->array_idx++;
        }

        return 1;
    }
    else
    {
        /* printf("chain = %d, array = %d \n ", chain_idx, array_idx); */
        /* for (int j = 0; j < iter->pma->used; j++) */
        /* { */
        /*     /1* total += lmb->pma->chain[j]->used; *1/ */
        /*     printf("current = %d, used == %d\n", j, iter->pma->chain[j]->used); */
        /*     /1* for (int k = 0; i < count; i++) { *1/ */

        /*     /1* } *1/ */
        /* } */
        return 0;
    }
}
Esempio n. 4
0
int _search_leaf(struct cursor *cur, struct search *so, struct node *leaf)
{
	int found;
	int ret = CURSOR_EOF;
	struct lmb *lmb;
	struct mb_iter iter;
	struct leafentry *le;
	struct pma_coord coord;

	/* 1) apply all msgs to leaf msgbuf */
	//leaf_apply_ancestors(leaf, cur->ances);

	/* 2) init leaf iterator, TODO: which msgbuf to read */
	lmb = leaf->parts[0].msgbuf;
	mb_iter_init(&iter, lmb->pma);

	/* 3) do search */
	switch (so->gap) {
	case GAP_ZERO:
		found = lmb_find_zero(lmb, &cur->key, &le, &coord);
		if (found) {
			mb_iter_reset(&iter, &coord);
			if (mb_iter_valid(&iter)) {
				_cursor_get_values_from_leafentry(cur, iter.base);
			}
		}
		ret = CURSOR_EOF;
		break;
	case GAP_POSI:
		found = lmb_find_plus(lmb, &cur->key, &le, &coord);
		if (found) {
			mb_iter_reset(&iter, &coord);
POSI_RETRY:
			if (mb_iter_valid(&iter)) {
				int got = _cursor_get_values_from_leafentry(cur, iter.base);
				if (!got) {
					mb_iter_next(&iter);
					goto POSI_RETRY;
				} else {
					ret = CURSOR_EOF;
				}
			} else {
				ret = CURSOR_CONTINUE;
			}
		}
		break;
	case GAP_NEGA:
		found = lmb_find_minus(lmb, &cur->key, &le, &coord);
		if (found) {
			mb_iter_reset(&iter, &coord);
NEGA_RETRY:
			if (mb_iter_valid(&iter)) {
				int got = _cursor_get_values_from_leafentry(cur, iter.base);
				if (!got) {
					mb_iter_prev(&iter);
					goto NEGA_RETRY;
				} else {
					ret = CURSOR_EOF;
				}
			} else {
				ret = CURSOR_CONTINUE;
			}
		}
		break;
	}

	return ret;
}