Top Description Fields Constructors Methods
org.wildfly.common.math

public final Class HashMath

extends Object
Class Inheritance
Imports
org.wildfly.common.Assert

Routines which are useful for hashcode computation, among other things.
Author
David M. Lloyd

Field Summary

Modifier and TypeField and Description
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

the new accumulated hash code
multiHashOrdered
(int
the accumulated hash code of the previous stage
accumulatedHash
,
int
a prime multiplier
prime
,
int
the hash code of the next single item
nextHash
)

A hash function which combines an accumulated hash with a next hash such that f(f(k, p2, b), p1, a) ≠ₙ f(f(k, p1, a), p2, b).

public static int

Returns:

the new accumulated hash code
multiHashOrdered
(int
the accumulated hash code of the previous stage
accumulatedHash
,
int
the hash code of the next single item
nextHash
)

A hash function which combines an accumulated hash with a next hash such that f(f(k, b), a) ≠ₙ f(f(k, a), b).

public static int

Returns:

the new accumulated hash code
multiHashUnordered
(int
the accumulated hash code of the previous stage
accumulatedHash
,
int
a prime multiplier
prime
,
int
the hash code of the next single item
nextHash
)

A hash function which combines an accumulated hash with a next hash such that f(f(k, p2, b), p1, a) = f(f(k, p1, a), p2, b).

public static int

Returns:

the new accumulated hash code
multiHashUnordered
(int
the accumulated hash code of the previous stage
accumulatedHash
,
int
the hash code of the next single item
nextHash
)

A hash function which combines an accumulated hash with a next hash such that f(f(k, b), a) = f(f(k, a), b).

public static int

Returns:

the wrapped multiply result
multiplyWrap
(int
the first number to multiply
a
,
int
the second number to multiply
b
)

Multiply two unsigned integers together.

public static int

Returns:

the rounded power of two value
roundToPowerOfTwo
(int
the value (must not be negative and must be less than or equal to 2^31)
value
)

Round the given value up to the next positive power of two.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

PRESELECTED_PRIMEback to summary
private static final int PRESELECTED_PRIME

Constructor Detail

HashMathback to summary
private HashMath()

Method Detail

multiHashOrderedback to summary
public static int multiHashOrdered(int accumulatedHash, int prime, int nextHash)

A hash function which combines an accumulated hash with a next hash such that f(f(k, p2, b), p1, a) ≠ₙ f(f(k, p1, a), p2, b). This function is suitable for object chains whose order affects the overall equality of the hash code.

The exact algorithm is not specified and is therefore subject to change and should not be relied upon for hash codes that persist outside of the JVM process.

Parameters
accumulatedHash:int

the accumulated hash code of the previous stage

prime:int

a prime multiplier

nextHash:int

the hash code of the next single item

Returns:int

the new accumulated hash code

multiHashOrderedback to summary
public static int multiHashOrdered(int accumulatedHash, int nextHash)

A hash function which combines an accumulated hash with a next hash such that f(f(k, b), a) ≠ₙ f(f(k, a), b). This function is suitable for object chains whose order affects the overall equality of the hash code.

The exact algorithm is not specified and is therefore subject to change and should not be relied upon for hash codes that persist outside of the JVM process.

Parameters
accumulatedHash:int

the accumulated hash code of the previous stage

nextHash:int

the hash code of the next single item

Returns:int

the new accumulated hash code

multiHashUnorderedback to summary
public static int multiHashUnordered(int accumulatedHash, int prime, int nextHash)

A hash function which combines an accumulated hash with a next hash such that f(f(k, p2, b), p1, a) = f(f(k, p1, a), p2, b). This function is suitable for object chains whose order does not affect the overall equality of the hash code.

The exact algorithm is not specified and is therefore subject to change and should not be relied upon for hash codes that persist outside of the JVM process.

Parameters
accumulatedHash:int

the accumulated hash code of the previous stage

prime:int

a prime multiplier

nextHash:int

the hash code of the next single item

Returns:int

the new accumulated hash code

multiHashUnorderedback to summary
public static int multiHashUnordered(int accumulatedHash, int nextHash)

A hash function which combines an accumulated hash with a next hash such that f(f(k, b), a) = f(f(k, a), b). This function is suitable for object chains whose order does not affect the overall equality of the hash code.

The exact algorithm is not specified and is therefore subject to change and should not be relied upon for hash codes that persist outside of the JVM process.

Parameters
accumulatedHash:int

the accumulated hash code of the previous stage

nextHash:int

the hash code of the next single item

Returns:int

the new accumulated hash code

multiplyWrapback to summary
public static int multiplyWrap(int a, int b)

Multiply two unsigned integers together. If the result overflows a 32-bit number, XOR the overflowed bits back into the result. This operation is commutative, i.e. if we designate the ⨰ symbol to represent this operation, then a ⨰ b = b ⨰ a. This operation is not associative, i.e. (a ⨰ b) ⨰ c ≠ₙ a ⨰ (b ⨰ c) (the symbol ≠ₙ meaning "not necessarily equal to"), therefore this operation is suitable for ordered combinatorial hash functions.

Parameters
a:int

the first number to multiply

b:int

the second number to multiply

Returns:int

the wrapped multiply result

roundToPowerOfTwoback to summary
public static int roundToPowerOfTwo(int value)

Round the given value up to the next positive power of two.

Parameters
value:int

the value (must not be negative and must be less than or equal to 2^31)

Returns:int

the rounded power of two value