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 <QFile>
7
8#include <xxhash.h>
9
10namespace zrythm::utils::hash
11{
12using HashT = XXH64_hash_t;
13
14template <typename T>
15HashT
16get_custom_hash (const T * data, size_t size)
17{
18 return XXH3_64bits (data, size);
19}
20
21// Hash any object
22template <typename T>
23HashT
24get_object_hash (const T &obj)
25{
26 return get_custom_hash (&obj, sizeof (T));
27}
28
29// Hash string contents
30inline HashT
31get_string_hash (const std::string &str)
32{
33 return get_custom_hash (str.data (), str.size ());
34}
35
36// Hash a file
37HashT
38get_file_hash (const std::filesystem::path &path);
39
40// Get canonical string representation of a hash
41std::string
42to_string (HashT hash);
43
44}; // namespace zrythm::utils::hash