TutHashInsert insert an entry into the hash table
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
None
None
TutHashInsert inserts an entry into table
. The type of key
should be consistent with the key type specified when table
was created.
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.
TutHashCreate, TutHashDelete, TutHashLookup, TutHashBucketSetValue
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:
TIBCO SmartSockets™ Utilities Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |