PersistentStringHash Structure

Combines the hash code for multiple character based values into a single persistent hash code.

Definition

Namespace: FolkerKinzel.Strings
Assembly: FolkerKinzel.Strings (in FolkerKinzel.Strings.dll) Version: 9.4.0+10a7d4d71aa960998e32ac0ac6c4fcbe4164c917
C#
public struct PersistentStringHash
Inheritance
Object    ValueType    PersistentStringHash

Remarks

  Important

Keep in mind that this is a value type. Don't forget the ref keyword when passing instances to other methods!

  Caution

Never use the default constructor!

The method String.GetHashCode() returns a different hash code for an identical string with each program run for security reasons. Apart from the fact that the hash algorithm of String.GetHashCode() could be different in different framework versions, it makes no sense to use the return value of GetHashCode for reuse. The alternatives, e.g. MD5 or SHA256, use more storage space and are slower. This struct offers a slim alternative that is suitable for hashing very short strings that are not used in a security-critical context.

The hashcode generated by this method is not identical to the hashcode generated by the .NET Framework 4.0, because it uses roundshifting to preserve more information.

The hashcodes generated with different values for hashType may provide different hashcodes for an identical Char sequence and MUST therefore not be mixed.

Do not use the hashcodes generated by this method for security-critical purposes (such as hashing passwords)!

Constructors

PersistentStringHash Combines the hash code for multiple character based values into a single persistent hash code.

Properties

HashType The type of hash code this instance computes.

Methods

Add(Char) Adds a single character to the hash code.
Add(ReadOnlySpanChar) Adds the content of a read-only character span to the hash code.
Add(StringBuilder) Adds the content of a StringBuilder to the hash code.
Add(StringBuilder, Int32) Adds a sequence of characters from the content of a StringBuilder to the hash code that begins with startIndex and reaches to the end of builder.
Add(StringBuilder, Int32, Int32) Adds a sequence of characters from the content of a StringBuilder to the hash code that begins with startIndex and contains count characters.
GetTypeGets the Type of the current instance.
(Inherited from Object)
ToHashCode Calculates the final hash code after consecutive Add invocations.
ToStringReturns the fully qualified type name of this instance.
(Inherited from ValueType)

Exceptions

See Also