# util_module

The util module offers a range of functions for tasks such as validation and
creating cryptographic hash values. This module serves as a practical resource
for streamlining a variety of tasks related to database operations.

| Trait               | Value               |
| ------------------- | ------------------- |
| **Module type**     | util                |
| **Implementation**  | C++                 |
| **Graph direction** | directed/undirected |
| **Edge weights**    | weighted/unweighted |
| **Parallelism**     | sequential          |

## Procedures

### `md5()`

The procedure gets the string representation of every element in the input list or string,
concatenates it into a single string, and returns the md5 hash of that string.

The format of string representations can be seen by checking `ToString` in [C++
API](https://memgraph.com/docs/custom-query-modules/cpp/cpp-api) documentation for desired type or Value.

> **Info**
>
> This procedure is equivalent to **apoc.util.md5**.

#### Input:

- `subgraph: Graph` (**OPTIONAL**) ➡ A specific subgraph, which is an [object of type Graph](https://memgraph.com/docs/advanced-algorithms/run-algorithms#run-procedures-on-subgraph) returned by the `project()` function, on which the algorithm is run. 
If subgraph is not specified, the algorithm is computed on the entire graph by default.
- `values: List[Any], Any` ➡ THe input list containing elements which can be any of
  Memgraph's data types. User can also pass any type by itself.

#### Output:

- `result: string` ➡ The resulting md5 hash returned as string.

#### Usage:

The hash provided in this documentation will be different from the user's hash
for the same input unless the node has the same ID because `Node.ToString()`
uses the node's ID in string formation, so different IDs equal different
strings, hence, different hashes:

```cypher
CREATE (d:Dog);
MATCH (d:Dog)
CALL util_module.md5([d, "string", 50])
YIELD result
RETURN result;
```

Result:

```plaintext
+-----------------------------------+
| result                            |
+-----------------------------------+
| 47e656a5f446fc21316e97df90e8ae33  |
+-----------------------------------+
```

## Functions

### `md5()`

The function gets the string representation of every element in the input list or string,
concatenates it into a single string, and returns the md5 hash of that string. Does the same
computation as the `md5()` procedure but can be called as a function

> **Info**
>
> This function is equivalent to **apoc.util.md5**.

The format of string representations can be seen by checking `ToString` in [C++
API](https://memgraph.com/docs/custom-query-modules/cpp/cpp-api) documentation for desired type or Value.

#### Input:

- `values: List[Any], Any` ➡ The input list containing elements which can be any of
  Memgraph's data types. User can also pass any type by itself.

#### Output:

- `result: string` ➡ The resulting md5 hash returned as a string.

#### Usage:

The hash provided in this documentation will be different from the user's hash
for the same input unless the node has the same ID because `Node.ToString()`
uses the node's ID in string formation, so different IDs equal different
strings, hence, different hashes:

```cypher
CREATE (d:Dog);
MATCH (d:Dog)
RETURN util_module.md5([d, "string", 50]) AS result
```

Result:

```plaintext
+-----------------------------------+
| result                            |
+-----------------------------------+
| 47e656a5f446fc21316e97df90e8ae33  |
+-----------------------------------+
```
