Returns a hash code, as an INTEGER value, for one or more arguments. The HASH-CODE function is intended to be used in objects that are part of a hash-based collection, that is, those that implement the Progress.Collections.IHashable interface or the Progress.Collections.IEqualityComparer<T> interface.

Syntax

HASH-CODE(arg [, arg]…)
arg
An expression of any of the data types allowed when defining a variable.This includes scalar data types, object-oriented ABL object types, and the Unknown value (?). BLOB/CLOB types are not supported.

The function accepts up to 10 arguments. If you need more than 10 arguments, you can calculate the hash code for the first 10, and then feed the result into another call to HASH-CODE.

Example

The following code example uses the HASH-CODE function to generate a hash code based on a first and last name.

VAR CHAR FirstName.
VAR CHAR LastName.
VAR INT hashval.
...
hashval = HASH-CODE(FirstName, LastName).

Notes

  • This function is intended for use with hash-based collections only.
  • The hash code returned by the HASH-CODE function is consistent within a given ABL session. Once the ABL session is restarted, there is no guarantee that the hash code will be the same. Therefore, it is strongly recommended that you do not store or pass the hash code between sessions, as the value may not be the same while executing in different sessions.
  • The HASH-CODE function is provided specifically to support hash-based collection within a given session and is not a replacement for the ENCODE function, nor is it suitable for any cryptography tasks. Its sole purpose is to provide a hash code that can be used with hash-based collections.
  • The order of the arguments can change the resulting hash code value. Therefore, if comparing the value returned by the function, be consistent with the order of the parameters.
  • Any two values that return TRUE when compared with the EQ operator in ABL return the same hash code. Simply put, given two values, val1 and val2, if the expression val1 EQ val2 returns TRUE, then HASH-CODE(val1) EQ HASH-CODE(val2) is also true.
  • The format of a given field or variable does not impact the calculation of the hash code, only the actual data does.
  • A given integer value returns the same hash code whether it is represented using either the INTEGER or INT64 data type (assuming the value does not overflow the INTEGER data type).
  • A given decimal value with no significant decimal places (that is 5 EQ 5.00 returns TRUE) returns the same hash code regardless of the number of decimal places specified.
  • Values of type CHARACTER and LONGCHAR generate the hash code respecting the case-insensitiveness of the values. That is, a value of either one of those data types generate the same hash code if two case-insensitive strings are considered equal. If the value is case-sensitive, the hash code is not expected to be the same as another value that is case-insensitive, unless both strings match exactly.
  • LONGCHAR strings of different code pages are always converted to the codepage specified by the -cpinternal startup parameter for comparison and return the same hash code if they are considered to be equal by the AVM.
  • For MEMPTR values, HASH-CODE uses all the bytes stored in the memptr, as defined by its size (as returned by the GET-SIZE function) when generating the hash code. All other data types use the data as provided by the expression that generated them.
  • When passing an object-oriented ABL object as an argument to the HASH-CODE function, the AVM checks if the object implements the Progress.Collection.IHashable interface, in which case it calls the HashCode() method to get the hash code for that object instance. If the object does not implement such interface, the AVM uses an internally generated value that is guaranteed not to change while the object is still in scope.

See also

Progress.Collections.IHashable interface, Progress.Collections.IEqualityComparer<T> interface