Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
hash.h
1// SPDX-FileCopyrightText: © 2021-2022, 2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "utils/types.h"
7
8#include <QFile>
9
10#include <xxhash.h>
11
12namespace zrythm::utils::hash
13{
14using HashT = XXH64_hash_t;
15
16template <typename T>
17HashT
18get_custom_hash (const T * data, size_t size)
19{
20 return XXH3_64bits (data, size);
21}
22
23// Hash any object
24template <typename T>
25HashT
26get_object_hash (const T &obj)
27{
28 return get_custom_hash (&obj, sizeof (T));
29}
30
31// Hash string contents
32inline HashT
33get_string_hash (const std::string &str)
34{
35 return get_custom_hash (str.data (), str.size ());
36}
37
38// Hash a file
39HashT
40get_file_hash (const std::filesystem::path &path);
41
42// Get canonical string representation of a hash
43std::string
44to_string (HashT hash);
45
46}; // namespace zrythm::utils::hash