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

Generated by: LCOV version 1.14