Table of Contents

Class HashCode

Namespace
iText.IO.Util
Assembly
itext.io.dll

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 . If you need order independent hash code just summate, multiply or XOR all elements.

Suppose we have class:

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

int

Methods

Append(bool)

Appends value's hashCode to the current hashCode.

public HashCode Append(bool value)

Parameters

value bool

new element

Returns

HashCode

this

Append(double)

Appends value's hashCode to the current hashCode.

public HashCode Append(double value)

Parameters

value double

new element

Returns

HashCode

this

Append(int)

Appends value's hashCode to the current hashCode.

public HashCode Append(int value)

Parameters

value int

new element

Returns

HashCode

this

Append(long)

Appends value's hashCode to the current hashCode.

public HashCode Append(long value)

Parameters

value long

new element

Returns

HashCode

this

Append(object)

Appends value's hashCode to the current hashCode.

public HashCode Append(object value)

Parameters

value object

new element

Returns

HashCode

this

Append(float)

Appends value's hashCode to the current hashCode.

public HashCode Append(float value)

Parameters

value float

new 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

hashCode int

previous hashCode value

value bool

new element

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

hashCode int

previous hashCode value

value double

new element

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

hashCode int

previous hashCode value

value int

new element

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

hashCode int

previous hashCode value

value long

new element

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

hashCode int

previous hashCode value

value object

new element

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

hashCode int

previous hashCode value

value float

new element

Returns

int

combined hashCode

GetHashCode()

Returns accumulated hashCode

public override sealed int GetHashCode()

Returns

int