示例#1
0
bool nodeset_resize (nodeset_t *n, uint32_t size)
{
    assert (n->magic == NS_MAGIC);

    uint32_t r;
    Veb T;

    if (size < veb_minsize)         /* don't allow size below minimum */
        size = veb_minsize;
    if (size < NS_SIZE (n)) {       /* If shrinking, bump size up to */
        r = NS_FIRST (n);           /*   fit highest rank in set. */
        while (r < NS_SIZE (n)) {
            if (r >= size)
                size = r + 1;
            r = NS_NEXT (n, r);
        }
    }
    if (size != NS_SIZE (n)) {
        T = vebnew (size, 0);
        if (!T.D)
            oom ();
        r = NS_FIRST (n);
        while (r < NS_SIZE (n)) {
            vebput (T, r);
            r = NS_NEXT (n, r);
        }
        free (n->T.D);
        n->T = T;
    }
    return true;
}
示例#2
0
const char *nodeset_string (nodeset_t *n)
{
    assert (n->magic == NS_MAGIC);

    const char *sep = "";
    int used = 0;
    uint32_t r, lo = 0, hi = 0;
    bool inrange = false;
    char tmp[128];

    if (!n->s_valid) {
        if (!n->s) {
            n->s_size = string_initsize;
            if (!(n->s = malloc (n->s_size)))
                oom ();
        }
        n->s[0] = '\0';
        if (n->conf_brackets && !nodeset_single (n))
            catstr (&n->s, &n->s_size, &used, "[");
        r = NS_FIRST (n);
        while (r < NS_SIZE (n) || inrange) {
            if (n->conf_ranges) {
                if (!inrange) {
                    lo = hi = r;
                    inrange = true;
                } else if (r < NS_SIZE (n) && r == hi + 1) {
                    hi++;
                } else if (lo == hi) {
                    snprintf (tmp, sizeof (tmp), "%s%0*u", sep,
                              n->conf_padding, lo);
                    catstr (&n->s, &n->s_size, &used, tmp);
                    sep = n->conf_separator;
                    inrange = false;
                    continue;
                } else {
                    snprintf (tmp, sizeof (tmp), "%s%0*u-%0*u", sep,
                             n->conf_padding, lo,
                             n->conf_padding, hi);
                    catstr (&n->s, &n->s_size, &used, tmp);
                    sep = n->conf_separator;
                    inrange = false;
                    continue;
                }
            } else {
                snprintf (tmp, sizeof (tmp), "%s%0*u", sep,
                          n->conf_padding, r);
                catstr (&n->s, &n->s_size, &used, tmp);
                sep = n->conf_separator;
                inrange = false;
            }
            if (r < NS_SIZE (n))
                r = NS_NEXT (n, r);
        }
        if (n->s[0] == '[')
            catstr (&n->s, &n->s_size, &used, "]");
        n->s_valid = true;
    }
    return n->s;
}
示例#3
0
uint32_t nodeset_next (nodeset_iterator_t *itr)
{
    if (itr->started)
        itr->r = NS_NEXT (itr->n, itr->r);
    else {
        itr->r = NS_FIRST (itr->n);
        itr->started = true;
    }
    return (itr->r == NS_SIZE (itr->n) ? NODESET_EOF : itr->r);
}
示例#4
0
static bool nodeset_single (nodeset_t *n)
{
    uint32_t len = 0;
    uint32_t r;

    r = NS_FIRST (n);
    while (r < NS_SIZE (n) && len < 2) {
        len++;
        r = NS_NEXT (n, r);
    }
    return (len < 2);
}
示例#5
0
uint32_t nodeset_count (nodeset_t *n)
{
    assert (n->magic == NS_MAGIC);

    uint32_t count = 0;
    uint32_t r;

    r = NS_FIRST (n);
    while (r < NS_SIZE (n)) {
        count++;
        r = NS_NEXT (n, r);
    }
    return count;
}
示例#6
0
文件: nodeset.c 项目: trws/flux-core
uint32_t nodeset_next_rank (nodeset_t *n, uint32_t r)
{
    uint32_t next = NS_NEXT (n, r);
    return (next == NS_SIZE (n) ? NODESET_EOF : next);
}