TutHashInsert


Name

TutHashInsert — insert an entry into the hash table

Synopsis

void TutHashInsert(table, key, value) 
T_HASH_TABLE table; 
T_PTR key; 
T_PTR value; 

Arguments

table — table where entry is inserted

key — the value that is used as a key to the entry

value — the entry that is stored in the table

Return Values

None

Diagnostics

None

Description

TutHashInsert inserts an entry into table. The type of key should be consistent with the key type specified when table was created.

Caution

Hash tables do not manage storage for their keys and values. It is up to the caller to manage the memory allocation of the data structures for the keys and values.

value cannot be a null pointer.

See Also

TutHashCreate, TutHashDelete, TutHashLookup, TutHashBucketSetValue

Examples

This example adds an entry to the hash table:

typedef struct entry { 
  T_STR name; 
  T_PTR addr; 
} ENTRY; 
 
T_PTR print_entry(key, value, arg) 
T_PTR key; 
T_PTR value; 
T_PTR arg; 
{ 
  TutOut("Name <%s> has address <%s>\n", key,  
         ((ENTRY *)value)->addr); 
  return NULL; 
} 
 
main() 
{ 
  T_HASH_TABLE table; 
  ENTRY *e; 
 
  /* Initialize the hash table */ 
  table = TutHashCreateStr(4); 
  
  /* Allocate one entry */ 
  e = TutMalloc(sizeof(ENTRY)); 
  e->name = TutMalloc(25); 
  e->addr = TutMalloc(50); 
  
  /* Set the values in the entry */ 
  strcpy(e->name, "Johnson"); 
  strcpy(e->addr, "1234 Mulberry Lane"); 
 
  /* Insert the entry into the table */ 
  TutHashInsert(table, e->name, e); 
 
  /* Echo the whole table */ 
  TutHashTraverse(table, print_entry, NULL); 
} 

The example produces this output:

Name <Johnson> has address <1234 Mulberry Lane> 

TIBCO SmartSockets™ Utilities
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com