Class HashCode
This class is a convenience method to sequentially calculate hash code of the object based on the field values.
public sealed class HashCode
- Inheritance
-
HashCode
- Inherited Members
Remarks
This class is a convenience method to sequentially calculate hash code of the
object based on the field values. The result depends on the order of elements
appended. The exact formula is the same as for
class Thing {
long id;
String name;
float weight;
}
The hash code calculation can be expressed in 2 forms.
For maximum performance:
public int hashCode() {
int hashCode = HashCode.EMPTY_HASH_CODE;
hashCode = HashCode.combine(hashCode, id);
hashCode = HashCode.combine(hashCode, name);
hashCode = HashCode.combine(hashCode, weight);
return hashCode;
}
For convenience:
public int hashCode() {
return new HashCode().append(id).append(name).append(weight).hashCode();
}
Constructors
HashCode()
public HashCode()
Fields
EMPTY_HASH_CODE
The hashCode value before any data is appended, equals to 1.
public const int EMPTY_HASH_CODE = 1
Field Value
Methods
Append(bool)
Appends value's hashCode to the current hashCode.
public HashCode Append(bool value)
Parameters
value
boolnew element
Returns
- HashCode
this
Append(double)
Appends value's hashCode to the current hashCode.
public HashCode Append(double value)
Parameters
value
doublenew element
Returns
- HashCode
this
Append(int)
Appends value's hashCode to the current hashCode.
public HashCode Append(int value)
Parameters
value
intnew element
Returns
- HashCode
this
Append(long)
Appends value's hashCode to the current hashCode.
public HashCode Append(long value)
Parameters
value
longnew element
Returns
- HashCode
this
Append(object)
Appends value's hashCode to the current hashCode.
public HashCode Append(object value)
Parameters
value
objectnew element
Returns
- HashCode
this
Append(float)
Appends value's hashCode to the current hashCode.
public HashCode Append(float value)
Parameters
value
floatnew element
Returns
- HashCode
this
Combine(int, bool)
Combines hashCode of previous elements sequence and value's hashCode.
public static int Combine(int hashCode, bool value)
Parameters
Returns
- int
combined hashCode
Combine(int, double)
Combines hashCode of previous elements sequence and value's hashCode.
public static int Combine(int hashCode, double value)
Parameters
Returns
- int
combined hashCode
Combine(int, int)
Combines hashCode of previous elements sequence and value's hashCode.
public static int Combine(int hashCode, int value)
Parameters
Returns
- int
combined hashCode
Combine(int, long)
Combines hashCode of previous elements sequence and value's hashCode.
public static int Combine(int hashCode, long value)
Parameters
Returns
- int
combined hashCode
Combine(int, object)
Combines hashCode of previous elements sequence and value's hashCode.
public static int Combine(int hashCode, object value)
Parameters
Returns
- int
combined hashCode
Combine(int, float)
Combines hashCode of previous elements sequence and value's hashCode.
public static int Combine(int hashCode, float value)
Parameters
Returns
- int
combined hashCode
GetHashCode()
Returns accumulated hashCode
public override sealed int GetHashCode()