PHP version: 5
Required modules:
standard, spl, simplexml, dom
Required packages:
all.php, errors.php, autoload.php, AutoloadException.php, cast.php, Types.php, ArrayBothType.php, TypeInterface.php, Printable.php, ArrayIntType.php, ArrayStringType.php, BooleanType.php, ClassType.php, FloatType.php, IntType.php, NullType.php, ObjectType.php, ResourceType.php, StringType.php, CastException.php, Hashable.php, Comparable.php
class it\icosaedro\containers\Hash
Hashing functions
Version: $Date: 2012/04/02 09:11:36 $
Author: Umberto Salsi <salsi@icosaedro.it>
For every type T on which one may want to calculate an hash, a function named hashOfT() is provided. Classes that implement the
it\icosaedro\containers\Hashableinterface may then easily implement the getHash() method by "xoring" the properties that univocally identify the object:class MyClass implements Hashable { function getHash() { return Hash::hashOfInt($this->int_property) ^ Hash::hashOfString($this->string_property) ^ $this->hashable_object_propery->getHash(); } }Note that the same properties should appear in the implementation of the equals() method.
{
static int hashOfBoolean(
boolean $b)Hash of a boolean value
Parameters:
$bThe value. Return: Hash of the value. Implementation note: merely returns 1 if true, 0 if false, so you may want to save time simply avoiding to call this function at all :-)
static int hashOfInt(
int $i)Hash of an integer value
Parameters:
$iThe value. Return: Hash of the value. Implementation note: merely returns the value itself, so you may want to save time simply avoiding to call this function at all :-)
static int hashOfString(
string $s)Hash of a string value
Parameters:
$sThe value. Return: Hash of the value, or zero if NULL. Implementation note: if the string is not NULL, returns the CRC32 of its bytes.
static int hashOfObject(
object $obj)Hash of an object
Parameters:
$objThe value. Return: If the object implements the
it\icosaedro\containers\Hashable::getHash()method, then returns the value from that method. Otherwise, returns the CRC32 of the has given by thespl_object_hash()function.static int hashOf(
mixed $x)Returns the hash of the expression passed, typically a key
The value is calculated applying the methods hashOfT() of this class according to the actual type of the value.
Parameters:
$xAny value of type null, boolean, int, string or object. Types float, array and resource are not supported and give exception. Return: The hash of the value.
Throws:
- unchecked
RuntimeExceptionType not supported float, array or resource.
}
Generated by PHPLint Documentator