LCOV - code coverage report
Current view: top level - gdk - gdk_cross.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 42 46 91.3 %
Date: 2021-09-14 19:48:19 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : #include "monetdb_config.h"
      10             : #include "gdk.h"
      11             : #include "gdk_private.h"
      12             : 
      13             : /* Calculate a cross product between bats l and r with optional
      14             :  * candidate lists sl for l and sr for r.
      15             :  * The result is two bats r1 and r2 which contain the OID (head
      16             :  * values) of the input bats l and r.
      17             :  * If max_one is set, r can have at most one row. */
      18             : gdk_return
      19       13339 : BATsubcross(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr, bool max_one)
      20             : {
      21             :         BAT *bn1, *bn2 = NULL;
      22             :         struct canditer ci1, ci2;
      23             :         BUN cnt1, cnt2;
      24             :         oid *restrict p;
      25             :         BUN i, j;
      26             : 
      27       13339 :         cnt1 = canditer_init(&ci1, l, sl);
      28       13338 :         cnt2 = canditer_init(&ci2, r, sr);
      29             : 
      30       13339 :         if (max_one && cnt1 > 0 && cnt2 > 1) {
      31          53 :                 GDKerror("more than one match");
      32          53 :                 return GDK_FAIL;
      33             :         }
      34             : 
      35       13286 :         bn1 = COLnew(0, TYPE_oid, cnt1 * cnt2, TRANSIENT);
      36       13286 :         if (r2p)
      37       12653 :                 bn2 = COLnew(0, TYPE_oid, cnt1 * cnt2, TRANSIENT);
      38       13287 :         if (!bn1 || (r2p && !bn2)) {
      39           0 :                 BBPreclaim(bn1);
      40           0 :                 if (bn2)
      41           0 :                         BBPreclaim(bn2);
      42           0 :                 return GDK_FAIL;
      43             :         }
      44       13287 :         if (cnt1 > 0 && cnt2 > 0) {
      45       10701 :                 BATsetcount(bn1, cnt1 * cnt2);
      46       10702 :                 bn1->tsorted = true;
      47       10702 :                 bn1->trevsorted = cnt1 <= 1;
      48       10702 :                 bn1->tkey = cnt2 <= 1;
      49       10702 :                 bn1->tnil = false;
      50       10702 :                 bn1->tnonil = true;
      51       10702 :                 p = (oid *) Tloc(bn1, 0);
      52    13005745 :                 for (i = 0; i < cnt1; i++) {
      53    12995043 :                         oid x = canditer_next(&ci1);
      54    29423695 :                         for (j = 0; j < cnt2; j++) {
      55    16428652 :                                 *p++ = x;
      56             :                         }
      57             :                 }
      58       10702 :                 BATtseqbase(bn1, cnt2 == 1 ? *(oid *) Tloc(bn1, 0) : oid_nil);
      59             : 
      60       10701 :                 if (bn2) {
      61       10390 :                         BATsetcount(bn2, cnt1 * cnt2);
      62       10390 :                         bn2->tsorted = cnt1 <= 1 || cnt2 <= 1;
      63       10390 :                         bn2->trevsorted = cnt2 <= 1;
      64       10390 :                         bn2->tkey = cnt1 <= 1;
      65       10390 :                         bn2->tnil = false;
      66       10390 :                         bn2->tnonil = true;
      67       10390 :                         p = (oid *) Tloc(bn2, 0);
      68    11691300 :                         for (i = 0; i < cnt1; i++) {
      69    26774852 :                                 for (j = 0; j < cnt2; j++) {
      70    15093639 :                                         *p++ = canditer_next(&ci2);
      71             :                                 }
      72    11681213 :                                 canditer_reset(&ci2);
      73             :                         }
      74       10390 :                         BATtseqbase(bn2, cnt1 == 1 ? *(oid *) Tloc(bn2, 0) : oid_nil);
      75             :                 }
      76             :         }
      77       13287 :         *r1p = bn1;
      78       13287 :         if (r2p)
      79       12654 :                 *r2p = bn2;
      80       13287 :         if (r2p)
      81       12654 :                 TRC_DEBUG(ALGO, "BATsubcross()=(" ALGOBATFMT "," ALGOBATFMT ")\n", ALGOBATPAR(bn1), ALGOBATPAR(bn2));
      82             :         else
      83         633 :                 TRC_DEBUG(ALGO, "BATsubcross()=(" ALGOBATFMT ")\n", ALGOBATPAR(bn1));
      84             :         return GDK_SUCCEED;
      85             : }

Generated by: LCOV version 1.14