Changeset: 77c15068147f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=77c15068147f
Modified Files:
        gdk/gdk_imprints.c
        gdk/gdk_search.c
Branch: default
Log Message:

Use manifest constant for header size in persistent hash/imprints.


diffs (133 lines):

diff --git a/gdk/gdk_imprints.c b/gdk/gdk_imprints.c
--- a/gdk/gdk_imprints.c
+++ b/gdk/gdk_imprints.c
@@ -19,6 +19,7 @@
 #include "gdk_imprints.h"
 
 #define IMPRINTS_VERSION       2
+#define IMPRINTS_HEADER_SIZE   4 /* nr of size_t fields in header */
 
 #define BINSIZE(B, FUNC, T) do {               \
        switch (B) {                            \
@@ -631,7 +632,7 @@ BATimprints(BAT *b)
                                                           imprintsheap);
                if ((fd = GDKfdlocate(imprints->imprints->farmid, nme, "rb",
                                      b->batCacheid > 0 ? "timprints" : 
"himprints")) >= 0) {
-                       size_t hdata[4];
+                       size_t hdata[IMPRINTS_HEADER_SIZE];
                        struct stat st;
                        if (read(fd, hdata, sizeof(hdata)) == sizeof(hdata) &&
                            hdata[0] & ((size_t) 1 << 16) &&
@@ -646,13 +647,13 @@ BATimprints(BAT *b)
                                                   pages * ((bte) hdata[0] / 8) 
+
                                                   hdata[2] * sizeof(cchdc_t) +
                                                   sizeof(uint64_t) /* padding 
for alignment */
-                                                  + 4 * SIZEOF_SIZE_T) &&
+                                                  + IMPRINTS_HEADER_SIZE * 
SIZEOF_SIZE_T) &&
                            HEAPload(imprints->imprints, nme, b->batCacheid > 0 
? "timprints" : "himprints", 0) >= 0) {
                                /* usable */
                                imprints->bits = (bte) (hdata[0] & 0xFF);
                                imprints->impcnt = (BUN) hdata[1];
                                imprints->dictcnt = (BUN) hdata[2];
-                               imprints->bins = imprints->imprints->base + 4 * 
SIZEOF_SIZE_T;
+                               imprints->bins = imprints->imprints->base + 
IMPRINTS_HEADER_SIZE * SIZEOF_SIZE_T;
                                imprints->stats = (BUN *) ((char *) 
imprints->bins + 64 * b->T->width);
                                imprints->imps = (void *) (imprints->stats + 64 
* 3);
                                imprints->dict = (void *) ((uintptr_t) ((char 
*) imprints->imps + pages * (imprints->bits / 8) + sizeof(uint64_t)) & 
~(sizeof(uint64_t) - 1));
@@ -727,7 +728,7 @@ BATimprints(BAT *b)
                              pages * (imprints->bits / 8) +
                              pages * sizeof(cchdc_t) +
                              sizeof(uint64_t) /* padding for alignment */
-                             + 4 * SIZEOF_SIZE_T, /* extra info */
+                             + IMPRINTS_HEADER_SIZE * SIZEOF_SIZE_T, /* extra 
info */
                              1) < 0) {
                        GDKfree(imprints->imprints);
                        GDKfree(imprints);
@@ -736,7 +737,7 @@ BATimprints(BAT *b)
                                      "BATimprints");
                        return GDK_FAIL;
                }
-               imprints->bins = imprints->imprints->base + 4 * SIZEOF_SIZE_T;
+               imprints->bins = imprints->imprints->base + 
IMPRINTS_HEADER_SIZE * SIZEOF_SIZE_T;
                imprints->stats = (BUN *) ((char *) imprints->bins + 64 * 
b->T->width);
                imprints->imps = (void *) (imprints->stats + 64 * 3);
                imprints->dict = (void *) ((uintptr_t) ((char *) imprints->imps 
+ pages * (imprints->bits / 8) + sizeof(uint64_t)) & ~(sizeof(uint64_t) - 1));
diff --git a/gdk/gdk_search.c b/gdk/gdk_search.c
--- a/gdk/gdk_search.c
+++ b/gdk/gdk_search.c
@@ -119,7 +119,8 @@ HASHclear(Hash *h)
        memset(h->Hash, 0xFF, (h->mask + 1) * h->width);
 }
 
