FB_HashTableCtrl 1:

The hash table can be used as an efficient tool for finding individual data element 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, using the hashing with chaining (separate chaining) procedure. 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:


    hTable  : T_HHASHTABLE;

hTable: Hash table handle (type: T_HHASHTABLE). The handle must be initialized once with the function F_CreateHashTableHnd before it can be used. A corresponding instance of the handle variable must be created and initialized for each table.


    key       : DWORD := 0;
    putValue  : PVOID := 0;
    putPosPtr : POINTER TO T_HashTableEntry := 0;

key: Key (unsigned 32 bit number or pointer). This key enables a data object to be identified and found quickly in the table.

putValue: Value/data element (input parameter, 32/64 bit, unsigned number or pointer).

putPosPtr: Address for data element (input parameter, type: T_HashTableEntry)


    bOk        : BOOL := FALSE;
    getValue   : PVOID := 0;
    getPosPtr  : POINTER TO T_HashTableEntry := 0;

bOk: 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 (table has no free data elements).

getValue: 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, type: T_HashTableEntry).


See: Example: Hash table (FB_HashTableCtrl).


Development environment

Target platform

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_Utilities (System)