FB_Ordered_Hash_Set (Function Block)

A collection that stores unique items while preserving their insertion order. Implemented using hash table with closed addressing.

Extends: FB_Collection

Implements: I_Hash_Set

Properties

_Bucket_Count

Type: T_Capacity

Number of buckets in the hash set.

Methods

Clear

Empties/Clears/Deletes every item in the set.

Contains

Checks if item is contained in set.

Inputs

Name

Type

Description

Item

ANY

Item to find.

Create_Buckets

Creates buckets and initialises them since user defined types can’t be created as arrays dynamically using __NEW(…).

Inputs

Name

Type

Description

Count

T_Capacity

Outputs

Name

Type

Description

bSuccess

BOOL

Error

T_Error

Create_Node

Creates a new node in dynamic memory with a clone of the generic item as it data.

Inputs

Name

Type

Description

Item

T_Generic

Outputs

Name

Type

Description

bSuccess

BOOL

Error

T_Error

Delete_Node

Safety deletes node. If the node and/or it’s value/data is in dynamic memory it/they will be deleted.

Inputs

Name

Type

Description

pNode

REFERENCE TO POINTER TO ST_ORDERED_HASHSET_BUCKET_NODE

FB_exit

Inputs

Name

Type

Description

bInCopyCode

BOOL

if TRUE, the exit method is called for exiting an instance that is copied afterwards (online change).

FB_init

Inputs

Name

Type

Description

bInitRetains

BOOL

if TRUE, the retain variables are initialized (warm start / cold start)

bInCopyCode

BOOL

if TRUE, the instance afterwards gets moved into the copy code (online change)

Initial_Bucket_Count

T_Capacity

Number of buckets you want to initialise the hash set with. Use 0 if you don’t know.

Get_Values

Gets an immutable list of the values in the set.

Hash

Wrapper for murmur3 hash function that generates a value that fits in the upperage of DINT to avoid negative values due to integer overflow.

Inputs

Name

Type

Description

Data

T_Generic

Insert

Insert item into set.

Inputs

Name

Type

Description

Item

ANY

Data to insert

Outputs

Name

Type

Description

bSuccess

BOOL

Indicates whether operation was successful. Success = TRUE, Failure = FALSE

Insert_Generic

Adds new generic item at into set. The set will store a copy of the generic item so as to not modify the original value outside it’s scope.

Inputs

Name

Type

Description

Item

T_Generic

Item to store

Outputs

Name

Type

Description

bSuccess

BOOL

Indicates whether operation was successful. Success = TRUE, Failure = FALSE

Remove

Removes item from the set.

Inputs

Name

Type

Description

Item

ANY

Data to remove

Outputs

Name

Type

Description

bSuccess

BOOL

Indicates whether operation was successful. Success = TRUE, Failure = FALSE

Remove_Generic

Removes generic item from the set.

Inputs

Name

Type

Description

Item

T_Generic

Data to remove

Outputs

Name

Type

Description

bSuccess

BOOL

Indicates whether operation was successful. Success = TRUE, Failure = FALSE

Resize

Sets the number of buckets in the hash set. Existing items are rehashed and redistributed into the new buckets. Note that of the count is 0 the hashtable is cleared.

Inputs

Name

Type

Description

Count

T_Capacity

Outputs

Name

Type

Description

bSuccess

BOOL