HashTableCreate
int HashTableCreate (unsigned int initialSize, HashTableKeyType keyType, size_t keySize, size_t valueSize, HashTableType *table);
Purpose
Creates a hash table that stores key-value pairs of the specified type and size.
The table creates allocated copies of the key and value data that you store in it; however, if you store pointers, the table stores only the pointers themselves — not the data pointed to.
When you finish using the hash table, you must call HashTableDispose to free its resources.
Parameters
Input | ||||||
Name | Type | Description | ||||
initialSize | unsigned int |
Approximate number of key-value pairs that you expect to store in the hash table. This value determines the number of buckets initially allocated.
The number of buckets initially allocated is the smallest power of two that is at least 125% of the initialSize. The function always allocates a minimum of 32 buckets. The hash table may grow beyond this size if you enable growing, but the table never shrinks beyond this initial size even if you enable shrinking. An accurate initial size estimate can accelerate table access and eliminate the need to resize the table, which is a time-consuming operation. |
||||
keyType | HashTableKeyType |
The type of the keys to use in the table. The following values are valid:
|
||||
keySize | size_t |
If keyType is FIXED_SIZE_KEY, pass the size, in bytes, of the keys you will use.
If keyType is C_STRING_KEY this parameter is ignored. |
||||
valueSize | size_t |
The size, in bytes, of the values to store in the hash table.
|
||||
Output | ||||||
Name | Type | Description | ||||
table | HashTableType |
A reference to a HashTableType variable that stores the created hash table. If the function returns an error, table contains NULL. |
Return Value
Name | Type | Description |
status | int |
Returns a value indicating if the function was successful.
A negative number means an error occurred. For a detailed error message, pass the returned value to GetGeneralErrorString. |
Additional Information
Library: Programmer's Toolbox
Include file: toolbox\toolbox.h
LabWindows/CVI compatibility: LabWindows/CVI 8.5 and later
Example
Refer to toolbox\hashtable.cws for an example of using the HashTableCreate function.