DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
HashHelper.h
Go to the documentation of this file.
1
5
6
#pragma once
7
#include "
Common.h
"
8
#include "
System/Object.h
"
9
#include "
System/String.h
"
10
#include "
System/SmartPointer.h
"
11
12
namespace
DotNetDupe
{
13
namespace
System
{
14
20
template
<
typename
T>
21
struct
HashHelper
{
25
static
int
GetHashCode
(
const
T& value) {
26
const
char
* p =
reinterpret_cast<
const
char
*
>
(&value);
27
int
hash = 17;
28
for
(
size_t
i = 0; i <
sizeof
(T); ++i) {
29
hash = hash * 31 + p[i];
30
}
31
return
hash;
32
}
33
};
34
35
template
<>
struct
HashHelper
<int> {
static
int
GetHashCode
(
const
int
& value) {
return
value; } };
36
template
<>
struct
HashHelper
<unsigned int> {
static
int
GetHashCode
(
const
unsigned
int
& value) {
return
(
int
)value; } };
37
template
<>
struct
HashHelper
<long long> {
static
int
GetHashCode
(
const
long
long
& value) {
return
(
int
)(value ^ (value >> 32)); } };
38
template
<>
struct
HashHelper
<unsigned long long> {
static
int
GetHashCode
(
const
unsigned
long
long
& value) {
return
(
int
)(value ^ (value >> 32)); } };
39
template
<>
struct
HashHelper
<short> {
static
int
GetHashCode
(
const
short
& value) {
return
value; } };
40
template
<>
struct
HashHelper
<unsigned short> {
static
int
GetHashCode
(
const
unsigned
short
& value) {
return
value; } };
41
template
<>
struct
HashHelper
<char> {
static
int
GetHashCode
(
const
char
& value) {
return
value; } };
42
template
<>
struct
HashHelper
<unsigned char> {
static
int
GetHashCode
(
const
unsigned
char
& value) {
return
value; } };
43
template
<>
struct
HashHelper
<wchar_t> {
static
int
GetHashCode
(
const
wchar_t
& value) {
return
value; } };
44
template
<>
struct
HashHelper
<bool> {
static
int
GetHashCode
(
const
bool
& value) {
return
value ? 1 : 0; } };
45
46
template
<>
struct
HashHelper
<
String
> {
47
static
int
GetHashCode
(
const
String
& value) {
48
return
value.
GetHashCode
();
49
}
50
};
51
52
template
<
typename
T>
53
struct
HashHelper
<
SmartPointer
<T>> {
54
static
int
GetHashCode
(
const
SmartPointer<T>
& value) {
55
if
(value.
IsNull
())
return
0;
56
return
value->GetHashCode();
57
}
58
};
59
60
template
<
typename
T>
61
struct
HashHelper
<T*> {
62
static
int
GetHashCode
(T*
const
& value) {
63
if
(!value)
return
0;
64
unsigned
long
long
ptr =
reinterpret_cast<
unsigned
long
long
>
(value);
65
return
(
int
)(ptr ^ (ptr >> 32));
66
}
67
};
68
69
}
70
}
Common.h
Defines common cross-platform macros, export decorators, and fundamental types.
Object.h
Base object class for DotNetDupe mirroring .NET System.Object.
SmartPointer.h
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
String.h
High-performance UTF-8 / UTF-16 string manipulation class mirroring .NET System.String.
DotNetDupe::System::SmartPointer
A unified smart pointer that supports both unique and shared ownership semantics.
Definition
SmartPointer.h:72
DotNetDupe::System::SmartPointer::IsNull
bool IsNull() const noexcept
Checks if the SmartPointer is null.
Definition
SmartPointer.h:393
DotNetDupe::System::String
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition
String.h:74
DotNetDupe::System::String::GetHashCode
int GetHashCode() const
Definition
String.cpp:236
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
DotNetDupe::System::HashHelper< SmartPointer< T > >::GetHashCode
static int GetHashCode(const SmartPointer< T > &value)
Definition
HashHelper.h:54
DotNetDupe::System::HashHelper< String >::GetHashCode
static int GetHashCode(const String &value)
Definition
HashHelper.h:47
DotNetDupe::System::HashHelper< T * >::GetHashCode
static int GetHashCode(T *const &value)
Definition
HashHelper.h:62
DotNetDupe::System::HashHelper< bool >::GetHashCode
static int GetHashCode(const bool &value)
Definition
HashHelper.h:44
DotNetDupe::System::HashHelper< char >::GetHashCode
static int GetHashCode(const char &value)
Definition
HashHelper.h:41
DotNetDupe::System::HashHelper< int >::GetHashCode
static int GetHashCode(const int &value)
Definition
HashHelper.h:35
DotNetDupe::System::HashHelper< long long >::GetHashCode
static int GetHashCode(const long long &value)
Definition
HashHelper.h:37
DotNetDupe::System::HashHelper< short >::GetHashCode
static int GetHashCode(const short &value)
Definition
HashHelper.h:39
DotNetDupe::System::HashHelper< unsigned char >::GetHashCode
static int GetHashCode(const unsigned char &value)
Definition
HashHelper.h:42
DotNetDupe::System::HashHelper< unsigned int >::GetHashCode
static int GetHashCode(const unsigned int &value)
Definition
HashHelper.h:36
DotNetDupe::System::HashHelper< unsigned long long >::GetHashCode
static int GetHashCode(const unsigned long long &value)
Definition
HashHelper.h:38
DotNetDupe::System::HashHelper< unsigned short >::GetHashCode
static int GetHashCode(const unsigned short &value)
Definition
HashHelper.h:40
DotNetDupe::System::HashHelper< wchar_t >::GetHashCode
static int GetHashCode(const wchar_t &value)
Definition
HashHelper.h:43
DotNetDupe::System::HashHelper
Primary template for generating 32-bit hash codes from arbitrary types using byte-level folding.
Definition
HashHelper.h:21
DotNetDupe::System::HashHelper::GetHashCode
static int GetHashCode(const T &value)
Computes a 32-bit hash code for the specified value.
Definition
HashHelper.h:25
Include
System
HashHelper.h
Generated by
1.18.0