Quote:
Originally Posted by Gammix
getIndex
This function locates indexes using simple hash algorithm instead of looping through an entire array. This is good way to locate indexes quickly(faster than looping and strcmp) but indexes can be located anywhere from 0 to size.
Say if i want to put "abc" and "tat" in my array of size 50.
PHP код:
"abc" - placed at 33
"tat" - placed at 24
// code
new array[50][64];
printf("abc = %i", getIndex(array, "abc"));
printf("tat = %i", getIndex(array, "tat"));
Source
PHP код:
stock getIndex(array[][], const value[], size = sizeof array)
{
new index;
for (new i = 0, j = strlen(value); i < j; i++)
{
index += value[i] + index;
}
index %= size;
return index;
}
|
pretty sure that you didn't run much tests on that code. It will not work as you expecting to.Might give correct result on small strings. Just view the assembly of that code and you will understand why.