/rxwandc/application/ad.rxwan.com/classes/model/stringhash.php
PHP | 32 lines | 23 code | 9 blank | 0 comment | 1 complexity | b86bd6d5b1169e9e00acf7873f606ebc MD5 | raw file
Possible License(s): BSD-3-Clause
- <?php
- defined('SYSPATH') or die('No direct script access.');
- class Model_Stringhash extends Model{
- public function getHashValue($str) {
- $bytes = $this->stringToByteArray($str);
- return array_reduce($bytes, array($this, 'hash'));
- }
- public function hash($p, $v) {
- return (($p << 5) - $p) + $v;
- }
- public function stringToByteArray($str) {
- preg_match_all('/(.)/s', $str, $bytes);
- $bytes=array_map(array($this, 'toByte'), $bytes[1]);
- return $bytes;
- }
- public function toByte($input) {
- $num = ord($input);
- if($num > 0x7F) {
- return 0 - (~($num - 1) & 0x7F);
- }
- return $num;
- }
-
- }