# Hash128

> Represents a 128-bit hash value.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule
* **Implements:** [IComparable](https://learn.microsoft.com/dotnet/api/system.icomparable), [IComparable\<Hash128>](https://learn.microsoft.com/dotnet/api/system.icomparable-1), [IEquatable\<Hash128>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct Hash128 : IComparable, IComparable<Hash128>, IEquatable<Hash128>
```

## Remarks

Use `Hash128` to uniquely identify a piece of data. A 128-bit hash value has an extremely low probability of hash collisions, so you can assume that if the hash values of two pieces of data are identical, then the data is identical too. For example, to quickly determine whether texture pixel contents have changed, or if they are identical between several textures, you can use [Texture.imageContentsHash](/engine/6000.6/script-reference/unityengine/texture/imagecontentshash.md).

To compute the hash values for some data, use the [Hash128.Compute](/engine/6000.6/script-reference/unityengine/hash128/compute.md) function. To compute the hash values incrementally for several pieces of data, use [Hash128.Append](/engine/6000.6/script-reference/unityengine/hash128/append.md).

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    void Start()
    {
        var hash = new Hash128();
        hash.Append(42);
        hash.Append(13.0f);
        hash.Append("Hello");
        hash.Append(new int[] {1, 2, 3, 4, 5});
        // prints "2d6e582c3fcfb4b8f3c16650a75dc37b"
        Debug.Log(hash.ToString());
    }
}
```

The hash algorithm used to compute `Hash128` values is [SpookyHash V2](https://en.wikipedia.org/wiki/Jenkins_hash_function#SpookyHash). Note that while this hash algorithm is quite fast to compute and has good hash distribution qualities, it is not a cryptographic hash function.

## Constructors

| Constructor                                                                                                                                                    | Description                                         |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| [Hash128(System.UInt32,System.UInt32,System.UInt32,System.UInt32)](/engine/6000.6/script-reference/unityengine/hash128/ctor.md#hash128\(uint-uint-uint-uint\)) | Directly initialize a Hash128 with a 128-bit value. |
| [Hash128(System.UInt64,System.UInt64)](/engine/6000.6/script-reference/unityengine/hash128/ctor.md#hash128\(ulong-ulong\))                                     | Directly initialize a Hash128 with a 128-bit value. |

## Properties

| Property                                                                  | Description                                          |
| ------------------------------------------------------------------------- | ---------------------------------------------------- |
| [isValid](/engine/6000.6/script-reference/unityengine/hash128/isvalid.md) | Returns true is the hash value is valid. (Read Only) |

## Methods

| Method                                                                      | Description                                                  |
| --------------------------------------------------------------------------- | ------------------------------------------------------------ |
| [Append](/engine/6000.6/script-reference/unityengine/hash128/append.md)     | Hash new input data and combine with the current hash value. |
| [ToString](/engine/6000.6/script-reference/unityengine/hash128/tostring.md) | Convert a Hash128 to string.                                 |

## Static Methods

| Method                                                                    | Description                                      |
| ------------------------------------------------------------------------- | ------------------------------------------------ |
| [Compute](/engine/6000.6/script-reference/unityengine/hash128/compute.md) | Compute a hash of input data.                    |
| [Parse](/engine/6000.6/script-reference/unityengine/hash128/parse.md)     | Convert a hex-encoded string into Hash128 value. |
