Remove `binarySearchWith()`. Fix bug for `binarySearchBy()`.

This commit is contained in:
CismonX 2018-09-12 14:39:18 +08:00
parent 4eba5b27b7
commit 3245047186
5 changed files with 2 additions and 31 deletions

View File

@ -122,14 +122,6 @@ ZEND_BEGIN_ARG_INFO(binary_search_by_arginfo, 0)
ZEND_ARG_TYPE_INFO(0, to_index, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(binary_search_with_arginfo, 0)
ZEND_ARG_INFO(0, element)
ZEND_ARG_CALLABLE_INFO(0, comparator, 0)
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, from_index, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, to_index, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(chuncked_arginfo, 0)
ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0)
ZEND_ARG_CALLABLE_INFO(0, transform, 0)
@ -156,7 +148,6 @@ const zend_function_entry collection_methods[] = {
PHP_ME(Collection, average, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Collection, binarySearch, binary_search_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(Collection, binarySearchBy, binary_search_by_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(Collection, binarySearchWith, binary_search_with_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(Collection, chunked, chuncked_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(Collection, containsAll, other_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(Collection, containsAllKeys, other_arginfo, ZEND_ACC_PUBLIC)

View File

@ -987,7 +987,7 @@ PHP_METHOD(Collection, binarySearchBy)
Bucket* end = current->arData + to_idx;
for (; bucket < end; ++bucket) {
CALLBACK_KEYVAL_INVOKE(params, bucket);
memcpy(&ref[idx++].val, &bucket->val, sizeof(zval));
memcpy(&ref[idx++].val, &retval, sizeof(zval));
if (UNEXPECTED(cmp == NULL)) {
cmp = compare_func_init(&retval, 0, flags);
}
@ -1000,11 +1000,6 @@ PHP_METHOD(Collection, binarySearchBy)
free(ref);
}
PHP_METHOD(Collection, binarySearchWith)
{
}
PHP_METHOD(Collection, chunked)
{
zend_long size;

View File

@ -20,7 +20,6 @@ PHP_METHOD(Collection, associateByTo);
PHP_METHOD(Collection, average);
PHP_METHOD(Collection, binarySearch);
PHP_METHOD(Collection, binarySearchBy);
PHP_METHOD(Collection, binarySearchWith);
PHP_METHOD(Collection, chunked);
PHP_METHOD(Collection, containsAll);
PHP_METHOD(Collection, containsAllKeys);

View File

@ -124,21 +124,6 @@ class Collection implements ArrayAccess, Countable
*/
function binarySearchBy($element, $selector, $flags, $from_index, $to_index) {}
/**
* Searches the array or the range of the array for the provided element using the
* binary search algorithm.
*
* The array is expected to be packed and sorted into ascending order according to
* the specified comparator, otherwise the result is undefined.
*
* @param mixed $element
* @param callable $comparator (Pair($key, $value), Pair($key, $value)) -> int
* @param int $from_index[optional]
* @param int $to_index[optional]
* @return int|null
*/
function binarySearchWith($element, $comparator, $from_index, $to_index) {}
/**
* Splits this collection into a collection of arrays each not exceeding the given size.
*

View File

@ -23,6 +23,7 @@ $array = array_map(function ($value) {
$selector = function ($value) {
return $value[0];
};
$collection = Collection::init($array);
if ($collection->binarySearchBy($which, $selector, 0, $from, $to) != $idx) {
echo 'Collection::binarySearchBy() failed.', PHP_EOL;
}