public function hash() { $hasher = hash_init('sha256'); hash_update($hasher, $this->kind()); hash_update($hasher, $this->name); hash_update($hasher, hashComplex($this->t_args)); return hash_final($hasher); }
public function hash() { if ($this->hash === null) { $hasher = hash_init('sha256'); hash_update($hasher, $this->name); hash_update($hasher, '('); hash_update($hasher, hashComplex($this->args)); hash_update($hasher, ')'); $this->hash = hash_final($hasher); } return $this->hash; }
function hashComplex($val) { $hasher = hash_init('sha256'); if (is_array($val)) { hash_update($hasher, '['); // Ensure array is sorted by keys ksort($val); foreach ($val as $name => $v) { hash_update($hasher, $name); hash_update($hasher, '=>'); hash_update($hasher, hashComplex($v)); } hash_update($hasher, ']'); } else { if (is_gla($val)) { hash_update($hasher, 'gla'); hash_update($hasher, $val->hash()); } else { if (is_gf($val)) { hash_update($hasher, 'gf'); hash_update($hasher, $val->hash()); } else { if (is_gt($val)) { hash_update($hasher, 'gt'); hash_update($hasher, $val->hash()); } else { if (is_gist($val)) { hash_update($hasher, 'gist'); hash_update($hasher, $val->hash()); } else { if (is_gi($val)) { hash_update($hasher, 'gi'); hash_update($hasher, $val->hash()); } else { if (is_datatype($val)) { hash_update($hasher, 'datatype'); hash_update($hasher, $val->hash()); } else { if (is_functor($val)) { hash_update($hasher, 'functor'); hash_update($hasher, $val->hash()); } else { if (is_identifier($val)) { hash_update($hasher, 'identifier'); hash_update($hasher, $val->hash()); } else { if (is_attribute($val)) { hash_update($hasher, 'attribute'); hash_update($hasher, strval($val)); } else { if (is_int($val) || is_float($val) || is_string($val) || is_bool($val)) { hash_update($hasher, gettype($val)); hash_update($hasher, $val); } else { if (is_null($val)) { hash_update($hasher, 'null'); } else { $valType = is_object($val) ? get_class($val) : gettype($val); grokit_logic_error('Unable to hash unknown type ' . $valType); } } } } } } } } } } } } return hash_final($hasher); }
public static function HashFunctionSignature($name, array $args, array $targs = []) { $hasher = hash_init('sha256'); hash_update($hasher, \strtoupper($name)); // Hash arguments hash_update($hasher, '('); foreach ($args as $n => $type) { hash_update($hasher, $n); hash_update($hasher, $type->hash()); } hash_update($hasher, ')'); // If there are any template arguments, hash them too. if (count($targs) > 0) { hash_update($hasher, '<'); hash_update($hasher, hashComplex($targs)); hash_update($hasher, '>'); } return hash_final($hasher); }