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;
}
|
Really nice and useful function but it is failing on multiple possibilities and on invalid checking (if the result is not in the array).