ucif/antlr3/src/antlr3collections.c
static  ANTLR3_INT32
antlr3HashPut(pANTLR3_HASH_TABLE table, void * key, void * element, void (ANTLR3_CDECL *freeptr)(void *))
{
        ANTLR3_UINT32       hash;
        pANTLR3_HASH_BUCKET         bucket;
        pANTLR3_HASH_ENTRY          entry;
        pANTLR3_HASH_ENTRY          * newPointer;

        /* First we need to know the hash of the provided key
        */
        hash    = antlr3Hash(key, (ANTLR3_UINT32)strlen((const char *)key));

        /* Knowing the hash, we can find the bucket
        */
        bucket  = table->buckets + (hash % table->modulo);

        /* Knowign the bucket, we can traverse the entries until we
        * we find a NULL pointer ofr we find that this is already
        * in the table and duplicates were not allowed.
        */
        newPointer      = &bucket->entries;

        while   (*newPointer !=  NULL)
        {
                /* The value at new pointer is pointing to an existing entry.
                * If duplicates are allowed then we don't care what it is, but
                * must reject this add if the key is the same as the one we are
                * supplied with.
                */
                if  (table->allowDups == ANTLR3_FALSE)
                {
                        if      (strcmp((const char*) key, (const char *)(*newPointer)->keybase.key.sKey) == 0)
                        {
                                return  ANTLR3_ERR_HASHDUP;
                        }
                }

                /* Point to the next entry pointer of the current entry we
                * are traversing, if it is NULL we will create our new
                * structure and point this to it.
                */
                newPointer = &((*newPointer)->nextEntry);
        }

        /* newPointer is now poiting at the pointer where we need to
        * add our new entry, so let's crate the entry and add it in.
        */
        entry   = (pANTLR3_HASH_ENTRY)ANTLR3_MALLOC((size_t)sizeof(ANTLR3_HASH_ENTRY));

        if      (entry == NULL)
        {
                return  ANTLR3_ERR_NOMEM;
        }

        entry->data                     = element;                                      /* Install the data element supplied                            */
        entry->free                     = freeptr;                                      /* Function that knows how to release the entry     */
        entry->keybase.type     = ANTLR3_HASH_TYPE_STR;     /* Indicate the key type stored here for free()         */
    if  (table->doStrdup == ANTLR3_TRUE)
    {
        entry->keybase.key.sKey = ANTLR3_STRDUP(key);   /* Record the key value                                                         */
    }
    else
    {
        entry->keybase.key.sKey = (pANTLR3_UINT8)key;                  /* Record the key value                                                          */
    }
        entry->nextEntry                = NULL;                                 /* Ensure that the forward pointer ends the chain   */

        *newPointer     = entry;    /* Install the next entry in this bucket    */

        table->count++;

        return  ANTLR3_SUCCESS;
}
/** Add the element pointer in to the table, based upon the
 *  hash of the provided key.
 */
Add the element pointer in to the table, based upon the
hash of the provided key.
Add the element pointer in to the table based upon the hash of the provided key .
static  ANTLR3_INT32
antlr3HashPut(pANTLR3_HASH_TABLE table, void * key, void * element, void (ANTLR3_CDECL *freeptr)(void *))
{
        ANTLR3_UINT32       hash;
        pANTLR3_HASH_BUCKET         bucket;
        pANTLR3_HASH_ENTRY          entry;
        pANTLR3_HASH_ENTRY          * newPointer;
        hash    = antlr3Hash(key, (ANTLR3_UINT32)strlen((const char *)key));
        bucket  = table->buckets + (hash % table->modulo);
        newPointer      = &bucket->entries;
        while   (*newPointer !=  NULL)
        {
                if  (table->allowDups == ANTLR3_FALSE)
                {
                        if      (strcmp((const char*) key, (const char *)(*newPointer)->keybase.key.sKey) == 0)
                        {
                                return  ANTLR3_ERR_HASHDUP;
                        }
                }
                newPointer = &((*newPointer)->nextEntry);
        }
        entry   = (pANTLR3_HASH_ENTRY)ANTLR3_MALLOC((size_t)sizeof(ANTLR3_HASH_ENTRY));
        if      (entry == NULL)
        {
                return  ANTLR3_ERR_NOMEM;
        }
        entry->data                     = element;                                      
        entry->free                     = freeptr;                                      
        entry->keybase.type     = ANTLR3_HASH_TYPE_STR;     
    if  (table->doStrdup == ANTLR3_TRUE)
    {
        entry->keybase.key.sKey = ANTLR3_STRDUP(key);   
    }
    else
    {
        entry->keybase.key.sKey = (pANTLR3_UINT8)key;                  
    }
        entry->nextEntry                = NULL;                                 
        *newPointer     = entry;    
        table->count++;
        return  ANTLR3_SUCCESS;
}
static ANTLR3_INT32 antlr3HashPut ( pANTLR3_HASH_TABLE table , void * key , void * element , void ( ANTLR3_CDECL * freeptr ) ( void * ) ) { ANTLR3_UINT32 hash ; pANTLR3_HASH_BUCKET bucket ; pANTLR3_HASH_ENTRY entry ; pANTLR3_HASH_ENTRY * newPointer ; hash = antlr3Hash ( key , ( ANTLR3_UINT32 ) strlen ( ( const char * ) key ) ) ; bucket = table -> buckets + ( hash % table -> modulo ) ; newPointer = & bucket -> entries ; while ( * newPointer != NULL ) { if ( table -> allowDups == ANTLR3_FALSE ) { if ( strcmp ( ( const char * ) key , ( const char * ) ( * newPointer ) -> keybase . key . sKey ) == 0 ) { return ANTLR3_ERR_HASHDUP ; } } newPointer = & ( ( * newPointer ) -> nextEntry ) ; } entry = ( pANTLR3_HASH_ENTRY ) ANTLR3_MALLOC ( ( size_t ) sizeof ( ANTLR3_HASH_ENTRY ) ) ; if ( entry == NULL ) { return ANTLR3_ERR_NOMEM ; } entry -> data = element ; entry -> free = freeptr ; entry -> keybase . type = ANTLR3_HASH_TYPE_STR ; if ( table -> doStrdup == ANTLR3_TRUE ) { entry -> keybase . key . sKey = ANTLR3_STRDUP ( key ) ; } else { entry -> keybase . key . sKey = ( pANTLR3_UINT8 ) key ; } entry -> nextEntry = NULL ; * newPointer = entry ; table -> count ++ ; return ANTLR3_SUCCESS ; }
Add the element pointer in to the table, based upon the
  hash of the provided key.
Add the element pointer in to the table based upon the hash of the provided key .
/* First we need to know the hash of the provided key
        */ /* Knowing the hash, we can find the bucket
        */ /* Knowign the bucket, we can traverse the entries until we
        * we find a NULL pointer ofr we find that this is already
        * in the table and duplicates were not allowed.
        */ /* The value at new pointer is pointing to an existing entry.
                * If duplicates are allowed then we don't care what it is, but
                * must reject this add if the key is the same as the one we are
                * supplied with.
                */ /* Point to the next entry pointer of the current entry we
                * are traversing, if it is NULL we will create our new
                * structure and point this to it.
                */ /* newPointer is now poiting at the pointer where we need to
        * add our new entry, so let's crate the entry and add it in.
        */ /* Install the data element supplied                            */ /* Function that knows how to release the entry     */ /* Indicate the key type stored here for free()         */ /* Record the key value                                                         */ /* Record the key value                                                          */ /* Ensure that the forward pointer ends the chain   */ /* Install the next entry in this bucket    */