LCOV - code coverage report
Current view: top level - sql/backends/monet5/UDF/udf - udf_impl.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 34 36 94.4 %
Date: 2021-10-13 02:24:04 Functions: 12 16 75.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             : /* This file is included multiple times.  We expect the tokens UI, UU, UO, US
      10             :  * to be defined by the including file, and we expect that the
      11             :  * combination (UI,UU,UO,US) is unique to each inclusion. */
      12             : 
      13             : 
      14             : /* ! ENSURE THAT THESE LOCAL MACROS ARE UNDEFINED AT THE END OF THIS FILE ! */
      15             : 
      16             : /* concatenate two, three or five tokens */
      17             : #define U_CONCAT_2(a,b)       a##b
      18             : #define U_CONCAT_3(a,b,c)     a##b##c
      19             : #define U_CONCAT_5(a,b,c,d,e) a##b##c##d##e
      20             : 
      21             : /* function names, *_nil & TYPE_* macros */
      22             : #define UF(p,i,o,s) U_CONCAT_5(p,i,_,o,s)
      23             : #define UN(t)       U_CONCAT_2(t,_nil)
      24             : #define UT(t)       U_CONCAT_2(TYPE_,t)
      25             : #define NL(t)       U_CONCAT_3(is_,t,_nil)
      26             : 
      27             : 
      28             : /* scalar fuse */
      29             : 
      30             : /* fuse two (shift-byte) in values into one (2*shift-byte) out value */
      31             : /* actual implementation */
      32             : static char *
      33           6 : UF(UDFfuse_,UI,UO,_) ( UO *ret , UI one , UI two )
      34             : {
      35             :         int shift = sizeof(UI) * 8;
      36             : 
      37             :         /* assert calling sanity */
      38           6 :         assert(ret != NULL);
      39             : 
      40           6 :         if (NL(UI)(one) || NL(UI)(two))
      41             :                 /* NULL/nil in => NULL/nil out */
      42           0 :                 *ret = UN(UO);
      43             :         else
      44             :                 /* do the work; watch out for sign bits */
      45           6 :                 *ret = ((UO) (UU) one << shift) | (UU) two;
      46             : 
      47           6 :         return MAL_SUCCEED;
      48             : }
      49             : /* MAL wrapper */
      50             : char *
      51           6 : UF(UDFfuse_,UI,UO,) ( UO *ret , const UI *one , const UI *two )
      52             : {
      53             :         /* assert calling sanity */
      54           6 :         assert(ret != NULL && one != NULL && two != NULL);
      55             : 
      56           6 :         return UF(UDFfuse_,UI,UO,_) ( ret, *one, *two );
      57             : }
      58             : 
      59             : /* BAT fuse */
      60             : /*
      61             :  * TYPE-expanded optimized version,
      62             :  * accessing value arrays directly.
      63             :  */
      64             : 
      65             : /* type-specific core algorithm on arrays */
      66             : static char *
      67           8 : UF(UDFarrayfuse_,UI,UO,)  ( UO *res, const UI *one, const UI *two, BUN n )
      68             : {
      69             :         BUN i;
      70             :         int shift = sizeof(UI) * 8;
      71             : 
      72             :         /* assert calling sanity */
      73           8 :         assert(res != NULL && one != NULL && two != NULL);
      74             : 
      75             :         /* iterate over all values/tuples and do the work */
      76          38 :         for (i = 0; i < n; i++)
      77          30 :                 if (NL(UI)(one[i]) || NL(UI)(two[i]))
      78             :                         /* NULL/nil in => NULL/nil out */
      79           0 :                         res[i] = UN(UO);
      80             :                 else
      81             :                         /* do the work; watch out for sign bits */
      82          30 :                         res[i] = ((UO) (UU) one[i] << shift) | (UU) two[i];
      83             : 
      84           8 :         return MAL_SUCCEED;
      85             : }
      86             : 
      87             : /* type-specific core algorithm on BATs */
      88             : static char *
      89           8 : UF(UDFBATfuse_,UI,UO,)  ( const BAT *bres, BAT *bone, BAT *btwo, BUN n,
      90             :                           bit *two_tail_sorted_unsigned,
      91             :                           bit *two_tail_revsorted_unsigned )
      92             : {
      93             :         UI *one = NULL, *two = NULL;
      94             :         UO *res = NULL;
      95             :         str msg = NULL;
      96             : 
      97             :         /* assert calling sanity */
      98           8 :         assert(bres != NULL && bone != NULL && btwo != NULL);
      99           8 :         assert(BATcapacity(bres) >= n);
     100           8 :         assert(BATcount(bone) >= n && BATcount(btwo) >= n);
     101           8 :         assert(bone->ttype == UT(UI) && btwo->ttype == UT(UI));
     102           8 :         assert(bres->ttype == UT(UO));
     103             : 
     104             :         /* get direct access to the tail arrays */
     105           8 :         BATiter bonei = bat_iterator(bone);
     106           8 :         BATiter btwoi = bat_iterator(btwo);
     107           8 :         one = (UI*) bonei.base;
     108           8 :         two = (UI*) btwoi.base;
     109           8 :         res = (UO*) Tloc(bres, 0);
     110             : 
     111             :         /* call core function on arrays */
     112           8 :         msg = UF(UDFarrayfuse_,UI,UO,) ( res, one, two , n );
     113           8 :         if (msg == MAL_SUCCEED) {
     114           8 :                 *two_tail_sorted_unsigned =
     115           8 :                         BATtordered(btwo) && (two[0] >= 0 || two[n-1] < 0);
     116           8 :                 *two_tail_revsorted_unsigned =
     117           8 :                         BATtrevordered(btwo) && (two[0] < 0 || two[n-1] >= 0);
     118             :         }
     119           8 :         bat_iterator_end(&bonei);
     120           8 :         bat_iterator_end(&btwoi);
     121           8 :         return msg;
     122             : }
     123             : 
     124             : 
     125             : /* undo local defines */
     126             : #undef UT
     127             : #undef UN
     128             : #undef UF
     129             : #undef NL
     130             : #undef U_CONCAT_5
     131             : #undef U_CONCAT_3
     132             : #undef U_CONCAT_2

Generated by: LCOV version 1.14