11.05.2017, 14:17
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.
Source
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"));
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;
}