Esempio n. 1
0
static L_AMAP *
BuildMapHistogram(PIX     *pix,
                  l_int32  factor,
                  l_int32  print)
{
l_int32    i, j, w, h, wpl, val;
l_uint32   val32;
l_uint32  *data, *line;
L_AMAP    *m;
PIXCMAP   *cmap;
RB_TYPE    key, value;
RB_TYPE   *pval;

    fprintf(stderr, "\n --------------- Begin building map --------------\n");
    m = l_amapCreate(L_UINT_TYPE);
    data = pixGetData(pix);
    wpl = pixGetWpl(pix);
    cmap = pixGetColormap(pix);
    pixGetDimensions(pix, &w, &h, NULL);
    for (i = 0; i < h; i += factor) {
        line = data + i * wpl;
        for (j = 0; j < w; j += factor) {
            val = GET_DATA_BYTE(line, j);
            pixcmapGetColor32(cmap, val, &val32);
            key.utype = val32;
            pval = l_amapFind(m, key);
            if (!pval)
                value.itype = 1;
            else
                value.itype = 1 + pval->itype;
            if (print) {
                fprintf(stderr, "key = %llx, val = %lld\n",
                        key.utype, value.itype);
            }
            l_amapInsert(m, key, value);
        }
    }
    fprintf(stderr, "Size: %d\n", l_amapSize(m));
    if (print)
        l_rbtreePrint(stderr, m);
    fprintf(stderr, " ----------- End Building map -----------------\n");

    return m;
}
Esempio n. 2
0
static L_ASET *
BuildSet(PIX     *pix,
         l_int32  factor,
         l_int32  print)
{
l_int32    i, j, w, h, wpl, val;
l_uint32   val32;
l_uint32  *data, *line;
L_ASET    *s;
PIXCMAP   *cmap;
RB_TYPE    key;
RB_TYPE   *pval;

    fprintf(stderr, "\n --------------- Begin building set --------------\n");
    s = l_asetCreate(L_UINT_TYPE);
    data = pixGetData(pix);
    wpl = pixGetWpl(pix);
    cmap = pixGetColormap(pix);
    pixGetDimensions(pix, &w, &h, NULL);
    for (i = 0; i < h; i += factor) {
        line = data + i * wpl;
        for (j = 0; j < w; j += factor) {
            if (cmap) {
                val = GET_DATA_BYTE(line, j);
                pixcmapGetColor32(cmap, val, &val32);
                key.utype = val32;
            } else {
                key.utype = line[j];
            }
            pval = l_asetFind(s, key);
            if (pval && print)
                fprintf(stderr, "key = %llx\n", key.utype);
            l_asetInsert(s, key);
        }
    }
    fprintf(stderr, "Size: %d\n", l_asetSize(s));
    if (print)
        l_rbtreePrint(stderr, s);
    fprintf(stderr, " ----------- End Building set -----------------\n");

    return s;
}
Esempio n. 3
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;
}