Hash * HASHnew(Heap *hp, int tpe, BUN size, BUN mask, BUN count) { Hash *h = NULL; int width = HASHwidth(size); if (HEAPalloc(hp, mask + size + HASH_HEADER_SIZE * SIZEOF_SIZE_T / width, width) != GDK_SUCCEED) return NULL; hp->free = (mask + size) * width + HASH_HEADER_SIZE * SIZEOF_SIZE_T; h = GDKmalloc(sizeof(Hash)); if (h == NULL) return NULL; h->lim = size; h->mask = mask - 1; h->width = width; switch (width) { case BUN2: h->nil = (BUN) BUN2_NONE; break; case BUN4: h->nil = (BUN) BUN4_NONE; break; #ifdef BUN8 case BUN8: h->nil = (BUN) BUN8_NONE; break; #endif default: assert(0); } 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; HASHclear(h); /* zero the mask */ ((size_t *) hp->base)[0] = HASH_VERSION; ((size_t *) hp->base)[1] = size; ((size_t *) hp->base)[2] = mask; ((size_t *) hp->base)[3] = width; ((size_t *) hp->base)[4] = count; ALGODEBUG fprintf(stderr, "#HASHnew: create hash(size " BUNFMT ", mask " BUNFMT ",width %d, nil " BUNFMT ", total " BUNFMT " bytes);\n", size, mask, width, h->nil, (size + mask) * width); return h; }
Hash * HASHnew(Heap *hp, int tpe, BUN size, BUN mask) { Hash *h = NULL; int width = HASHwidth(size); if (HEAPalloc(hp, mask + size, width) < 0) return NULL; hp->free = (mask + size) * width; h = (Hash *) GDKmalloc(sizeof(Hash)); if (!h) return h; h->lim = size; h->mask = mask - 1; h->width = width; switch (width) { case BUN1: h->nil = (BUN) BUN1_NONE; break; case BUN2: h->nil = (BUN) BUN2_NONE; break; case BUN4: h->nil = (BUN) BUN4_NONE; break; #if SIZEOF_BUN > 4 case BUN8: h->nil = (BUN) BUN8_NONE; break; #endif default: assert(0); } h->Link = (void *) hp->base; h->Hash = (void *) ((char *) h->Link + h->lim * width); h->type = tpe; h->heap = hp; HASHclear(h); /* zero the mask */ ALGODEBUG fprintf(stderr, "#HASHnew: create hash(size " BUNFMT ", mask " BUNFMT ",width %d, nil "BUNFMT ", total "BUNFMT " bytes);\n", size, mask, width, h->nil, (size+mask) * width); return h; }