-#define HASH_VERSION   1
+#define HASH_VERSION           1
+#define HASH_HEADER_SIZE       5 /* nr of size_t fields in header */
 
 Hash *
 HASHnew(Heap *hp, int tpe, BUN size, BUN mask, BUN count)
@@ -127,9 +128,9 @@ HASHnew(Heap *hp, int tpe, BUN size, BUN
        Hash *h = NULL;
        int width = HASHwidth(size);
 
-       if (HEAPalloc(hp, mask + size + 5 * SIZEOF_SIZE_T / width, width) < 0)
+       if (HEAPalloc(hp, mask + size + HASH_HEADER_SIZE * SIZEOF_SIZE_T / 
width, width) < 0)
                return NULL;
-       hp->free = (mask + size) * width + 5 * SIZEOF_SIZE_T;
+       hp->free = (mask + size) * width + HASH_HEADER_SIZE * SIZEOF_SIZE_T;
        h = GDKmalloc(sizeof(Hash));
        if (h == NULL)
                return NULL;
@@ -143,7 +144,7 @@ HASHnew(Heap *hp, int tpe, BUN size, BUN
        case BUN4:
                h->nil = (BUN) BUN4_NONE;
                break;
-#if SIZEOF_BUN > 4
+#ifdef BUN8
        case BUN8:
                h->nil = (BUN) BUN8_NONE;
                break;
@@ -151,7 +152,7 @@ HASHnew(Heap *hp, int tpe, BUN size, BUN
        default:
                assert(0);
        }
-       h->Link = hp->base + 5 * SIZEOF_SIZE_T;
+       h->Link = hp->base + HASH_HEADER_SIZE * SIZEOF_SIZE_T;
        h->Hash = (void *) ((char *) h->Link + h->lim * width);
        h->type = tpe;
        h->heap = hp;
@@ -234,7 +235,7 @@ BATcheckhash(BAT *b)
 
                        /* check whether a persisted hash can be found */
                        if ((fd = GDKfdlocate(hp->farmid, nme, "rb+", ext)) >= 
0) {
-                               size_t hdata[5];
+                               size_t hdata[HASH_HEADER_SIZE];
                                struct stat st;
 
                                if ((h = GDKmalloc(sizeof(*h))) != NULL &&
@@ -242,7 +243,7 @@ BATcheckhash(BAT *b)
                                    hdata[0] == (((size_t) 1 << 24) | 
HASH_VERSION) &&
                                    hdata[4] == (size_t) BATcount(b) &&
                                    fstat(fd, &st) == 0 &&
-                                   st.st_size >= (off_t) ((hdata[1] + 
hdata[2]) * hdata[3] + 5 * SIZEOF_SIZE_T) &&
+                                   st.st_size >= (off_t) ((hdata[1] + 
hdata[2]) * hdata[3] + HASH_HEADER_SIZE * SIZEOF_SIZE_T) &&
                                    HEAPload(hp, nme, ext, 0) >= 0) {
                                        h->lim = (BUN) hdata[1];
                                        h->type = ATOMtype(b->ttype);
@@ -256,7 +257,7 @@ BATcheckhash(BAT *b)
                                        case BUN4:
                                                h->nil = (BUN) BUN4_NONE;
                                                break;
-#if SIZEOF_BUN > 4
+#ifdef BUN8
                                        case BUN8:
                                                h->nil = (BUN) BUN8_NONE;
                                                break;
@@ -264,7 +265,7 @@ BATcheckhash(BAT *b)
                                        default:
                                                assert(0);
                                        }
-                                       h->Link = hp->base + 5 * SIZEOF_SIZE_T;
+                                       h->Link = hp->base + HASH_HEADER_SIZE * 
SIZEOF_SIZE_T;
                                        h->Hash = (void *) ((char *) h->Link + 
h->lim * h->width);
                                        close(fd);
                                        b->T->hash = h;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to