Example #1
0
treeNode NewTreeNode(treeNode left, treeNode right, long item)
{
    treeNode    newT = NULL;

    GGC_PUSH_3(left, right, newT);

    newT = GGC_NEW(treeNode);

    GGC_WP(newT, left, left);
    GGC_WP(newT, right, right);
    GGC_WD(newT, item, item);

    return newT;
} /* NewTreeNode() */
Example #2
0
treeNode TopDownTree(long item, unsigned depth)
{
    if (depth > 0) {
        treeNode ret, l, r;
        ret = l = r = NULL;
        GGC_PUSH_3(ret, l, r);

        ret = NewTreeNode(NULL, NULL, item);
        l = TopDownTree(2 * item - 1, depth - 1);
        r = TopDownTree(2 * item, depth - 1);
        GGC_WP(ret, left, l);
        GGC_WP(ret, right, r);

        return ret;
    } else
        return NewTreeNode(NULL, NULL, item);
} /* BottomUpTree() */
int main(void)
{
    int i, j, last, cur;
    TWO head = NULL, end = NULL, node = NULL;
    
    GGC_PUSH_3(node, end, head);

    head = GGC_NEW(TWO);
    GGC_WD(head, val, 0);
    end = head;

    /* create list */
    for (i = 1; i < 4096; i++) {
        
        /* create garbage */
        for (j = 0; j < 4096; j++) {
            node = GGC_NEW(TWO);
        }
        
        node = GGC_NEW(TWO);
        GGC_WD(node, val, i);
        GGC_WP(end, next, node);
        end = node;
    }

    /* check list */
    last = GGC_RD(head, val);
    node = GGC_RP(head, next);
    while (node) {
        cur = GGC_RD(node, val);
        if (cur == (last + 1)) {
            last = cur;
            node = GGC_RP(node, next);
        }
        else {
            printf("WRONG\n");
            exit(1);
        }
    }
    
    return 0;
}
Example #4
0
LLL buildLLL(int sz)
{
    int i;
    LLL ll0 = NULL, lll = NULL, llc = NULL;

    GGC_PUSH_3(ll0, lll, llc);
 	printf("calling malloc\n");
    ll0 = GGC_NEW(LLL);
    printf("here obj is %u\n",ll0);
    GGC_WD(ll0, val, 0);
    lll = ll0;

    for (i = 1; i < sz; i++) {
        llc = GGC_NEW(LLL);
        //printf("here obj is %zu\n",llc);
        GGC_WD(llc, val, i);
        GGC_WP(lll, next, llc);
        lll = llc;
        GGC_YIELD();
    }

    return ll0;
}
Example #5
0
int main(int argc, char* argv[])
{
    unsigned   N, depth, minDepth, maxDepth, stretchDepth;
    treeNode   stretchTree, longLivedTree, tempTree;

    N = atol(argv[1]);

    minDepth = 4;

    if ((minDepth + 2) > N)
        maxDepth = minDepth + 2;
    else
        maxDepth = N;

    stretchDepth = maxDepth + 1;

    tempTree = stretchTree = longLivedTree = NULL;
    GGC_PUSH_3(tempTree, stretchTree, longLivedTree);

    stretchTree = TopDownTree(0, stretchDepth);
    printf
    (
        "stretch tree of depth %u\t check: %li\n",
        stretchDepth,
        ItemCheck(stretchTree)
    );

    longLivedTree = TopDownTree(0, maxDepth);

    for (depth = minDepth; depth <= maxDepth; depth += 2)
    {
        long    i, iterations, check;

        iterations = pow(2, maxDepth - depth + minDepth);

        check = 0;

        for (i = 1; i <= iterations; i++)
        {
            tempTree = TopDownTree(i, depth);
            check += ItemCheck(tempTree);

            tempTree = TopDownTree(-i, depth);
            check += ItemCheck(tempTree);
        } /* for(i = 1...) */

        printf
        (
            "%li\t trees of depth %u\t check: %li\n",
            iterations * 2,
            depth,
            check
        );
    } /* for(depth = minDepth...) */

    printf
    (
        "long lived tree of depth %u\t check: %li\n",
        maxDepth,
        ItemCheck(longLivedTree)
    );

    return 0;
} /* main() */