Esempio n. 1
0
l_int32
l_asetSize(L_ASET  *s)
{
    return l_rbtreeGetCount(s);
}
Esempio n. 2
0
l_int32 main(int    argc,
             char **argv)
{
l_int32    i;
RB_TYPE    x, y;
RB_TYPE   *pval;
L_RBTREE  *t;

    setLeptDebugOK(1);

    t = l_rbtreeCreate(L_INT_TYPE);
    l_rbtreePrint(stderr, t);

        /* Build the tree */
    for (i = 0; i < 5000; i++) {
        x.itype = rand() % 10000;
        y.itype = rand() % 10000;
#if TRACE
        l_rbtreePrint(stderr, t);
        printf("Inserting %d -> %d\n\n", x.itype, y.itype);
#endif  /* TRACE */
        l_rbtreeInsert(t, x, y);
        pval = l_rbtreeLookup(t, x);
        if (pval->itype != y.itype)
            L_ERROR("val %lld doesn't agree for key %lld\n", "main",
                    pval->itype, x.itype);
    }

        /* Count the nodes in the tree */
    fprintf(stderr, "count = %d\n", l_rbtreeGetCount(t));

#if PRINT_FULL_TREE
    l_rbtreePrint(stderr, t);  /* very big */
#endif  /* PRINT_FULL_TREE */

        /* Destroy the tree and count the remaining nodes */
    l_rbtreeDestroy(&t);
    l_rbtreePrint(stderr, t);  /* should give an error message */
    fprintf(stderr, "count = %d\n", l_rbtreeGetCount(t));

        /* Build another tree */
    t = l_rbtreeCreate(L_INT_TYPE);
    for (i = 0; i < 6000; i++) {
        x.itype = rand() % 10000;
        y.itype = rand() % 10000;
        l_rbtreeInsert(t, x, y);
    }

        /* Count the nodes in the tree */
    fprintf(stderr, "count = %d\n", l_rbtreeGetCount(t));

        /* Delete lots of nodes randomly from the tree and recount.
         * Deleting 80,000 random points gets them all; deleting
         * 60,000 removes all but 7 points. */
    for (i = 0; i < 60000; i++) {
        x.itype = rand() % 10000;
#if TRACE
        l_rbtreePrint(stderr, t);
        printf("Deleting key %d\n\n", x.itype);
#endif  /* TRACE */
        l_rbtreeDelete(t, x);
    }
    fprintf(stderr, "count = %d\n", l_rbtreeGetCount(t));
    l_rbtreePrint(stderr, t);
    lept_free(t);

    return 0;
}
Esempio n. 3
0
l_int32
l_amapSize(L_AMAP  *m)
{
    return l_rbtreeGetCount(m);
}