FB_HashTableCtrl

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 realise a simple hash table in the PLC project, using the hashing with chaining (separate chaining) procedure.

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:

VAR_IN_OUT

VAR_IN_OUT
    hTable      : T_HHASHTABLE;
END_VAR

hTable: Hash table handle. 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.

VAR_INPUT

VAR_INPUT
    key         : DWORD := 0;
    putValue    : DWORD := 0;
    putPosPtr   : POINTER TO T_HashTableEntry := 0;
END_VAR

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

putValue: Value/data element (32 bit).

putPosPtr: Address for a previous data element.

VAR_OUTPUT

VAR_OUTPUT
    bOk         : BOOL := FALSE;
    getValue    : DWORD := 0;
    getPosPtr   : POINTER TO T_HashTableEntry := 0;
END_VAR

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.

getPosPtr: The address for the data element.

Example:

See: Example: Hash table (FB_HashTableCtrl).

Requirements

Development environment

Target platform

PLC libraries to be linked

TwinCAT v2.10.0 Build > 1332

PC or CX (x86, ARM)

TcUtilities.Lib