Alien-Judy

 view release on metacpan or  search on metacpan

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


#define GETSTRING(STRING)                                               \
{                                                                       \
        PWord_t _PValue;                                                \
        JSLG(_PValue, JudyArray, (uint8_t *) STRING);                   \
        if (_PValue == NULL)                 /* not found -- bug */     \
        {                                                               \
               printf("GETSTRING failed(Judy) -- BUG!\n\n");            \
               exit(1);                                                 \
        }                                                               \
}

#endif // JUDYMETHOD

// Note: this optimization by J. Zobel should not be necessary
// with the -static compile option (linux). (dlb)

#ifdef SLOW_STRCMP
int
scmp(char *s1, char *s2)
{
    while (*s1 != '\0' && *s1 == *s2)
    {
        s1++;
        s2++;
    }
    return (*s1 - *s2);
}
#else // ! SLOW_STRCMP

#define scmp strcmp

#endif // ! SLOW_STRCMP

//=======================================================================
//      H A S H   M E T H O D
//=======================================================================

#ifdef HASHMETHOD
#define ADTMETHOD       "HASH"

#define MEMOVD	(sizeof(ht))     /* the hash table is overhead */

#define STORESTRING(STRING)   hashinsert(ht, STRING)

#define GETSTRING(STRING)                                               \
{                                                                       \
        HASHREC *_return;                                               \
        _return = hashsearch(ht, STRING);                               \
        if (_return == NULL)              /* not found -- bug */        \
        {                                                               \
               printf("GETSTRING(hash) failed -- BUG!\n\n");            \
               exit(1);                                                 \
        }                                                               \
}

/* Author J. Zobel, April 2001.
   Permission to use this code is freely granted, provided that this
   statement is retained. */

#define TSIZE (1LU << 20)  /* many processors need this to be a pwr of 2 */
#define SEED	1159241
#define HASHFN  bitwisehash

#define INITARRAY       static HASHREC *ht[TSIZE]
#define SIZEOFINIT      sizeof(ht[TSIZE])

typedef struct hashrec
{
    char     *word;
    struct hashrec *next;
}
HASHREC;

/* Bitwise hash function.  Note that tsize does not have to be prime. */
unsigned int
bitwisehash(char *word, int tsize, unsigned int seed)
{
    char      c;
    unsigned int h;

    h = seed;
    for (; (c = *word) != '\0'; word++)
    {
        h ^= ((h << 5) + c + (h >> 2));
    }
    return ((unsigned int)((h & 0x7fffffff) % tsize));
}

#ifdef notdef                   // not needed if a static definition used in UNIX
/* Create hash table, initialise ptrs to NULL */
HASHREC **
inithashtable()
{
    int       i;
    HASHREC **ht;

    ht = (HASHREC **) malloc(sizeof(HASHREC *) * TSIZE);

    for (i = 0; i < TSIZE; i++)
        ht[i] = (HASHREC *) NULL;

    return (ht);
}
#endif // notdef

/* Search hash table for given string, return record if found, else NULL */
HASHREC  *
hashsearch(HASHREC ** ht, char *w)
{
    HASHREC  *htmp, *hprv;
    unsigned int hval = HASHFN(w, TSIZE, SEED);

    for (hprv = NULL, htmp = ht[hval];
         htmp != NULL && scmp(htmp->word, w) != 0;
         hprv = htmp, htmp = htmp->next)
    {
        ;
    }

    if (hprv != NULL && htmp != NULL) /* move to front on access */



( run in 1.532 second using v1.01-cache-2.11-cpan-140bd7fdf52 )