MediaWiki
REL1_22
|
Static Public Member Functions | |
static | consistentHashSort (&$array, $key, $separator="\000") |
Sort the given array in a pseudo-random order which depends only on the given key and each element value. | |
static | pickRandom ($weights) |
Given an array of non-normalised probabilities, this function will select an element and return the appropriate key. |
Definition at line 3 of file ArrayUtils.php.
static ArrayUtils::consistentHashSort | ( | &$ | array, |
$ | key, | ||
$ | separator = "\000" |
||
) | [static] |
Sort the given array in a pseudo-random order which depends only on the given key and each element value.
This is typically used for load balancing between servers each with a local cache.
Keys are preserved. The input array is modified in place.
Note: Benchmarking on PHP 5.3 and 5.4 indicates that for small strings, md5() is only 10% slower than hash('joaat',...) etc., since the function call overhead dominates. So there's not much justification for breaking compatibility with installations compiled with ./configure --disable-hash.
$array | The array to sort |
$key | The string key |
$separator | A separator used to delimit the array elements and the key. This can be chosen to provide backwards compatibility with various consistent hash implementations that existed before this function was introduced. |
Definition at line 24 of file ArrayUtils.php.
static ArrayUtils::pickRandom | ( | $ | weights | ) | [static] |
Given an array of non-normalised probabilities, this function will select an element and return the appropriate key.
$weights | array |
Definition at line 42 of file ArrayUtils.php.
References as.