/**
* @throws MWException
- * @param $collationName string
+ * @param string $collationName
* @return Collation
*/
static function factory( $collationName ) {
$sortKey = $this->getPrimarySortKey( $string );
// Do a binary search to find the correct letter to sort under
- $min = $this->findLowerBound(
+ $min = ArrayUtils::findLowerBound(
array( $this, 'getSortKeyByLetterIndex' ),
$this->getFirstLetterCount(),
'strcmp',
$prev = $trimmedKey;
}
foreach ( $duplicatePrefixes as $badKey ) {
- wfDebug( "Removing '{$letterMap[$badKey]}' from first letters." );
+ wfDebug( "Removing '{$letterMap[$badKey]}' from first letters.\n" );
unset( $letterMap[$badKey] );
// This code assumes that unsetting does not change sort order.
}
* Do a binary search, and return the index of the largest item that sorts
* less than or equal to the target value.
*
+ * @deprecated since 1.23; use ArrayUtils::findLowerBound() instead
+ *
* @param array $valueCallback A function to call to get the value with
* a given array index.
* @param int $valueCount The number of items accessible via $valueCallback,
* sorts before all items.
*/
function findLowerBound( $valueCallback, $valueCount, $comparisonCallback, $target ) {
- if ( $valueCount === 0 ) {
- return false;
- }
-
- $min = 0;
- $max = $valueCount;
- do {
- $mid = $min + ( ( $max - $min ) >> 1 );
- $item = call_user_func( $valueCallback, $mid );
- $comparison = call_user_func( $comparisonCallback, $target, $item );
- if ( $comparison > 0 ) {
- $min = $mid;
- } elseif ( $comparison == 0 ) {
- $min = $mid;
- break;
- } else {
- $max = $mid;
- }
- } while ( $min < $max - 1 );
-
- if ( $min == 0 ) {
- $item = call_user_func( $valueCallback, $min );
- $comparison = call_user_func( $comparisonCallback, $target, $item );
- if ( $comparison < 0 ) {
- // Before the first item
- return false;
- }
- }
- return $min;
+ wfDeprecated( __METHOD__, '1.23' );
+ return ArrayUtils::findLowerBound( $valueCallback, $valueCount, $comparisonCallback, $target );
}
static function isCjk( $codepoint ) {