FB_HashTableCtrl
The hash table can be used to find an individual data element quickly among a larger number of data elements. The data objects must have a unique key. The key enables the data objects to be identified unambiguously and found quickly in the table.
The function block FB_HashTableCtrl can be used to realize a simple hash table in the PLC project. The hashing with chaining (separate chaining) procedure is used.
The maximum number of data elements cannot be changed at runtime and must be specified in advance. Adding/removing/finding of data elements is controlled through action calls. The function block features the following tasks:
- A_Add (adds a new data element to the table (key/value). If an element with the same key already exists, it is overwritten! )
- A_GetFirst (reads the first table data element. If successful, getValue supplies the associated value.)
- A_GetNext (reads the next table data element. The address: putPosPtr must point to the previous data element!)
- A_Lookup (looks for a data element matching the key. If successful, getValue supplies the associated value.)
- A_Remove (removes a data element matching the key.)
- A_RemoveAll (removes all data elements)
- A_RemoveFirst (removes the first data element)
- A_reset (deletes all data elements and resets the table.)
- A_GetIndexAtPosPtr (returns the array index of the data element at the address: putPosPtr. When successful, getValue returns the null-based array index. The value putValue is not used. Please note that the value getValue returns a data element index, not the data element value! )
Inputs
VAR_INPUT
key : DWORD := 0;
putValue : PVOID := 0;
putPosPtr : POINTER TO T_HashTableEntry := 0;
END_VAR
Name | Type | Description |
---|---|---|
key | DWORD | Key (unsigned 32 bit number or pointer). This key enables a data object to be identified and found quickly in the table. |
putValue | PVOID | Value/data element (input parameter, 32/64 bit, unsigned number or pointer). |
putPosPtr | Address for data element (input parameter) |
Inputs/outputs
VAR_IN_OUT
hTable : T_HHASHTABLE;
END_VAR
Name | Type | Description |
---|---|---|
hTable | Hash table handle. The handle must be initialized once with the function: F_CreateHashTableHnd before it will be used. A corresponding instance of the handle variable must be created and initialized for each table. |
Outputs
VAR_OUTPUT
bOk : BOOL := FALSE;
getValue : PVOID := 0;
getPosPtr : POINTER TO T_HashTableEntry := 0;
END_VAR
Name | Type | Description |
---|---|---|
bOk | BOOL | Returns TRUE if a new data element was added to/removed from or found in the table. Returns FALSE, if the searched data element was not found, the table is empty or an overflow occurred (no more free data elements). |
getValue | PVOID | The value matching the key/data element (output parameter, 32/64 bit, unsigned number or pointer). |
getPosPtr | The address for the data element (output parameter). |
Requirements
Development environment |
Target platform |
PLC libraries to be integrated (category group) |
---|---|---|
TwinCAT v3.1.0 |
PC or CX (x86, x64, ARM) |
Tc2_Utilities (System) |