FB_HashTableCtrl

FB_HashTableCtrl 1:

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:

FB_HashTableCtrl 2: 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

T_HashTableEntry

Address for data element (input parameter)

FB_HashTableCtrl 3: Inputs/outputs

VAR_IN_OUT
    hTable  : T_HHASHTABLE;
END_VAR

Name

Type

Description

hTable

T_HHASHTABLE

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.

FB_HashTableCtrl 4: 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

T_HashTableEntry

The address for the data element (output parameter).

Example:

See: Example: Hash table (FB_HashTableCtrl).

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)