fisothemes / TwinCAT-Hashing-Algorithms

A library containing the most commonly used non-cryptographic hashing functions such as MurmurHash3, CRC32 and FNV1a. All functions Hash data of type ANY.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TwinCAT Hashing Algorithms

A library containing the most commonly used non-cryptographic hashing functions such as MurmurHash3, CRC32 and FNV1a. All functions Hash data of type ANY.

Table of Contents

F_CRC32

Signature:

FUNCTION F_CRC32 : DWORD
VAR_INPUT
	Data : ANY;
END_VAR

Example

Declarations:

sData        : STRING  := '123456789';
nData        : DINT    := 123456789;
nSTRING_Hash,
nDINT_Hash   : DWORD;

Implementation:

nSTRING_Hash    := F_CRC32(sData); // Output: 3421780262
nDINT_Hash      := F_CRC32(nData); // Output: 417295518

Source: https://lxp32.github.io/docs/a-simple-example-crc32-calculation/

F_DJB2

Signature:

FUNCTION F_DJB2 : DWORD
VAR_INPUT
	Data : ANY;
END_VAR

Example

Declarations:

sData        : STRING  := '123456789';
nData        : DINT    := 123456789;
nSTRING_Hash,
nDINT_Hash   : DWORD;

Implementation:

nSTRING_Hash    := F_DJB2(sData); // Output: 902675330
nDINT_Hash      := F_DJB2(nData); // Output: 2087454537

Source: http://www.cse.yorku.ca/~oz/hash.html

F_FNV1a

Signature:

FUNCTION F_FNV1a : DWORD
VAR_INPUT
	Data : ANY;
END_VAR

Example

Declarations:

sData        : STRING  := '123456789';
nData        : DINT    := 123456789;
nSTRING_Hash,
nDINT_Hash   : DWORD;

Implementation:

nSTRING_Hash    := F_FNV1a(sData); // Output: 3146166556
nDINT_Hash      := F_FNV1a(nData); // Output: 1186151337

Source: http://www.isthe.com/chongo/tech/comp/fnv/

F_Lose_Lose

Signature:

FUNCTION F_Lose_Lose : DWORD
VAR_INPUT
	Data : ANY;
END_VAR

Example

Declarations:

sData        : STRING  := '123456789';
nData        : DINT    := 123456789;
nSTRING_Hash,
nDINT_Hash   : DWORD;

Implementation:

nSTRING_Hash    := F_Lose_Lose(sData); // Output: 477
nDINT_Hash      := F_Lose_Lose(nData); // Output: 324

Source: http://www.cse.yorku.ca/~oz/hash.html

F_MurMurHash3

Signature:

FUNCTION F_MurMurHash3 : DWORD
VAR_INPUT
	Data : ANY;
END_VAR

Example

Declarations:

sData        : STRING  := '123456789';
nData        : DINT    := 123456789;
nSTRING_Hash,
nDINT_Hash   : DWORD;

Implementation:

nSTRING_Hash    := F_MurMurHash3(sData); // Output: 3036607362
nDINT_Hash      := F_MurMurHash3(nData); // Output: 3206620847

Source: https://en.wikipedia.org/wiki/MurmurHash

F_SDBM

Signature:

FUNCTION F_SDBM : DWORD
VAR_INPUT
	Data : ANY;
END_VAR

Example

Declarations:

sData        : STRING  := '123456789';
nData        : DINT    := 123456789;
nSTRING_Hash,
nDINT_Hash   : DWORD;

Implementation:

nSTRING_Hash    := F_SDBM(sData); // Output: 1755344949
nDINT_Hash      := F_SDBM(nData); // Output: 912040036

Source: http://www.cse.yorku.ca/~oz/hash.html

F_Hash_Code

Description:

64-bit hash code generated using MurmurHash3 and FNV1a hashing algorithms. Hash code is different for each runtime to mitigate hash flooding.

Signature:

FUNCTION F_Hash_Code : LWORD
VAR_INPUT
	Data : ANY;
END_VAR

Example

Declarations:

sData        : STRING  := '123456789';
nData        : DINT    := 123456789;
nSTRING_Hash,
nDINT_Hash   : LWORD;

Implementation:

nSTRING_Hash    := F_Hash_Code(sData); // Output: See description
nDINT_Hash      := F_Hash_Code(nData); // Output: See description

Developer Notes

TBD

About

A library containing the most commonly used non-cryptographic hashing functions such as MurmurHash3, CRC32 and FNV1a. All functions Hash data of type ANY.

License:MIT License