UaServerHashTable


Data Structures

struct  _UaServer_TableEntry
 A UaServer TableEntry Struct. More...
struct  _UaServer_HashTable
 A UaServer HashTable Struct. More...

Typedefs

typedef struct _UaServer_TableEntry UaServer_TableEntry
 A UaServer TableEntry Struct.
typedef struct _UaServer_HashTable UaServer_HashTable
 A UaServer HashTable Struct.

Functions

OpcUa_Void UaServer_HashTable_Initialize (UaServer_HashTable *pTable, int size, pt2GetKeyFromValue fctPtr)
 Initializes a hash table.
OpcUa_Void UaServer_HashTable_Cleanup (UaServer_HashTable *pTable)
 Cleans up hash table struct.
OpcUa_Void UaServer_HashTable_AddElement (UaServer_HashTable *pTable, char *szKey, OpcUa_Void *pData)
 Adds the given value pData with the key pKey to the hash table.
OpcUa_Void UaServer_HashTable_AddAt (UaServer_HashTable *pTable, int index, OpcUa_Void *pData)
 Adds the given value pData to the hash table at position index.
UaServer_TableEntryUaServer_HashTable_GetAt (UaServer_HashTable *pTable, int index)
 Returns the table entry at the given position.
OpcUa_Void * UaServer_HashTable_RemoveElement (UaServer_HashTable *pTable, char *szKey)
 Removes the given element from hash table and returns it.
OpcUa_Void * UaServer_HashTable_Lookup (UaServer_HashTable *pTable, char *szKey)
 Looks up the given element from hash table and returns it.
unsigned int UaServer_HashTable_HashString (UaServer_HashTable *pTable, char *szKey)
 Simple wrapper function for hashing strings.
unsigned int UaServer_HashTable_Hash (UaServer_HashTable *pTable, OpcUa_Void *pKey, OpcUa_UInt32 iKeyLen)
 Rotating hash algorithm.

Function Documentation

OpcUa_Void UaServer_HashTable_AddAt ( UaServer_HashTable pTable,
int  index,
OpcUa_Void *  pData 
)

Adds the given value pData to the hash table at position index.

This is used for prehashed keys or index based data. The differences to a simple array is that this function still uses the hash table's collision reduction stratagy and you can add multiple items at the same position without an error.

Parameters:
pTable hash table object
index index where the value is stored.
pData data to add
See also:
UaServer_HashTable_Lookup
This is used for prehashed keys or index based data. The differences to a simple array is that this function still uses the hash table's collision reduction stratagy and you can add multiple items at the same position without an error.
Parameters:
pTable hash table object
index index where the value is stored.
pData value to add
See also:
UaServer_HashTable_Lookup

OpcUa_Void UaServer_HashTable_AddElement ( UaServer_HashTable pTable,
char *  szKey,
OpcUa_Void *  pData 
)

Adds the given value pData with the key pKey to the hash table.

Parameters:
pTable hash table object
szKey key which identifies the value
pData data to add
See also:
UaServer_HashTable_Lookup
Parameters:
pTable hash table object
szKey key which identifies the value
pData value to add
See also:
UaServer_HashTable_Lookup

OpcUa_Void UaServer_HashTable_Cleanup ( UaServer_HashTable pTable  ) 

Cleans up hash table struct.

This deletes all memory allocated by hash table, but not the data referenced by the table.

Parameters:
pTable hash table object

UaServer_TableEntry * UaServer_HashTable_GetAt ( UaServer_HashTable pTable,
int  index 
)

Returns the table entry at the given position.

Use this to iterate over the list yourself.

Parameters:
pTable hash table object that should be initialized.
index index where the value is stored.
Returns:
the table entry at the given position.
Use this to iterate over the list yourself.

unsigned int UaServer_HashTable_Hash ( UaServer_HashTable pTable,
OpcUa_Void *  pKey,
OpcUa_UInt32  iKeyLen 
)

Rotating hash algorithm.

This simple and fast algorithm is ideal for hash table searches. It's not a cryptographic hash!

 !!! 'int' is used consciously instead of OpcUa_Int32,
 !!! because the hash is an array index,
 !!! which is 'int' by definition (address bus width).
 
This works for 16, 32 and 64 bit systems.
Parameters:
pTable hash table object that should be initialized.
pKey key which identifies the value
iKeyLen the length of the key.
Returns:
Rotating hash algorithm.
This simple and fast algorithm is ideal for hash table searches. It's not a cryptographic hash!
 !!! 'int' is used consciously instead of OpcUa_Int32,
 !!! because the hash is an array index,
 !!! which is 'int' by definition (address bus width).
 
This works for 16, 32 and 64 bit systems.

unsigned int UaServer_HashTable_HashString ( UaServer_HashTable pTable,
char *  szKey 
)

Simple wrapper function for hashing strings.

You can configure this to work case sensitive or case insensitive, by using the define CASE_SENSITIVE. The first variant is much faster.

See also:
UaServer_HashTable_Hash

OpcUa_Void UaServer_HashTable_Initialize ( UaServer_HashTable pTable,
int  size,
pt2GetKeyFromValue  fctPtr 
)

Initializes a hash table.

Parameters:
pTable hash table object that should be initialized.
size Size of hash table. Use a predefined size HASH_SIZE_XXX.
fctPtr function pointer to function that retrieves the key string from the data value.

OpcUa_Void * UaServer_HashTable_Lookup ( UaServer_HashTable pTable,
char *  szKey 
)

Looks up the given element from hash table and returns it.

  1. It generates the hash for the key to find the element by direct index access in the table.
  2. If there is only one element at this index, this gets returned. If there are more elements (hash collision), the elements in list are searched by linear probing.
Parameters:
pTable hash table object
szKey key to search for
Returns:
found element or OpcUa_Null if not found

OpcUa_Void * UaServer_HashTable_RemoveElement ( UaServer_HashTable pTable,
char *  szKey 
)

Removes the given element from hash table and returns it.

It searches the element simalar to UaServer_HashTable_Lookup, removes the entry from table and returns the data value.

Parameters:
pTable hash table object
szKey key to search for
Returns:
removed element or OpcUa_Null if not found
See also:
UaServer_HashTable_Lookup