note 52817 added to function.crc32
| From: | Johan at osu1 dot php dot net | Date: | Fri, 13 May 2005 10:12:46 +0000 |
| Subject: | note 52817 added to function.crc32 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89372@lists.php.net to get a copy of this message | ||
Here is a php version of the Java String hashCode:
( produced for: http://openmusic.op.funpic.org/catalog/ )
/**
* Calculate hash code for a string computed as
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* Equal to java.lang.String.hashCode()
*
* Returns an integer.
*/
function toID($link) {
$link = (string)$link;
$len = strLen($link);
$sum = 0;
for ($i = 0; $i < $len; $i++) {
$sum = (int)(31 * $sum + getASCIICode($link[$i]));
// echo($sum . "<br>");
}
return ((int)$sum);
}
// get char as int, - see example codes at intval on the subject.
function getASCIICode($caracter) {
// ...
}
----
Manual Page -- http://www.php.net/manual/en/function.crc32.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52817
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52817&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52817&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52817&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52817&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52817&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52817&report=yes
Search -- http://master.php.net/manage/user-notes.php