Provides an external means for producing hash codes and comparing values for
identity.
This equivalence relation uses the strict equal operator (===
) to compare
values, while hashing strategy varies according to the type of value.
Methods summary
public
boolean
|
#
equals( PhpCommon\Comparison\Equatable $other )
Checks whether the current relation is considered equal to another.
Checks whether the current relation is considered equal to another.
Since this class is stateless, its instances will always be considered
equal if they are of the same type.
Parameters
- $other
- The value to compare to.
Returns
boolean Returns true if the current object is equal to the
specified object, false otherwise.
|
protected
boolean
|
#
equivalentArray( array $left, mixed $right )
Checks whether an array is equivalent to another value.
Checks whether an array is equivalent to another value.
The specified values are considered equivalent if and only if the
right-hand value is also an array and they both contain the same
number of entries, in the same order and each pair of corresponding
entries is equivalent according to this relation. Empty arrays are
equivalent to one another.
Parameters
- $left
- The array to compare.
- $right
- The other value to compare.
Returns
boolean Returns true if the given values are considered
equivalent, false otherwise.
|
protected
boolean
|
#
equivalentBoolean( boolean $left, mixed $right )
Checks whether a boolean value is equivalent to another value.
Checks whether a boolean value is equivalent to another value.
The specified values are considered equivalent if and only if the
right-hand value is also a boolean and both are true or both are
false .
Parameters
- $left
- The boolean value to compare.
- $right
- The other value to compare.
Returns
boolean Returns true if the given values are considered
equivalent, false otherwise.
|
protected
boolean
|
#
equivalentFloat( float $left, mixed $right )
Checks whether a floating-point number is equivalent to another value.
Checks whether a floating-point number is equivalent to another value.
The specified values are considered equivalent if and only if the
right-hand value is also a float and they are numerically equal
(have the same number value). Positive and negative zeros are equal
to one another. NAN is not equal to anything, including
NAN.
Parameters
- $left
- The floating-point number to compare.
- $right
- The other value to compare.
Returns
boolean Returns true if the given values are considered
equivalent, false otherwise.
|
protected
boolean
|
#
equivalentInteger( integer $left, mixed $right )
Checks whether an integer number is equivalent to another value.
Checks whether an integer number is equivalent to another value.
The specified values are considered equivalent if and only if the
right-hand value is also an integer and they are numerically equal
(have the same number value). Positive and negative zeros are equal
to one another.
Parameters
- $left
- The integer number to compare.
- $right
- The other value to compare.
Returns
boolean Returns true if the given values are considered
equivalent, false otherwise.
|
protected
boolean
|
#
equivalentNull( mixed $right )
Checks whether value is equivalent to null.
Checks whether value is equivalent to null.
The specified value is considered equivalent to null if and only if it
is strictly equal to null .
Parameters
- $right
- The value to compare.
Returns
boolean Returns true if the given value is considered
equivalent to null, false otherwise.
|
protected
boolean
|
#
equivalentObject( object $left, mixed $right )
Checks whether an object is equivalent to another value.
Checks whether an object is equivalent to another value.
The specified values are considered equivalent if and only if the
right-hand value is also an object and both are references to the
same instance.
Parameters
- $left
- The object to compare.
- $right
- The other value to compare.
Returns
boolean Returns true if the given values are considered
equivalent, false otherwise.
|
protected
boolean
|
#
equivalentResource( resource $left, mixed $right )
Checks whether a resource is equivalent to another value.
Checks whether a resource is equivalent to another value.
The specified values are considered equivalent if and only if the
right-hand value is also a resource and both have the same unique
resource number.
Parameters
- $left
- The resource to compare.
- $right
- The other value to compare.
Returns
boolean Returns true if the given values are considered
equivalent, false otherwise.
|
protected
boolean
|
#
equivalentString( string $left, mixed $right )
Checks whether a string is equivalent to another value.
Checks whether a string is equivalent to another value.
The specified values are considered equivalent if and only if the
right-hand value is also a string and both have the same sequence of
characters.
Parameters
- $left
- The string value to compare.
- $right
- The other value to compare.
Returns
boolean Returns true if the given values are considered
equivalent, false otherwise.
|
protected
integer
|
#
hashArray( array $value )
Returns a hash code for the given array.
Returns a hash code for the given array.
The hash code is based on the deep contents of the specified array.
More precisely, it is computed as follows:
$hashCode = IdentityEquivalence::HASH_ARRAY;
foreach ($array => $key => $element) $hashCode = 31 * $hashCode + (hash($key) ^ hash($element));
Where hash() is a function that returns a hash code for a given value.
Note that the hash code of an empty array is the constant
IdentityEquivalence::HASH_ARRAY itself.
Parameters
- $value
- The array to hash.
Returns
integer The hash code for the given array.
|
protected
integer
|
#
hashBoolean( boolean $value )
Returns a hash code for the given boolean value.
Returns a hash code for the given boolean value.
It is defined by mapping the values true and false to
integer numbers defined by IdentityEquivalence::HASH_TRUE and
IdentityEquivalence::HASH_FALSE respectively.
Parameters
- $value
- The boolean value to hash.
Returns
integer The hash code for the given boolean value.
|
protected
integer
|
#
hashFloat( float $value )
Returns a hash code for the given floating-point number.
Returns a hash code for the given floating-point number.
It is computed by converting the float value to the integer bit
representation, according to the IEEE 754 floating-point single format
bit layout.
Parameters
- $value
- The floating-point number to hash.
Returns
integer The hash code for the given floating-point number.
Link
|
protected
integer
|
#
hashInteger( integer $value )
Returns a hash code for the given integer number.
Returns a hash code for the given integer number.
This method uses the integer number as the hash code itself.
Parameters
- $value
- The integer number to hash.
Returns
integer The hash code for the given integer number.
|
protected
integer
|
#
hashNull( )
Returns a hash code for the null value.
Returns a hash code for the null value.
The hash code for null is a constant defined by
IdentityEquivalence::HASH_NULL.
Returns
integer The hash code for the NULL value.
|
protected
integer
|
#
hashObject( object $value )
Returns a hash code for the given object.
Returns a hash code for the given object.
The hash code is computed as follows:
$k = IdentityEquivalence::HASH_OBJECT;
$hashCode = $k * hashString(spl_object_hash($object));
Where IdentityEquivalence::HASH_OBJECT is a constant and
hashString() is a function that returns a hash code for a given
string.
Parameters
- $value
- The object to hash.
Returns
integer The hash code for the given object.
|
protected
integer
|
#
hashString( string $value )
Returns a hash code for the given string value.
Returns a hash code for the given string value.
The hash code is computed as follows:
$hashCode = IdentityEquivalence::HASH_STRING;
for ($i = 0; $i < length($string); $i++) $hashCode = $hashCode * 31 + charCode($string[$i]);
Where IdentityEquivalence::HASH_STRING is a constant, $i is
the position of the current character in the string, $string[$i] is
the ith character of the string, length() is a function that returns
the length of the string, charCode() is a function that returns the
ASCII code (as an integer) of a given character, and ^ indicates
exponentiation. Note that the hash code of a zero length string is the
constant IdentityEquivalence::HASH_STRING itself.
Parameters
- $value
- The string value to hash.
Returns
integer The hash code for the given object.
|
protected
integer
|
#
hashResource( resource $value )
Returns a hash code for the given resource.
Returns a hash code for the given resource.
The hash code is computed as follows:
$k = IdentityEquivalence::HASH_RESOURCE;
$hashCode = $k * (1 + resourceId($value));
Where $k is a constant defined by
IdentityEquivalence::HASH_RESOURCE and resourceId() is a
function that returns the unique resource number assigned to the
resource by PHP at runtime.
Parameters
- $value
- The resource to hash.
Returns
integer The hash code for the given resource.
|