Logo Search packages:      
Sourcecode: likewise-open version File versions  Download package

CENTERROR CTStableHashTableInsert ( PSHASH_TABLE  tab,
lwgpointer  key,
lwgpointer  value 
)

Insert a key.

Inserts a key/value pair into the table. If the key was not previously present in the table, it will added to the end of the iteration order. If it was already present, the previous pair will be replaced and the iteration order will be unchanged.

Parameters:
tab the table in which to insert
key a key of user-defined type to insert into the table
value a value of user-defined associated with key

Definition at line 113 of file cthash.c.

References SHASH_PAIR::key, SHASH_TABLE::list, SHASH_TABLE::table, and SHASH_PAIR::value.

{
    CENTERROR ceError = CENTERROR_SUCCESS;
    LWGList* old_link;
    if ((old_link = (LWGList*) lwg_hash_table_lookup(tab->table, key)) != NULL)
    {
        PSHASH_PAIR pair = (PSHASH_PAIR) old_link->data;
        lwg_hash_table_replace(tab->table, key, old_link);
        if (tab->value_free)
            tab->value_free(pair->value);
        if (tab->key_free)
            tab->key_free(pair->key);
        pair->value = value;
        pair->key = key;

    }
    else
    {
        PSHASH_PAIR pair = NULL;
        LWGList* link = NULL;

        ceError = CTAllocateMemory(sizeof(SHASH_PAIR), (PVOID*) &pair);
        BAIL_ON_CENTERIS_ERROR(ceError);
        
        pair->key = key;
        pair->value = value;
        
        tab->list = lwg_list_append(tab->list, pair);
        link = lwg_list_last(tab->list);
        lwg_hash_table_insert(tab->table, key, link);
    }

error:
    return ceError;
}


Generated by  Doxygen 1.6.0   Back to index