예제 #1
0
/* Return value: count of id's in set, or -1 on failure.
 * N.B. if count is more than INT_MAX, return value is INT_MAX.
 */
static int encode_ranged (const struct idset *idset,
                          char **s, size_t *sz, size_t *len)
{
    int count = 0;
    unsigned int id;
    unsigned int lo = 0;
    unsigned int hi = 0;
    bool first = true;

    lo = hi = id = vebsucc (idset->T, 0);
    while (id < idset->T.M) {
        unsigned int next = vebsucc (idset->T, id + 1);;
        bool last = (next == idset->T.M);

        if (first)                  // first iteration
            first = false;
        else if (id == hi + 1)      // id is in range
            hi++;
        else {                      // id is NOT in range
            if (catrange (s, sz, len, lo, hi, ",") < 0)
                return -1;
            lo = hi = id;
        }
        if (last) {                 // last iteration
            if (catrange (s, sz, len, lo, hi, last ? "" : ",") < 0)
                return -1;
        }
        if (count < INT_MAX)
            count++;
        id = next;
    }
    return count;
}
예제 #2
0
int
main(void)
{
	srand(438749);
	uint M = rand()%(1<<16);
	Veb T = fill(M);
	uint i = i = vebsucc(T,0);
	while (i < M) {
		vebdel(T,i);
		uint j = vebsucc(T,i);
		test(i != j);
		i = j;
	}
	free(T.D);
	return 0;
}
예제 #3
0
/* Return value: count of id's in set, or -1 on failure.
 * N.B. if count is more than INT_MAX, return value is INT_MAX.
 */
static int encode_simple (const struct idset *idset,
                          char **s, size_t *sz, size_t *len)
{
    int count = 0;
    unsigned int id;

    id = vebsucc (idset->T, 0);
    while (id != idset->T.M) {
        int next = vebsucc (idset->T, id + 1);
        char *sep = next == idset->T.M ? "" : ",";
        if (catprintf (s, sz, len, "%d%s", id, sep) < 0)
            return -1;
        if (count < INT_MAX)
            count++;
        id = next;
    }
    return count;
}
예제 #4
0
Veb
fill(uint M)
{
	Veb T = vebnew(M,1);
	for (int i = 0; i < 0xff; ++i) {
		uint x = rand()%M;
		vebdel(T,x);
		test(vebsucc(T,x) != x);
	}
	return T;
}