SystemEX  Lacking
Additional generic collection types missing in .net
SystemEx.Hash.Hashable Class Referenceabstract

Public Member Functions

FixedVector< byte > ToBytes ()
 Converts the object into a byte array representation used by hashers. Implementations must return a deterministic and stable encoding.
override int GetHashCode ()
 Computes a 32‑bit hash using the algorithm specified by HashAlgorithmAttribute on the concrete type.
virtual long GetHashCodeLong ()
 Computes a 64‑bit hash using the algorithm specified by HashAlgorithmAttribute on the concrete type.

Properties

ulong Seed [get]
 Gets the random seed assigned to this instance.

Member Function Documentation

◆ GetHashCode()

override int SystemEx.Hash.Hashable.GetHashCode ( )

Computes a 32‑bit hash using the algorithm specified by HashAlgorithmAttribute on the concrete type.

If no attribute is present, base.GetHashCode() is used. The hasher instance is created transiently via reflection.

60 {
61 int _hash = 0;
62
63 // Attribut vom konkreten Typ lesen (nicht typeof(Hashable ))
64 var attr = (HashAlgorithmAttribute?)Attribute.GetCustomAttribute(this.GetType(), typeof(HashAlgorithmAttribute));
65 if ( attr == null ) {
66 _hash = base.GetHashCode();
67 } else {
68 // Bytes erzeugen
69 FixedVector<byte> input = ToBytes();
70
71 // Hasher transient erzeugen: zuerst versuchen, Konstruktor mit Endian, sonst parameterlos
72 object? inst = null;
73 try {
74 inst = Activator.CreateInstance(attr.HasherType, attr.Endian);
75 } catch {
76 try {
77 inst = Activator.CreateInstance(attr.HasherType);
78 } catch {
79 inst = null;
80 }
81 }
82
83 if ( inst is IHash hasher ) {
84 var h = hasher.Compute(input, (uint)m_seed );
85 _hash = (int)h.Value;
86 } else {
87 _hash = base.GetHashCode();
88 }
89 }
90
91 return _hash;
92 }
Here is the call graph for this function:

◆ GetHashCodeLong()

virtual long SystemEx.Hash.Hashable.GetHashCodeLong ( )
virtual

Computes a 64‑bit hash using the algorithm specified by HashAlgorithmAttribute on the concrete type.

If no attribute is present, base.GetHashCode() is used. The hasher instance is created transiently via reflection.

100 {
101 long _hash = 0;
102
103 // Attribut vom konkreten Typ lesen (nicht typeof(Hashable ))
104 var attr = (HashAlgorithmAttribute?)Attribute.GetCustomAttribute(this.GetType(), typeof(HashAlgorithmAttribute));
105 if ( attr == null ) {
106 _hash = base.GetHashCode();
107 } else {
108 // Bytes erzeugen
109 FixedVector<byte> input = ToBytes();
110
111 // Hasher transient erzeugen: zuerst versuchen, Konstruktor mit Endian, sonst parameterlos
112 object? inst = null;
113 try {
114 inst = Activator.CreateInstance(attr.HasherType, attr.Endian);
115 } catch {
116 try {
117 inst = Activator.CreateInstance(attr.HasherType);
118 } catch {
119 inst = null;
120 }
121 }
122
123 if ( inst is IHash hasher ) {
124 var h = hasher.ComputeLong(input, m_seed );
125 _hash = (long)h.Value;
126 } else {
127 _hash = base.GetHashCode();
128 }
129 }
130
131 return _hash;
132 }
Here is the call graph for this function:

◆ ToBytes()

FixedVector< byte > SystemEx.Hash.Hashable.ToBytes ( )
abstract

Converts the object into a byte array representation used by hashers. Implementations must return a deterministic and stable encoding.

Here is the caller graph for this function:

Property Documentation

◆ Seed

ulong SystemEx.Hash.Hashable.Seed
get

Gets the random seed assigned to this instance.

51{ get => m_seed; }

The documentation for this class was generated from the following file:
  • Hashable.cs