Class Hash
This static class contains functions for calculating hashes from different Unity types.
All functions are deterministic and are well spread across the output range. This is not secure for cryptography.
Vectors are quantized before hashing - for each component of the vector, work out the closest fraction the number is and use that to seed the hashing algorithm. The size of the fraction is controlled by the quantizationResolution parameter.
Inheritance
Inherited Members
Namespace: CarbideFunction.Wildtile
Syntax
public static class Hash
Methods
CycleShift(IntegerType, Int32)
Left-shift bits around a word, with no loss of data. All bits that flow off either end are added to the opposite end.
This allows the combination of hashes of several similar inputs by avoiding the collision of equal hashes. In particular, this is designed to support hashing Vector2s and Vector3s that should all be between -1 and 1.
Declaration
public static IntegerType CycleShift(IntegerType input, int leftShiftAmount)
Parameters
| Type | Name | Description |
|---|---|---|
| IntegerType | input | |
| System.Int32 | leftShiftAmount |
Returns
| Type | Description |
|---|---|
| IntegerType |
Int(IntegerType)
Hash an int.
Declaration
public static IntegerType Int(IntegerType seed)
Parameters
| Type | Name | Description |
|---|---|---|
| IntegerType | seed |
Returns
| Type | Description |
|---|---|
| IntegerType |
Long(Int64)
Hash a long to an int.
Declaration
public static IntegerType Long(long input)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int64 | input |
Returns
| Type | Description |
|---|---|
| IntegerType |
QuantizedVector(Vector2, Single)
Hash a Vector2. Both components should be between -1 and 1 for a good hash spread, but all values can be hashed with a potentially poorer spread.
Declaration
public static IntegerType QuantizedVector(Vector2 vector, float quantizationResolution)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | vector | The vector to hash |
| System.Single | quantizationResolution | How finely should the vector be split up before hashing. |
Returns
| Type | Description |
|---|---|
| IntegerType |
QuantizedVector(Vector3, Single)
Hash a Vector3. All components should be between -1 and 1 for a good hash spread, but all values can be hashed with a potentially poorer spread.
Declaration
public static IntegerType QuantizedVector(Vector3 vector, float quantizationResolution)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | vector | The vector to hash |
| System.Single | quantizationResolution | How finely should the vector be split up before hashing. |
Returns
| Type | Description |
|---|---|
| IntegerType |
String(String)
Hash a string.
Declaration
public static IntegerType String(string input)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input |
Returns
| Type | Description |
|---|---|
| IntegerType |