Messagelib

md5hash.h
1// SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org>
2// SPDX-License-Identifier: LGPL-2.0-or-later
3
4#pragma once
5
6#include <QByteArrayView>
7#include <QHash>
8
9#include <cstring>
10
11namespace MessageList
12{
13namespace Core
14{
15
16/** Compact storage of the result of an MD5 hash computation, for use in the threading code. */
18{
19public:
20 inline MD5Hash()
21 {
22 std::memset(&data, 0, sizeof(MD5Hash));
23 }
24 inline MD5Hash(QByteArrayView ba)
25 {
26 if (ba.size() != sizeof(MD5Hash)) {
27 std::memset(&data, 0, sizeof(MD5Hash));
28 return;
29 }
30
31 std::memcpy(&data, ba.constData(), sizeof(MD5Hash));
32 }
33 inline MD5Hash(const MD5Hash &other)
34 {
35 std::memcpy(&data, &other.data, sizeof(MD5Hash));
36 }
37
38 inline MD5Hash &operator=(const MD5Hash &other)
39 {
40 std::memcpy(&data, &other.data, sizeof(MD5Hash));
41 return *this;
42 }
43
44 inline bool operator==(MD5Hash other) const
45 {
46 return std::memcmp(&data, &other.data, sizeof(MD5Hash)) == 0;
47 }
48
49 inline bool isEmpty() const
50 {
51 return *reinterpret_cast<const quint64 *>(&data) == 0 && *(reinterpret_cast<const quint64 *>(&data) + 1) == 0;
52 }
53
54 uint8_t data[16];
55};
56
57inline std::size_t qHash(MD5Hash key, std::size_t seed)
58{
59 return ::qHash(*reinterpret_cast<quint64 *>(&key.data), seed) ^ ::qHash(*(reinterpret_cast<quint64 *>(&key.data) + 1), seed);
60}
61
62}
63}
Compact storage of the result of an MD5 hash computation, for use in the threading code.
Definition md5hash.h:18
const_pointer constData() const const
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.