LCOV - code coverage report
Current view: top level - gdk - gdk_cross.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 42 45 93.3 %
Date: 2020-06-29 20:00:14 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 - 2020 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       10804 : BATsubcross(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr, bool max_one)
      20             : {
      21       10804 :         BAT *bn1, *bn2;
      22       10804 :         struct canditer ci1, ci2;
      23       10804 :         BUN cnt1, cnt2;
      24       10804 :         oid *restrict p;
      25       10804 :         BUN i, j;
      26             : 
      27       10804 :         cnt1 = canditer_init(&ci1, l, sl);
      28       10804 :         cnt2 = canditer_init(&ci2, r, sr);
      29             : 
      30       10804 :         if (max_one && cnt1 > 0 && cnt2 > 1) {
      31          36 :                 GDKerror("more than one match");
      32          36 :                 return GDK_FAIL;
      33             :         }
      34             : 
      35       10768 :         bn1 = COLnew(0, TYPE_oid, cnt1 * cnt2, TRANSIENT);
      36       10768 :         bn2 = COLnew(0, TYPE_oid, cnt1 * cnt2, TRANSIENT);
      37       10767 :         if (bn1 == NULL || bn2 == NULL) {
      38           0 :                 BBPreclaim(bn1);
      39           0 :                 BBPreclaim(bn2);
      40           0 :                 return GDK_FAIL;
      41             :         }
      42       10767 :         if (cnt1 > 0 && cnt2 > 0) {
      43        9392 :                 BATsetcount(bn1, cnt1 * cnt2);
      44        9392 :                 bn1->tsorted = true;
      45        9392 :                 bn1->trevsorted = cnt1 <= 1;
      46        9392 :                 bn1->tkey = cnt2 <= 1;
      47        9392 :                 bn1->tnil = false;
      48        9392 :                 bn1->tnonil = true;
      49        9392 :                 p = (oid *) Tloc(bn1, 0);
      50    10603100 :                 for (i = 0; i < cnt1; i++) {
      51    10593700 :                         oid x = canditer_next(&ci1);
      52    37042500 :                         for (j = 0; j < cnt2; j++) {
      53    15855100 :                                 *p++ = x;
      54             :                         }
      55             :                 }
      56        9392 :                 BATtseqbase(bn1, cnt2 == 1 ? *(oid *) Tloc(bn1, 0) : oid_nil);
      57             : 
      58        9392 :                 BATsetcount(bn2, cnt1 * cnt2);
      59        9392 :                 bn2->tsorted = cnt1 <= 1 || cnt2 <= 1;
      60        9392 :                 bn2->trevsorted = cnt2 <= 1;
      61        9392 :                 bn2->tkey = cnt1 <= 1;
      62        9392 :                 bn2->tnil = false;
      63        9392 :                 bn2->tnonil = true;
      64        9392 :                 p = (oid *) Tloc(bn2, 0);
      65    11051500 :                 for (i = 0; i < cnt1; i++) {
      66    27256900 :                         for (j = 0; j < cnt2; j++) {
      67    16210000 :                                 *p++ = canditer_next(&ci2);
      68             :                         }
      69    11046800 :                         canditer_reset(&ci2);
      70             :                 }
      71        9392 :                 BATtseqbase(bn2, cnt1 == 1 ? *(oid *) Tloc(bn2, 0) : oid_nil);
      72             :         }
      73       10767 :         *r1p = bn1;
      74       10767 :         *r2p = bn2;
      75       10767 :         TRC_DEBUG(ALGO, "BATsubcross()=(" ALGOBATFMT "," ALGOBATFMT ")\n", ALGOBATPAR(bn1), ALGOBATPAR(bn2));
      76             :         return GDK_SUCCEED;
      77             : }

Generated by: LCOV version 1.14