FB_Hash_Map (Function Block)

A collection of key value pairs items. Implemented using hash table with closed addressing.

Extends: FB_Collection

Implements: I_Hash_Map

Properties

_Bucket_Count

Type: T_Capacity

Number of buckets in the hash map.

Methods

Clear

Empties/Clears/Deletes every item in the map.

Contains

Checks if key is contained in the map.

Inputs

Name

Type

Description

Key

ANY

Key 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

Key, Value

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 T_Hashmap_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 map with. Use 0 if you don’t know.

Get

Gets the value associated with the specified key without removing it from the map.

Inputs

Name

Type

Description

Key

ANY

Key used to identify stored value

Value

ANY

Variable to store requested data

Outputs

Name

Type

Description

bSuccess

BOOL

Get_As_String

Returns value as a string, if type to string conversion is supported.

Inputs

Name

Type

Description

Key

ANY

Key used to identify stored value

sValue

REFERENCE TO STRING

Variable to store returned item.

Outputs

Name

Type

Description

bSuccess

BOOL

Get_Generic

Gets the value in its generic form associated with the specified key in its generic form without removing it from the map. Use carefully as this contains the pointer of the actual value in the collection. If you wish to use this it is recommeded you create a copy of the returned value using MEMCPY

Inputs

Name

Type

Description

Key

T_Generic

Key used to identify stored value

Outputs

Name

Type

Description

Value

T_Generic

Variable to store requested data

bSuccess

BOOL

Get_Keys

Gets an immutable list of the keys.

Get_Values

Gets an immutable list of the values.

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 an element with the provided key and value to the map.

Inputs

Name

Type

Description

Key

ANY

Key used to identify stored value

Value

ANY

Value to store in map with key

Outputs

Name

Type

Description

bSuccess

BOOL

Insert_Generic

Insert an element with the provided key and value in their generic forms to the map.

Inputs

Name

Type

Description

Key

T_Generic

Key used to identify stored value

Value

T_Generic

Value to store in map with key

bUpdate

BOOL

If this is true the value will be updated if the key already exists.

Outputs

Name

Type

Description

bSuccess

BOOL

Remove

Removes value with the specified key from the map.

Inputs

Name

Type

Description

Key

ANY

Key used to identify stored value

Outputs

Name

Type

Description

bSuccess

BOOL

Remove_Generic

Removes value with the specified key in its generic form from the map.

Inputs

Name

Type

Description

Key

T_Generic

Key used to identify stored value

Outputs

Name

Type

Description

bSuccess

BOOL

Resize

Sets the number of buckets in the hash map. 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

Update

Updates the value at the provided key with the new value in the map.

Inputs

Name

Type

Description

Key

ANY

Key used to identify stored value

Value

ANY

Value to store in map with key

Outputs

Name

Type

Description

bSuccess

BOOL

Update_Generic

Updates the value at the provided key with the new value in their generic forms in the map.

Inputs

Name

Type

Description

Key

T_Generic

Key used to identify stored value

Value

T_Generic

Value to store in map with key

Outputs

Name

Type

Description

bSuccess

BOOL

Upsert

Updates a value in the map for a given key. If the key doesnt exist, it will be inserted.

Inputs

Name

Type

Description

Key

ANY

Key used to identify stored value

Value

ANY

Value to store in map with key

Outputs

Name

Type

Description

bSuccess

BOOL