LCOV - code coverage report
Current view: top level - gdk - gdk_private.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 12 12 100.0 %
Date: 2024-10-03 20:03:20 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : /* This file should not be included in any file outside of this directory */
      14             : 
      15             : #ifndef LIBGDK
      16             : #error this file should not be included outside its source directory
      17             : #endif
      18             : 
      19             : /* persist hash heaps for persistent BATs */
      20             : #define PERSISTENTHASH 1
      21             : 
      22             : /* persist order index heaps for persistent BATs */
      23             : #define PERSISTENTIDX 1
      24             : 
      25             : /* persist strimp heaps for persistent BATs */
      26             : #define PERSISTENTSTRIMP 1
      27             : 
      28             : /* only check whether we exceed gdk_vm_maxsize when allocating heaps */
      29             : #define SIZE_CHECK_IN_HEAPS_ONLY 1
      30             : 
      31             : #include "gdk_system_private.h"
      32             : 
      33             : enum heaptype {
      34             :         offheap,
      35             :         varheap,
      36             :         hashheap,
      37             :         imprintsheap,
      38             :         orderidxheap,
      39             :         strimpheap,
      40             :         dataheap
      41             : };
      42             : 
      43             : enum range_comp_t {
      44             :         range_before,           /* search range fully before bat range */
      45             :         range_after,            /* search range fully after bat range */
      46             :         range_atstart,          /* search range before + inside */
      47             :         range_atend,            /* search range inside + after */
      48             :         range_contains,         /* search range contains bat range */
      49             :         range_inside,           /* search range inside bat range */
      50             : };
      51             : 
      52             : bool ATOMisdescendant(int id, int parentid)
      53             :         __attribute__((__visibility__("hidden")));
      54             : int ATOMunknown_find(const char *nme)
      55             :         __attribute__((__warn_unused_result__))
      56             :         __attribute__((__visibility__("hidden")));
      57             : const char *ATOMunknown_name(int a)
      58             :         __attribute__((__visibility__("hidden")));
      59             : void ATOMunknown_clean(void)
      60             :         __attribute__((__visibility__("hidden")));
      61             : bool BATcheckhash(BAT *b)
      62             :         __attribute__((__visibility__("hidden")));
      63             : bool BATcheckimprints(BAT *b)
      64             :         __attribute__((__visibility__("hidden")));
      65             : gdk_return BATcheckmodes(BAT *b, bool persistent)
      66             :         __attribute__((__warn_unused_result__))
      67             :         __attribute__((__visibility__("hidden")));
      68             : BAT *BATcreatedesc(oid hseq, int tt, bool heapnames, role_t role, uint16_t width)
      69             :         __attribute__((__visibility__("hidden")));
      70             : void BATdelete(BAT *b)
      71             :         __attribute__((__visibility__("hidden")));
      72             : void BATdestroy(BAT *b)
      73             :         __attribute__((__visibility__("hidden")));
      74             : void BATfree(BAT *b)
      75             :         __attribute__((__visibility__("hidden")));
      76             : gdk_return BATgroup_internal(BAT **groups, BAT **extents, BAT **histo, BAT *b, BAT *s, BAT *g, BAT *e, BAT *h, bool subsorted)
      77             :         __attribute__((__warn_unused_result__))
      78             :         __attribute__((__visibility__("hidden")));
      79             : Hash *BAThash_impl(BAT *restrict b, struct canditer *restrict ci, const char *restrict ext)
      80             :         __attribute__((__visibility__("hidden")));
      81             : void BAThashsave(BAT *b, bool dosync)
      82             :         __attribute__((__visibility__("hidden")));
      83             : bool BATiscand(BAT *b)
      84             :         __attribute__((__visibility__("hidden")));
      85             : BAT *BATload_intern(bat bid, bool lock)
      86             :         __attribute__((__visibility__("hidden")));
      87             : gdk_return BATmaterialize(BAT *b, BUN cap)
      88             :         __attribute__((__warn_unused_result__))
      89             :         __attribute__((__visibility__("hidden")));
      90             : BAT *BATnegcands2(oid hseq, BUN nr, BAT *odels)
      91             :         __attribute__((__visibility__("hidden")));
      92             : gdk_return BATsave_iter(BAT *bd, BATiter *bi, BUN size)
      93             :         __attribute__((__visibility__("hidden")));
      94             : void BATsetdims(BAT *b, uint16_t width)
      95             :         __attribute__((__visibility__("hidden")));
      96             : gdk_return BBPcacheit(BAT *bn, bool lock)
      97             :         __attribute__((__warn_unused_result__))
      98             :         __attribute__((__visibility__("hidden")));
      99             : gdk_return BBPchkfarms(void)
     100             :         __attribute__((__warn_unused_result__))
     101             :         __attribute__((__visibility__("hidden")));
     102             : void BBPclear(bat bid)
     103             :         __attribute__((__visibility__("hidden")));
     104             : void BBPdump(void)              /* never called: for debugging only */
     105             :         __attribute__((__cold__));
     106             : void BBPexit(void)
     107             :         __attribute__((__visibility__("hidden")));
     108             : gdk_return BBPinit(bool allow_hge_upgrade)
     109             :         __attribute__((__visibility__("hidden")));
     110             : bat BBPallocbat(int tt)
     111             :         __attribute__((__warn_unused_result__))
     112             :         __attribute__((__visibility__("hidden")));
     113             : void BBPprintinfo(void)
     114             :         __attribute__((__visibility__("hidden")));
     115             : int BBPselectfarm(role_t role, int type, enum heaptype hptype)
     116             :         __attribute__((__visibility__("hidden")));
     117             : gdk_return BBPsync(int cnt, bat *restrict subcommit, BUN *restrict sizes, lng logno)
     118             :         __attribute__((__visibility__("hidden")));
     119             : BUN binsearch(const oid *restrict indir, oid offset, int type, const void *restrict vals, const char * restrict vars, int width, BUN lo, BUN hi, const void *restrict v, int ordering, int last)
     120             :         __attribute__((__visibility__("hidden")));
     121             : BUN binsearch_bte(const oid *restrict indir, oid offset, const bte *restrict vals, BUN lo, BUN hi, bte v, int ordering, int last)
     122             :         __attribute__((__visibility__("hidden")));
     123             : BUN binsearch_sht(const oid *restrict indir, oid offset, const sht *restrict vals, BUN lo, BUN hi, sht v, int ordering, int last)
     124             :         __attribute__((__visibility__("hidden")));
     125             : BUN binsearch_int(const oid *restrict indir, oid offset, const int *restrict vals, BUN lo, BUN hi, int v, int ordering, int last)
     126             :         __attribute__((__visibility__("hidden")));
     127             : BUN binsearch_lng(const oid *restrict indir, oid offset, const lng *restrict vals, BUN lo, BUN hi, lng v, int ordering, int last)
     128             :         __attribute__((__visibility__("hidden")));
     129             : #ifdef HAVE_HGE
     130             : BUN binsearch_hge(const oid *restrict indir, oid offset, const hge *restrict vals, BUN lo, BUN hi, hge v, int ordering, int last)
     131             :         __attribute__((__visibility__("hidden")));
     132             : #endif
     133             : BUN binsearch_flt(const oid *restrict indir, oid offset, const flt *restrict vals, BUN lo, BUN hi, flt v, int ordering, int last)
     134             :         __attribute__((__visibility__("hidden")));
     135             : BUN binsearch_dbl(const oid *restrict indir, oid offset, const dbl *restrict vals, BUN lo, BUN hi, dbl v, int ordering, int last)
     136             :         __attribute__((__visibility__("hidden")));
     137             : Heap *createOIDXheap(BAT *b, bool stable)
     138             :         __attribute__((__visibility__("hidden")));
     139             : void doHASHdestroy(BAT *b, Hash *hs)
     140             :         __attribute__((__visibility__("hidden")));
     141             : void gdk_bbp_reset(void)
     142             :         __attribute__((__visibility__("hidden")));
     143             : gdk_return GDKextend(const char *fn, size_t size)
     144             :         __attribute__((__warn_unused_result__))
     145             :         __attribute__((__visibility__("hidden")));
     146             : gdk_return GDKextendf(int fd, size_t size, const char *fn)
     147             :         __attribute__((__warn_unused_result__))
     148             :         __attribute__((__visibility__("hidden")));
     149             : int GDKfdlocate(int farmid, const char *nme, const char *mode, const char *ext)
     150             :         __attribute__((__visibility__("hidden")));
     151             : FILE *GDKfilelocate(int farmid, const char *nme, const char *mode, const char *ext)
     152             :         __attribute__((__visibility__("hidden")));
     153             : FILE *GDKfileopen(int farmid, const char *dir, const char *name, const char *extension, const char *mode)
     154             :         __attribute__((__visibility__("hidden")));
     155             : char *GDKload(int farmid, const char *nme, const char *ext, size_t size, size_t *maxsize, storage_t mode)
     156             :         __attribute__((__visibility__("hidden")));
     157             : gdk_return GDKmove(int farmid, const char *dir1, const char *nme1, const char *ext1, const char *dir2, const char *nme2, const char *ext2, bool report)
     158             :         __attribute__((__warn_unused_result__))
     159             :         __attribute__((__visibility__("hidden")));
     160             : void *GDKmremap(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size)
     161             :         __attribute__((__visibility__("hidden")));
     162             : gdk_return GDKremovedir(int farmid, const char *nme)
     163             :         __attribute__((__warn_unused_result__))
     164             :         __attribute__((__visibility__("hidden")));
     165             : gdk_return GDKsave(int farmid, const char *nme, const char *ext, void *buf, size_t size, storage_t mode, bool dosync)
     166             :         __attribute__((__warn_unused_result__))
     167             :         __attribute__((__visibility__("hidden")));
     168             : gdk_return GDKssort_rev(void *restrict h, void *restrict t, const void *restrict base, size_t n, int hs, int ts, int tpe)
     169             :         __attribute__((__warn_unused_result__))
     170             :         __attribute__((__visibility__("hidden")));
     171             : gdk_return GDKssort(void *restrict h, void *restrict t, const void *restrict base, size_t n, int hs, int ts, int tpe)
     172             :         __attribute__((__warn_unused_result__))
     173             :         __attribute__((__visibility__("hidden")));
     174             : gdk_return GDKtracer_init(const char *dbname, const char *dbtrace)
     175             :         __attribute__((__visibility__("hidden")));
     176             : gdk_return GDKunlink(int farmid, const char *dir, const char *nme, const char *extension)
     177             :         __attribute__((__visibility__("hidden")));
     178             : #define GDKwarning(format, ...)                                 \
     179             :         GDKtracer_log(__FILE__, __func__, __LINE__, M_WARNING,  \
     180             :                       GDK, NULL, format, ##__VA_ARGS__)
     181             : lng getBBPlogno(void)
     182             :         __attribute__((__visibility__("hidden")));
     183             : BUN HASHappend(BAT *b, BUN i, const void *v)
     184             :         __attribute__((__visibility__("hidden")));
     185             : void HASHappend_locked(BAT *b, BUN i, const void *v)
     186             :         __attribute__((__visibility__("hidden")));
     187             : void HASHfree(BAT *b)
     188             :         __attribute__((__visibility__("hidden")));
     189             : BUN HASHdelete(BATiter *bi, BUN p, const void *v)
     190             :         __attribute__((__visibility__("hidden")));
     191             : void HASHdelete_locked(BATiter *bi, BUN p, const void *v)
     192             :         __attribute__((__visibility__("hidden")));
     193             : BUN HASHinsert(BATiter *bi, BUN p, const void *v)
     194             :         __attribute__((__visibility__("hidden")));
     195             : void HASHinsert_locked(BATiter *bi, BUN p, const void *v)
     196             :         __attribute__((__visibility__("hidden")));
     197             : static inline BUN __attribute__((__const__))
     198      862571 : HASHmask(BUN cnt)
     199             : {
     200      862571 :         cnt = cnt * 8 / 7;
     201      862571 :         if (cnt < BATTINY)
     202       33258 :                 cnt = BATTINY;
     203      608772 :         return cnt;
     204             : }
     205             : gdk_return HASHnew(Hash *h, int tpe, BUN size, BUN mask, BUN count, bool bcktonly)
     206             :         __attribute__((__visibility__("hidden")));
     207             : gdk_return HEAPalloc(Heap *h, size_t nitems, size_t itemsize)
     208             :         __attribute__((__warn_unused_result__))
     209             :         __attribute__((__visibility__("hidden")));
     210             : gdk_return HEAPcopy(Heap *dst, Heap *src, size_t offset)
     211             :         __attribute__((__warn_unused_result__))
     212             :         __attribute__((__visibility__("hidden")));
     213             : void HEAPfree(Heap *h, bool remove)
     214             :         __attribute__((__visibility__("hidden")));
     215             : gdk_return HEAPgrow(Heap **old, size_t size, bool mayshare)
     216             :         __attribute__((__visibility__("hidden")));
     217             : gdk_return HEAPload(Heap *h, const char *nme, const char *ext, bool trunc)
     218             :         __attribute__((__warn_unused_result__))
     219             :         __attribute__((__visibility__("hidden")));
     220             : void HEAP_recover(Heap *, const var_t *, BUN)
     221             :         __attribute__((__visibility__("hidden")));
     222             : gdk_return HEAPsave(Heap *h, const char *nme, const char *ext, bool dosync, BUN free, MT_Lock *lock)
     223             :         __attribute__((__warn_unused_result__))
     224             :         __attribute__((__visibility__("hidden")));
     225             : void IMPSdecref(Imprints *imprints, bool remove)
     226             :         __attribute__((__visibility__("hidden")));
     227             : void IMPSfree(BAT *b)
     228             :         __attribute__((__visibility__("hidden")));
     229             : int IMPSgetbin(int tpe, bte bits, const char *restrict bins, const void *restrict v)
     230             :         __attribute__((__visibility__("hidden")));
     231             : void IMPSincref(Imprints *imprints)
     232             :         __attribute__((__visibility__("hidden")));
     233             : #ifndef NDEBUG
     234             : void IMPSprint(BAT *b)          /* never called: for debugging only */
     235             :         __attribute__((__cold__));
     236             : #endif
     237             : double joincost(BAT *r, BUN lcount, struct canditer *rci, bool *hash, bool *phash, bool *cand)
     238             :         __attribute__((__visibility__("hidden")));
     239             : void STRMPincref(Strimps *strimps)
     240             :         __attribute__((__visibility__("hidden")));
     241             : void STRMPdecref(Strimps *strimps, bool remove)
     242             :         __attribute__((__visibility__("hidden")));
     243             : void STRMPfree(BAT *b)
     244             :         __attribute__((__visibility__("hidden")));
     245             : void MT_init_posix(void)
     246             :         __attribute__((__visibility__("hidden")));
     247             : void *MT_mmap(const char *path, int mode, size_t len)
     248             :         __attribute__((__visibility__("hidden")));
     249             : void *MT_mremap(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size)
     250             :         __attribute__((__visibility__("hidden")));
     251             : int MT_msync(void *p, size_t len)
     252             :         __attribute__((__visibility__("hidden")));
     253             : int MT_munmap(void *p, size_t len)
     254             :         __attribute__((__visibility__("hidden")));
     255             : void OIDXfree(BAT *b)
     256             :         __attribute__((__visibility__("hidden")));
     257             : void persistOIDX(BAT *b)
     258             :         __attribute__((__visibility__("hidden")));
     259             : void PROPdestroy(BAT *b)
     260             :         __attribute__((__visibility__("hidden")));
     261             : void PROPdestroy_nolock(BAT *b)
     262             :         __attribute__((__visibility__("hidden")));
     263             : gdk_return rangejoin(BAT *r1, BAT *r2, BAT *l, BAT *rl, BAT *rh, struct canditer *lci, struct canditer *rci, bool li, bool hi, bool anti, bool symmetric, BUN maxsize)
     264             :         __attribute__((__warn_unused_result__))
     265             :         __attribute__((__visibility__("hidden")));
     266             : void settailname(Heap *restrict tail, const char *restrict physnme, int tt, int width)
     267             :         __attribute__((__visibility__("hidden")));
     268             : void strCleanHash(Heap *hp, bool rebuild)
     269             :         __attribute__((__visibility__("hidden")));
     270             : gdk_return strHeap(Heap *d, size_t cap)
     271             :         __attribute__((__visibility__("hidden")));
     272             : var_t strLocate(Heap *h, const char *v)
     273             :         __attribute__((__visibility__("hidden")));
     274             : var_t strPut(BAT *b, var_t *dst, const void *v)
     275             :         __attribute__((__visibility__("hidden")));
     276             : char *strRead(str a, size_t *dstlen, stream *s, size_t cnt)
     277             :         __attribute__((__visibility__("hidden")));
     278             : ssize_t strToStr(char **restrict dst, size_t *restrict len, const char *restrict src, bool external)
     279             :         __attribute__((__visibility__("hidden")));
     280             : gdk_return strWrite(const char *a, stream *s, size_t cnt)
     281             :         __attribute__((__visibility__("hidden")));
     282             : gdk_return TMcommit(void)
     283             :         __attribute__((__visibility__("hidden")));
     284             : gdk_return unshare_varsized_heap(BAT *b)
     285             :         __attribute__((__warn_unused_result__))
     286             :         __attribute__((__visibility__("hidden")));
     287             : void VIEWdestroy(BAT *b)
     288             :         __attribute__((__visibility__("hidden")));
     289             : BAT *virtualize(BAT *bn)
     290             :         __attribute__((__visibility__("hidden")));
     291             : 
     292             : static inline bool
     293          61 : imprintable(int tpe)
     294             : {
     295         107 :         switch (ATOMbasetype(tpe)) {
     296             :         case TYPE_bte:
     297             :         case TYPE_sht:
     298             :         case TYPE_int:
     299             :         case TYPE_lng:
     300             : #ifdef HAVE_HGE
     301             :         case TYPE_hge:
     302             : #endif
     303             :         case TYPE_flt:
     304             :         case TYPE_dbl:
     305             :                 return true;
     306           9 :         default:                /* type not supported */
     307           9 :                 return false;
     308             :         }
     309             : }
     310             : 
     311             : /* calculate the integer 2 logarithm (i.e. position of highest set
     312             :  * bit) of the argument (with a slight twist: 0 gives 0, 1 gives 1,
     313             :  * 0x8 to 0xF give 4, etc.) */
     314             : static inline unsigned
     315       10781 : ilog2(BUN x)
     316             : {
     317       10781 :         if (x == 0)
     318             :                 return 0;
     319             : #ifdef __has_builtin
     320             : #if SIZEOF_BUN == 8 && __has_builtin(__builtin_clzll)
     321       10781 :         return (unsigned) (64 - __builtin_clzll((unsigned long long) x));
     322             : #define BUILTIN_USED
     323             : #elif __has_builtin(__builtin_clz)
     324             :         return (unsigned) (32 - __builtin_clz((unsigned) x));
     325             : #define BUILTIN_USED
     326             : #endif
     327             : #endif
     328             : #ifndef BUILTIN_USED
     329             : #if defined(_MSC_VER)
     330             :         unsigned long n;
     331             :         if (
     332             : #if SIZEOF_BUN == 8
     333             :                 _BitScanReverse64(&n, (unsigned __int64) x)
     334             : #else
     335             :                 _BitScanReverse(&n, (unsigned long) x)
     336             : #endif
     337             :                 )
     338             :                 return (unsigned) n + 1;
     339             :         else
     340             :                 return 0;
     341             : #else
     342             :         unsigned n = 0;
     343             :         BUN y;
     344             : 
     345             :         /* use a "binary search" method */
     346             : #if SIZEOF_BUN == 8
     347             :         if ((y = x >> 32) != 0) {
     348             :                 x = y;
     349             :                 n += 32;
     350             :         }
     351             : #endif
     352             :         if ((y = x >> 16) != 0) {
     353             :                 x = y;
     354             :                 n += 16;
     355             :         }
     356             :         if ((y = x >> 8) != 0) {
     357             :                 x = y;
     358             :                 n += 8;
     359             :         }
     360             :         if ((y = x >> 4) != 0) {
     361             :                 x = y;
     362             :                 n += 4;
     363             :         }
     364             :         if ((y = x >> 2) != 0) {
     365             :                 x = y;
     366             :                 n += 2;
     367             :         }
     368             :         if ((y = x >> 1) != 0) {
     369             :                 x = y;
     370             :                 n += 1;
     371             :         }
     372             :         return n + (x != 0);
     373             : #endif
     374             : #endif
     375             : #undef BUILTIN_USED
     376             : }
     377             : 
     378             : /* some macros to help print info about BATs when using ALGODEBUG */
     379             : #define ALGOBATFMT      "%s#" BUNFMT "@" OIDFMT "[%s%s]%s%s%s%s%s%s%s%s%s"
     380             : #define ALGOBATPAR(b)                                                   \
     381             :         BATgetId(b),                                                    \
     382             :         BATcount(b),                                                    \
     383             :         b->hseqbase,                                                 \
     384             :         ATOMname(b->ttype),                                          \
     385             :         b->ttype==TYPE_str?b->twidth==1?"1":b->twidth==2?"2":b->twidth==4?"4":"8":"", \
     386             :         !b->batTransient ? "P" : b->theap && b->theap->parentid != b->batCacheid ? "V" : b->tvheap && b->tvheap->parentid != b->batCacheid ? "v" : "T", \
     387             :         BATtdense(b) ? "D" : b->ttype == TYPE_void && b->tvheap ? "X" : ATOMstorage(b->ttype) == TYPE_str && GDK_ELIMDOUBLES(b->tvheap) ? "E" : "", \
     388             :         b->tsorted ? "S" : b->tnosorted ? "!s" : "",                        \
     389             :         b->trevsorted ? "R" : b->tnorevsorted ? "!r" : "",          \
     390             :         b->tkey ? "K" : b->tnokey[1] ? "!k" : "",                   \
     391             :         b->tnonil ? "N" : "",                                            \
     392             :         b->thash ? "H" : "",                                             \
     393             :         b->torderidx ? "O" : "",                                 \
     394             :         b->timprints ? "I" : b->theap && b->theap->parentid && BBP_desc(b->theap->parentid) && BBP_desc(b->theap->parentid)->timprints ? "(I)" : ""
     395             : /* use ALGOOPTBAT* when BAT is optional (can be NULL) */
     396             : #define ALGOOPTBATFMT   "%s%s" BUNFMT "%s" OIDFMT "%s%s%s%s%s%s%s%s%s%s%s%s%s"
     397             : #define ALGOOPTBATPAR(b)                                                \
     398             :         b ? BATgetId(b) : "",                                         \
     399             :         b ? "#" : "",                                                       \
     400             :         b ? BATcount(b) : 0,                                            \
     401             :         b ? "@" : "",                                                       \
     402             :         b ? b->hseqbase : 0,                                         \
     403             :         b ? "[" : "",                                                       \
     404             :         b ? ATOMname(b->ttype) : "",                                       \
     405             :         b ? b->ttype==TYPE_str?b->twidth==1?"1":b->twidth==2?"2":b->twidth==4?"4":"8":"" : "", \
     406             :         b ? "]" : "",                                                       \
     407             :         b ? !b->batTransient ? "P" : b->theap && b->theap->parentid != b->batCacheid ? "V" : b->tvheap && b->tvheap->parentid != b->batCacheid ? "v" : "T" : "", \
     408             :         b ? BATtdense(b) ? "D" : b->ttype == TYPE_void && b->tvheap ? "X" : ATOMstorage(b->ttype) == TYPE_str && b->tvheap && GDK_ELIMDOUBLES(b->tvheap) ? "E" : "" : "", \
     409             :         b ? b->tsorted ? "S" : b->tnosorted ? "!s" : "" : "",             \
     410             :         b ? b->trevsorted ? "R" : b->tnorevsorted ? "!r" : "" : "",       \
     411             :         b ? b->tkey ? "K" : b->tnokey[1] ? "!k" : "" : "",                \
     412             :         b && b->tnonil ? "N" : "",                                       \
     413             :         b && b->thash ? "H" : "",                                        \
     414             :         b && b->torderidx ? "O" : "",                                    \
     415             :         b ? b->timprints ? "I" : b->theap && b->theap->parentid && BBP_desc(b->theap->parentid) && BBP_desc(b->theap->parentid)->timprints ? "(I)" : "" : ""
     416             : 
     417             : #ifdef __SANITIZE_THREAD__
     418             : #define BBP_BATMASK     31
     419             : #else
     420             : #define BBP_BATMASK     ((1 << (SIZEOF_SIZE_T + 5)) - 1)
     421             : #endif
     422             : 
     423             : struct PROPrec {
     424             :         enum prop_t id;
     425             :         ValRecord v;
     426             :         struct PROPrec *next;   /* simple chain of properties */
     427             : };
     428             : 
     429             : struct Imprints {
     430             :         bte bits;               /* how many bits in imprints */
     431             :         Heap imprints;
     432             :         void *bins;             /* pointer into imprints heap (bins borders)  */
     433             :         BUN *stats;             /* pointer into imprints heap (stats per bin) */
     434             :         void *imps;             /* pointer into imprints heap (bit vectors)   */
     435             :         void *dict;             /* pointer into imprints heap (dictionary)    */
     436             :         BUN impcnt;             /* counter for imprints                       */
     437             :         BUN dictcnt;            /* counter for cache dictionary               */
     438             : };
     439             : 
     440             : typedef uint64_t strimp_masks_t;  /* TODO: make this a sparse matrix */
     441             : 
     442             : struct Strimps {
     443             :         Heap strimps;
     444             :         uint8_t *sizes_base;    /* pointer into strimps heap (pair sizes)  */
     445             :         uint8_t *pairs_base;    /* pointer into strimps heap (pairs start)   */
     446             :         void *bitstrings_base;  /* pointer into strimps heap (bitstrings
     447             :                                  * start) bitstrings_base is a pointer
     448             :                                  * to uint64_t */
     449             :         size_t rec_cnt;         /* reconstruction counter: how many
     450             :                                  * bitstrings were added after header
     451             :                                  * construction. Currently unused. */
     452             :         strimp_masks_t *masks;  /* quick access to masks for
     453             :                                  * bitstring construction */
     454             : };
     455             : 
     456             : typedef struct {
     457             :         MT_Lock swap;
     458             : } batlock_t;
     459             : 
     460             : typedef char long_str[IDLENGTH];        /* standard GDK static string */
     461             : 
     462             : #define MAXFARMS       32
     463             : 
     464             : extern struct BBPfarm_t {
     465             :         uint32_t roles;         /* bitmask of allowed roles */
     466             :         const char *dirname;    /* farm directory */
     467             :         FILE *lock_file;
     468             : } BBPfarms[MAXFARMS];
     469             : 
     470             : extern batlock_t GDKbatLock[BBP_BATMASK + 1];
     471             : extern size_t GDK_mmap_minsize_persistent; /* size after which we use memory mapped files for persistent heaps */
     472             : extern size_t GDK_mmap_minsize_transient; /* size after which we use memory mapped files for transient heaps */
     473             : extern size_t GDK_mmap_pagesize; /* mmap granularity */
     474             : 
     475             : #define BATcheck(tst, err)                              \
     476             :         do {                                            \
     477             :                 if ((tst) == NULL) {                    \
     478             :                         GDKerror("BAT required.\n");  \
     479             :                         return (err);                   \
     480             :                 }                                       \
     481             :         } while (0)
     482             : #define ERRORcheck(tst, msg, err)               \
     483             :         do {                                    \
     484             :                 if (tst) {                      \
     485             :                         GDKerror(msg);          \
     486             :                         return (err);           \
     487             :                 }                               \
     488             :         } while (0)
     489             : 
     490             : #define GDKswapLock(x)  GDKbatLock[(x)&BBP_BATMASK].swap
     491             : 
     492             : #define HEAPREMOVE      ((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 1))
     493             : #define DELAYEDREMOVE   ((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 2))
     494             : #define HEAPREFS        (((ATOMIC_BASE_TYPE) 1 << (sizeof(ATOMIC_BASE_TYPE) * 8 - 2)) - 1)
     495             : 
     496             : /* when the number of updates to a BAT is less than 1 in this number, we
     497             :  * keep the unique_est property */
     498             : #define GDK_UNIQUE_ESTIMATE_KEEP_FRACTION       1000
     499             : extern BUN gdk_unique_estimate_keep_fraction; /* should become a define once */
     500             : /* if the number of unique values is less than 1 in this number, we
     501             :  * destroy the hash rather than update it in HASH{append,insert,delete} */
     502             : #define HASH_DESTROY_UNIQUES_FRACTION           1000
     503             : extern BUN hash_destroy_uniques_fraction;     /* likewise */
     504             : /* if the estimated number of unique values is less than 1 in this
     505             :  * number, don't build a hash table to do a hashselect */
     506             : #define NO_HASH_SELECT_FRACTION                 1000
     507             : extern dbl no_hash_select_fraction;           /* same here */
     508             : /* if the hash chain is longer than this number, we delete the hash
     509             :  * rather than maintaining it in HASHdelete */
     510             : #define HASH_DESTROY_CHAIN_LENGTH               1000
     511             : extern BUN hash_destroy_chain_length;
     512             : 
     513             : #if !defined(NDEBUG) && !defined(__COVERITY__)
     514             : /* see comment in gdk.h */
     515             : #ifdef __GNUC__
     516             : #define GDKmremap(p, m, oa, os, ns)                                     \
     517             :         ({                                                              \
     518             :                 const char *_path = (p);                                \
     519             :                 int _mode = (m);                                        \
     520             :                 void *_oa = (oa);                                       \
     521             :                 size_t _os = (os);                                      \
     522             :                 size_t *_ns = (ns);                                     \
     523             :                 size_t _ons = *_ns;                                     \
     524             :                 void *_res = GDKmremap(_path, _mode, _oa, _os, _ns);    \
     525             :                 TRC_DEBUG(ALLOC,                                        \
     526             :                           "GDKmremap(%s,0x%x,%p,%zu,%zu > %zu) -> %p\n", \
     527             :                           _path ? _path : "NULL", (unsigned) _mode,   \
     528             :                           _oa, _os, _ons, *_ns, _res);                  \
     529             :                 _res;                                                   \
     530             :          })
     531             : #else
     532             : static inline void *
     533             : GDKmremap_debug(const char *path, int mode, void *old_address, size_t old_size, size_t *new_size)
     534             : {
     535             :         size_t orig_new_size = *new_size;
     536             :         void *res = GDKmremap(path, mode, old_address, old_size, new_size);
     537             :         TRC_DEBUG(ALLOC, "GDKmremap(%s,0x%x,%p,%zu,%zu > %zu) -> %p\n",
     538             :                   path ? path : "NULL", (unsigned) mode,
     539             :                   old_address, old_size, orig_new_size, *new_size, res);
     540             :         return res;
     541             : }
     542             : #define GDKmremap(p, m, oa, os, ns)     GDKmremap_debug(p, m, oa, os, ns)
     543             : 
     544             : #endif
     545             : #endif

Generated by: LCOV version 1.14