MediaWiki  REL1_22
ArrayUtils Class Reference

List of all members.

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.

Detailed Description

Definition at line 3 of file ArrayUtils.php.


Member Function Documentation

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.

Parameters:
$arrayThe array to sort
$keyThe string key
$separatorA 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.

References $hashes, $key, array(), and as.

static ArrayUtils::pickRandom ( weights) [static]

Given an array of non-normalised probabilities, this function will select an element and return the appropriate key.

Parameters:
$weightsarray
Returns:
bool|int|string

Definition at line 42 of file ArrayUtils.php.

References as.


The documentation for this class was generated from the following file: