diff options
author | Liangent <liangent@gmail.com> | 2012-10-18 09:33:15 +0000 |
---|---|---|
committer | Reedy <reedy@wikimedia.org> | 2014-01-23 22:13:22 +0000 |
commit | 84a2f570b8cde63b62d8e5758dc9138e194f4adb (patch) | |
tree | c52d9c6b5af2bacb852bad5c57ae440ec69861fb /includes/Collation.php | |
parent | b06d5ed07887b8c1f294ce78abb022c74116d53c (diff) | |
download | mediawikicore-84a2f570b8cde63b62d8e5758dc9138e194f4adb.tar.gz mediawikicore-84a2f570b8cde63b62d8e5758dc9138e194f4adb.zip |
Create and move some functions for class ArrayUtils
Change-Id: Id9ca20925f49e314918810fb54b3819ba9cf9c39
Diffstat (limited to 'includes/Collation.php')
-rw-r--r-- | includes/Collation.php | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/includes/Collation.php b/includes/Collation.php index 7204f3129dfb..b51256b281e7 100644 --- a/includes/Collation.php +++ b/includes/Collation.php @@ -333,7 +333,7 @@ class IcuCollation extends Collation { $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', @@ -514,6 +514,8 @@ class IcuCollation extends Collation { * Do a binary search, and return the index of the largest item that sorts * less than or equal to the target value. * + * @deprecated in 1.22; 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, @@ -526,35 +528,8 @@ class IcuCollation extends Collation { * 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.22' ); + return ArrayUtils::findLowerBound( $valueCallback, $valueCount, $comparisonCallback, $target ); } static function isCjk( $codepoint ) { |