TutHashCreateInt create a hash table with integer keys
init_size
the initial size of the hash table
Returns a new hash table suitable for integer keys.
None
TutHashCreateInt creates a new hash table with integers for keys.
Providing an init_size
that is too small causes the hash table to be resized often as new entries are inserted.
TutHashCreate, TutHashCreatePtr, TutHashCreateStr, TutHashCreateStri
This example uses a hash table to look up string values from integer keys. Integer keys should be cast to (T_PTR) to avoid warnings from C compilers that understand function prototypes.
T_HASH_TABLE hash_table;
hash_table = TutHashCreateInt(4);
/* map integer directions to direction strings */
TutHashInsert(hash_table, (T_PTR)1, "NORTH");
TutHashInsert(hash_table, (T_PTR)2, "EAST");
TutHashInsert(hash_table, (T_PTR)3, "SOUTH");
TutHashInsert(hash_table, (T_PTR)4, "WEST");
TutOut("The value for 3 is %s.\n",
TutHashLookup(hash_table, (T_PTR)3));
This example is the hash function and test function used by TutHashCreateInt:
/* ============================================================= */
/*..utHashCalcInt -- hash function for ints */
static T_INT4 utHashCalcInt(key) T_PTR key; { return *(T_INT4 *)key; }/* utHashCalcInt */
/* ============================================================== */
/*..utHashTestInt -- test function for ints */
static T_BOOL utHashTestInt(key1, key2) T_PTR key1;/* really an int */
T_PTR key2;/* really an int */
{ return *(T_INT4 *)key1 == *(T_INT4 *)key2; }/* utHashTestInt */
This example creates the hash table:
/* ============================================================== */
/*..TutHashCreateInt -- convenience func to create hash table with int keys */
T_HASH_TABLE TutHashCreateInt(init_size) T_INT4 init_size;/* initial size of hash table */
{ return TutHashCreate(init_size, utHashCalcInt, utHashTestInt); }/* TutHashCreateInt */
TIBCO SmartSockets™ Utilities Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |