Alien-Judy

 view release on metacpan or  search on metacpan

src/judy-1.0.5/test/JudyString.c  view on Meta::CPAN

        if (Chr == '\n' && Len)
        {
            Index[Len] = '\0';

//printf("%3lu,%lu: %s\n", Lines, Len, Index);
//printf("%s\n", Index);

            JHSI(PValue, PJHArray, Index, Len); // store string into array
            if  (*PValue != 0) Dups++;
            *PValue += 1;
            Lines++;
            Len = 0;
        }
        else if (Len < MAXLENSTR)
        {
            Index[Len] = Chr;
            Len++;
        }
    }

    fclose(fid);
    fid = NULL;

    printf("'%s' has %lu lines, %lu duplicate lines\n", argv[1], Lines, Dups);

    printf("Re-open '%s' and verify each string is in JudyHS array\n", argv[1]);

    if ((fid = fopen(argv[1], "r")) == NULL)
    {
        printf("Failed to re-open '%s'\n", argv[1]);
        exit(2);
    }

    Lines = 0;
    Len = 0;
    while ((Chr = fgetc(fid)) != EOF)
    {
        if (Len < MAXLENSTR) Index[Len] = Chr;

        if (Chr == '\n' && Len)
        {
            Index[Len] = '\0';

            JHSG(PValue, PJHArray, Index, Len); // store string into array
            if (PValue == NULL)
            {
                printf("'%s'\n", Index);
                printf("JHSG() failed at Line %lu\n", Lines);
                exit(1);
            }
            Len = 0;
            Lines++;
        }
        else Len++;
    }

    printf("Begin JHSFA (JudyHSFreeArray)\n");

    JHSFA(Bytes, PJHArray);                     // free array

    fprintf(stderr, "JHSFA() free'ed %lu bytes of memory\n", Bytes);
    return (0);
}



( run in 0.959 second using v1.01-cache-2.11-cpan-817d5f8af8b )