示例#1
0
文件: sshare.c 项目: JohnLih/openlava
/* sort_tree_by_shares()
 */
static void
sort_tree_by_shares(struct tree_ *t)
{
    link_t *stack;
    struct tree_node_ *root;
    struct tree_node_ *n;

    stack = make_link();
    root = t->root;
    n = root->child;

znovu:
    while (n) {

        if (n->child)
            enqueue_link(stack, n);

        n = n->right;
    }

    sort_siblings(root, node_cmp);

    n = pop_link(stack);
    if (n) {
        root = n;
        n = root->child;
        goto znovu;
    }

    fin_link(stack);
    make_leafs(t);
}
示例#2
0
/* sort_tree_by_deviate()
 *
 */
static void
sort_tree_by_deviate(struct tree_ *t)
{
    struct tree_node_ *n;
    struct tree_node_ *n2;
    struct tree_node_ *root;
    link_t *stack;
    struct share_acct *s;
    uint64_t sum;
    uint64_t avail;

    stack = make_link();
    root = t->root;
    n = root->child;

znovu:
    n2 = n;
    sum = 0;
    while (n) {

        if (n->child)
            enqueue_link(stack, n);

        s = n->data;
        s->dsrv2 = 0;
        /* sum up the historical.
         */
        sum = sum + s->numRAN;
        n = n->right;
    }

    avail = sum;
    n = n2;
    while (n) {

        avail = avail - compute_deviate(n, sum, avail);
        assert(avail >= 0);
        n = n->right;
    }

    sort_siblings(root, node_cmp2);

    n = pop_link(stack);
    if (n) {
        root = n;
        n = n->child;
        goto znovu;
    }

    fin_link(stack);
    make_leafs(t);
}