Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11436 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4788 invoked by uid 1010); 21 Jul 2004 17:11:29 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 3577 invoked from network); 21 Jul 2004 17:11:14 -0000 Received: from unknown (HELO iko.gotobg.net) (80.168.8.116) by pb1.pair.com with SMTP; 21 Jul 2004 17:11:14 -0000 Received: from pd95e98cf.dip.t-dialin.net ([217.94.152.207] helo=[192.168.0.32]) by iko.gotobg.net with asmtp (Exim 4.34) id 1BnKcf-0007hV-OC; Wed, 21 Jul 2004 20:11:18 +0300 Message-ID: <40FEBF1C.5040409@hristov.com> Date: Wed, 21 Jul 2004 19:08:12 +0000 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8a2) Gecko/20040627 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Cristiano Duarte CC: internals@lists.php.net References: <20040720192358.26985.qmail@pb1.pair.com> <40FE3918.1000804@hristov.com> <20040721170125.54624.qmail@pb1.pair.com> In-Reply-To: <20040721170125.54624.qmail@pb1.pair.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - iko.gotobg.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - hristov.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] array_intersect_key From: php@hristov.com (Andrey Hristov) Hallo Cristiano, these 2 function will be added to HEAD in few minutes. I see that the patch is kind of trivial and won't hurt anything :) (INTERSECT_KEY is just INTERSECT_ASSOC but no data comparison performed). I will add also array_diff_key() and array_diff_ukey() cheers, andrey P.S. Andi: I think the changes are minimal, so is it possible to merge into 5_0 ? Cristiano Duarte wrote: > Andrey Hristov wrote: > > >>is "make test" showing problems? (i am just currious). >>I will try to review the patch later today (atm i am sick). > > Nope. Make test shows the same errors before and after the patch. > > I decided to attach the patch since it will keep tabs... > > Cristiano Duarte > > > ------------------------------------------------------------------------ > > --- array.c 2004-07-11 18:15:04.000000000 -0300 > +++ /home/aluno/php-5.0.0-new/ext/standard/array.c 2004-07-21 11:47:58.000000000 -0300 > @@ -77,6 +77,7 @@ > > #define DIFF_NORMAL 0 > #define DIFF_ASSOC 1 > +#define DIFF_KEY 2 > #define DIFF_COMP_DATA_INTERNAL 0 > #define DIFF_COMP_DATA_USER 1 > #define DIFF_COMP_KEY_INTERNAL 0 > @@ -84,6 +85,7 @@ > > #define INTERSECT_NORMAL 0 > #define INTERSECT_ASSOC 1 > +#define INTERSECT_KEY 2 > #define INTERSECT_COMP_DATA_INTERNAL 0 > #define INTERSECT_COMP_DATA_USER 1 > #define INTERSECT_COMP_KEY_INTERNAL 0 > @@ -2797,7 +2799,8 @@ > php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_compare_type is %d. This should never happen. Please report as a bug", data_compare_type); > return; > } > - } else if (behavior == INTERSECT_ASSOC) { > + } else if ((behavior == INTERSECT_ASSOC) > + ||(behavior == INTERSECT_KEY)) { > intersect_key_compare_func = array_key_compare; > if (data_compare_type == INTERSECT_COMP_DATA_INTERNAL > && > @@ -2910,7 +2913,7 @@ > *list = NULL; > if (behavior == INTERSECT_NORMAL) { > zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), intersect_data_compare_func TSRMLS_CC); > - } else if (behavior == INTERSECT_ASSOC) { > + } else if ((behavior == INTERSECT_ASSOC) || (behavior == INTERSECT_KEY)) { > zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), intersect_key_compare_func TSRMLS_CC); > } > } > @@ -2926,7 +2929,8 @@ > > /* go through the lists and look for common values */ > while (*ptrs[0]) { > - if (behavior == INTERSECT_ASSOC > + if ((behavior == INTERSECT_ASSOC > + || behavior == INTERSECT_KEY) > && > key_compare_type == INTERSECT_COMP_KEY_USER) { > > @@ -2938,11 +2942,11 @@ > while (*ptrs[i] && (0 < (c = intersect_data_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) { > ptrs[i]++; > } > - } else if (behavior == INTERSECT_ASSOC) { > + } else if (behavior == INTERSECT_ASSOC || behavior == INTERSECT_KEY) { > while (*ptrs[i] && (0 < (c = intersect_key_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) { > ptrs[i]++; > } > - if (!c && *ptrs[i]) { /* this means that ptrs[i] is not NULL so we can compare */ > + if ((!c && *ptrs[i]) && (behavior == INTERSECT_ASSOC)) { /* this means that ptrs[i] is not NULL so we can compare */ > /* and "c==0" is from last operation */ > if (data_compare_type == INTERSECT_COMP_DATA_USER) { > BG(user_compare_func_name) = args[arr_argc]; > @@ -2996,7 +3000,7 @@ > if (0 <= intersect_data_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)) { > break; > } > - } else if (behavior == INTERSECT_ASSOC) { > + } else if (behavior == INTERSECT_ASSOC || behavior == INTERSECT_KEY) { > /* no need of looping because indexes are unique */ > break; > } > @@ -3012,7 +3016,7 @@ > if (intersect_data_compare_func(ptrs[0]-1, ptrs[0] TSRMLS_CC)) { > break; > } > - } else if (behavior == INTERSECT_ASSOC) { > + } else if (behavior == INTERSECT_ASSOC || behavior == INTERSECT_KEY) { > /* no need of looping because indexes are unique */ > break; > } > @@ -3050,7 +3054,27 @@ > } > /* }}} */ > > +/* {{{ proto array array_intersect_key(array arr1, array arr2 [, > +array ...]) > + Returns the entries of arr1 that have keys which are present in all the other arguments. */ > +PHP_FUNCTION(array_intersect_key) > +{ > + php_array_intersect(INTERNAL_FUNCTION_PARAM_PASSTHRU, INTERSECT_KEY, > + INTERSECT_COMP_DATA_INTERNAL, INTERSECT_COMP_KEY_INTERNAL); > +} > +/* }}} */ > + > > +/* {{{ proto array array_uintersect_key(array arr1, array arr2 [, array ...], callback data_compare_func) > + Returns the entries of arr1 that have keys which are present in all the other arguments. Key is compared by using an user-supplied callback. */ > +PHP_FUNCTION(array_uintersect_key) > +{ > + php_array_intersect(INTERNAL_FUNCTION_PARAM_PASSTHRU, INTERSECT_KEY, > + INTERSECT_COMP_DATA_INTERNAL, INTERSECT_COMP_KEY_USER); > +} > +/* }}} */ > + > + > /* {{{ proto array array_intersect_assoc(array arr1, array arr2 [, array ...]) > Returns the entries of arr1 that have values which are present in all the other arguments. Keys are used to do more restrictive check */ > PHP_FUNCTION(array_intersect_assoc) > @@ -3151,7 +3175,8 @@ > php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_compare_type is %d. This should never happen. Please report as a bug", data_compare_type); > return; > } > - } else if (behavior == DIFF_ASSOC) { > + } else if ((behavior == DIFF_ASSOC) > + || (behavior == DIFF_KEY)) { > diff_key_compare_func = array_key_compare; > if (data_compare_type == DIFF_COMP_DATA_INTERNAL > && > @@ -3264,7 +3289,7 @@ > *list = NULL; > if (behavior == DIFF_NORMAL) { > zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), diff_data_compare_func TSRMLS_CC); > - } else if (behavior == DIFF_ASSOC) { > + } else if ((behavior == DIFF_ASSOC) || (behavior == DIFF_KEY)) { > zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), diff_key_compare_func TSRMLS_CC); > } > } > @@ -3280,7 +3305,8 @@ > > /* go through the lists and look for values of ptr[0] that are not in the others */ > while (*ptrs[0]) { > - if (behavior == DIFF_ASSOC > + if ((behavior == DIFF_ASSOC > + || behavior == DIFF_KEY) > && > key_compare_type == DIFF_COMP_KEY_USER) { > > @@ -3292,7 +3318,7 @@ > while (*ptrs[i] && (0 < (c = diff_data_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) { > ptrs[i]++; > } > - } else if (behavior == DIFF_ASSOC) { > + } else if ((behavior == DIFF_ASSOC) || (behavior == DIFF_KEY)) { > while (*ptrs[i] && (0 < (c = diff_key_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) { > ptrs[i]++; > } > @@ -3337,7 +3363,7 @@ > if (diff_data_compare_func(ptrs[0] - 1, ptrs[0] TSRMLS_CC)) { > break; > } > - } else if (behavior == DIFF_ASSOC) { > + } else if ((behavior == DIFF_ASSOC) || (behavior == DIFF_KEY)) { > /* in this case no array_key_compare is needed */ > break; > } > @@ -3353,7 +3379,7 @@ > if (diff_data_compare_func(ptrs[0]-1, ptrs[0] TSRMLS_CC)) { > break; > } > - } else if (behavior == DIFF_ASSOC) { > + } else if ((behavior == DIFF_ASSOC) || (behavior == DIFF_KEY)) { > /* in this case no array_key_compare is needed */ > break; > } > @@ -3392,6 +3418,23 @@ > } > /* }}} */ > > +/* {{{ proto array array_diff_key(array arr1, array arr2 [, array ...]) > + Returns the entries of arr1 that have keys which are not present in any of the others arguments */ > +PHP_FUNCTION(array_diff_key) > +{ > + php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, DIFF_KEY, > + DIFF_COMP_DATA_INTERNAL, DIFF_COMP_KEY_INTERNAL); > +} > +/* }}} */ > + > +/* {{{ proto array array_udiff_key(array arr1, array arr2 [, array ...], callback key_comp_func) > + Returns the entries of arr1 that have keys which are not present in any of the others arguments. Keys are compared by user supplied function. */ > +PHP_FUNCTION(array_udiff_key) > +{ > + php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, DIFF_KEY, > + DIFF_COMP_DATA_INTERNAL, DIFF_COMP_KEY_USER); > +} > +/* }}} */ > > /* {{{ proto array array_diff_assoc(array arr1, array arr2 [, array ...]) > Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal */ > --- basic_functions.c 2004-06-27 18:49:47.000000000 -0300 > +++ /home/aluno/php-5.0.0-new/ext/standard/basic_functions.c 2004-07-21 11:36:34.000000000 -0300 > @@ -780,12 +780,16 @@ > PHP_FE(array_unique, NULL) > PHP_FE(array_intersect, NULL) > PHP_FE(array_uintersect, NULL) > + PHP_FE(array_intersect_key, NULL) > + PHP_FE(array_uintersect_key, NULL) > PHP_FE(array_intersect_assoc, NULL) > PHP_FE(array_uintersect_assoc, NULL) > PHP_FE(array_intersect_uassoc, NULL) > PHP_FE(array_uintersect_uassoc, NULL) > PHP_FE(array_diff, NULL) > PHP_FE(array_udiff, NULL) > + PHP_FE(array_diff_key, NULL) > + PHP_FE(array_udiff_key, NULL) > PHP_FE(array_diff_assoc, NULL) > PHP_FE(array_udiff_assoc, NULL) > PHP_FE(array_diff_uassoc, NULL) > --- php_array.h 2004-01-08 15:32:51.000000000 -0200 > +++ /home/aluno/php-5.0.0-new/ext/standard/php_array.h 2004-07-21 11:36:54.000000000 -0300 > @@ -77,12 +77,16 @@ > PHP_FUNCTION(array_unique); > PHP_FUNCTION(array_intersect); > PHP_FUNCTION(array_uintersect); > +PHP_FUNCTION(array_intersect_key); > +PHP_FUNCTION(array_uintersect_key); > PHP_FUNCTION(array_intersect_assoc); > PHP_FUNCTION(array_uintersect_assoc); > PHP_FUNCTION(array_intersect_uassoc); > PHP_FUNCTION(array_uintersect_uassoc); > PHP_FUNCTION(array_diff); > PHP_FUNCTION(array_udiff); > +PHP_FUNCTION(array_diff_key); > +PHP_FUNCTION(array_udiff_key); > PHP_FUNCTION(array_diff_assoc); > PHP_FUNCTION(array_udiff_assoc); > PHP_FUNCTION(array_diff_uassoc); >