Changeset: edeae81de3e6 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=edeae81de3e6 Modified Files: gdk/gdk.h gdk/gdk_hash.h Branch: linear-hashing Log Message:
Moved all hash related stuff from gdk.h to gdk_hash.h. Note gdk_hash.h is included by gdk.h. diffs (182 lines): diff --git a/gdk/gdk.h b/gdk/gdk.h --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -595,17 +595,7 @@ typedef struct { bat parentid; /* cache id of VIEW parent bat */ } Heap; -typedef struct { - int type; /* type of index entity */ - int width; /* width of hash entries */ - BUN nil; /* nil representation */ - BUN mask; /* number of hash buckets-1 (power of 2) */ - void *Hash; /* hash table */ - void *Link; /* collision list */ - Heap heaplink; /* heap where the hash links are stored */ - Heap heapbckt; /* heap where the hash buckets are stored */ -} Hash; - +typedef struct Hash Hash; typedef struct Imprints Imprints; /* @@ -1838,24 +1828,6 @@ gdk_export char *ATOMformat(int id, cons gdk_export void *ATOMdup(int id, const void *val); /* - * @- Built-in Accelerator Functions - * - * @multitable @columnfractions 0.08 0.7 - * @item BAT* - * @tab - * BAThash (BAT *b) - * @end multitable - * - * The current BAT implementation supports three search accelerators: - * hashing, imprints, and ordered index. - * - * The routine BAThash makes sure that a hash accelerator on the tail of the - * BAT exists. GDK_FAIL is returned upon failure to create the supportive - * structures. - */ -gdk_export gdk_return BAThash(BAT *b); - -/* * @- Column Imprints Functions * * @multitable @columnfractions 0.08 0.7 @@ -2642,55 +2614,6 @@ gdk_export void VIEWbounds(BAT *b, BAT * */ #define GDK_STREQ(l,r) (*(char*) (l) == *(char*) (r) && !strcmp(l,r)) -#define HASHloop(bi, h, hb, v) \ - for (hb = HASHget(h, HASHprobe((h), v)); \ - hb != HASHnil(h); \ - hb = HASHgetlink(h,hb)) \ - if (ATOMcmp(h->type, v, BUNtail(bi, hb)) == 0) -#define HASHloop_str_hv(bi, h, hb, v) \ - for (hb = HASHget((h),((BUN *) (v))[-1]&(h)->mask); \ - hb != HASHnil(h); \ - hb = HASHgetlink(h,hb)) \ - if (GDK_STREQ(v, BUNtvar(bi, hb))) -#define HASHloop_str(bi, h, hb, v) \ - for (hb = HASHget((h),strHash(v)&(h)->mask); \ - hb != HASHnil(h); \ - hb = HASHgetlink(h,hb)) \ - if (GDK_STREQ(v, BUNtvar(bi, hb))) - -/* - * HASHloops come in various flavors, from the general HASHloop, as - * above, to specialized versions (for speed) where the type is known - * (e.g. HASHloop_int), or the fact that the atom is fixed-sized - * (HASHlooploc) or variable-sized (HASHloopvar). - */ -#define HASHlooploc(bi, h, hb, v) \ - for (hb = HASHget(h, HASHprobe(h, v)); \ - hb != HASHnil(h); \ - hb = HASHgetlink(h,hb)) \ - if (ATOMcmp(h->type, v, BUNtloc(bi, hb)) == 0) -#define HASHloopvar(bi, h, hb, v) \ - for (hb = HASHget(h,HASHprobe(h, v)); \ - hb != HASHnil(h); \ - hb = HASHgetlink(h,hb)) \ - if (ATOMcmp(h->type, v, BUNtvar(bi, hb)) == 0) - -#define HASHloop_TYPE(bi, h, hb, v, TYPE) \ - for (hb = HASHget(h, hash_##TYPE(h, v)); \ - hb != HASHnil(h); \ - hb = HASHgetlink(h,hb)) \ - if (* (const TYPE *) (v) == * (const TYPE *) BUNtloc(bi, hb)) - -#define HASHloop_bte(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, bte) -#define HASHloop_sht(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, sht) -#define HASHloop_int(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, int) -#define HASHloop_lng(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, lng) -#ifdef HAVE_HGE -#define HASHloop_hge(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, hge) -#endif -#define HASHloop_flt(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, flt) -#define HASHloop_dbl(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, dbl) - /* * @+ Common BAT Operations * Much used, but not necessarily kernel-operations on BATs. diff --git a/gdk/gdk_hash.h b/gdk/gdk_hash.h --- a/gdk/gdk_hash.h +++ b/gdk/gdk_hash.h @@ -8,6 +8,7 @@ #ifndef _GDK_SEARCH_H_ #define _GDK_SEARCH_H_ + /* * @+ Hash indexing * @@ -18,6 +19,19 @@ * of mean size 4. This was shown to be inferior to direct hashing * with integer anding. The new implementation reflects this. */ + +typedef struct Hash { + int type; /* type of index entity */ + int width; /* width of hash entries */ + BUN nil; /* nil representation */ + BUN mask; /* number of hash buckets-1 (power of 2) */ + void *Hash; /* hash table */ + void *Link; /* collision list */ + Heap heaplink; /* heap where the hash links are stored */ + Heap heapbckt; /* heap where the hash buckets are stored */ +} Hash; + +gdk_export gdk_return BAThash(BAT *b); gdk_export void HASHdestroy(BAT *b); gdk_export BUN HASHprobe(const Hash *h, const void *v); gdk_export BUN HASHlist(Hash *h, BUN i); @@ -261,4 +275,47 @@ gdk_export BUN HASHlist(Hash *h, BUN i); } \ } while (0) +#define HASHloop(bi, h, hb, v) \ + for (hb = HASHget(h, HASHprobe((h), v)); \ + hb != HASHnil(h); \ + hb = HASHgetlink(h,hb)) \ + if (ATOMcmp(h->type, v, BUNtail(bi, hb)) == 0) +#define HASHloop_str_hv(bi, h, hb, v) \ + for (hb = HASHget((h),((BUN *) (v))[-1]&(h)->mask); \ + hb != HASHnil(h); \ + hb = HASHgetlink(h,hb)) \ + if (GDK_STREQ(v, BUNtvar(bi, hb))) +#define HASHloop_str(bi, h, hb, v) \ + for (hb = HASHget((h),strHash(v)&(h)->mask); \ + hb != HASHnil(h); \ + hb = HASHgetlink(h,hb)) \ + if (GDK_STREQ(v, BUNtvar(bi, hb))) + +#define HASHlooploc(bi, h, hb, v) \ + for (hb = HASHget(h, HASHprobe(h, v)); \ + hb != HASHnil(h); \ + hb = HASHgetlink(h,hb)) \ + if (ATOMcmp(h->type, v, BUNtloc(bi, hb)) == 0) +#define HASHloopvar(bi, h, hb, v) \ + for (hb = HASHget(h,HASHprobe(h, v)); \ + hb != HASHnil(h); \ + hb = HASHgetlink(h,hb)) \ + if (ATOMcmp(h->type, v, BUNtvar(bi, hb)) == 0) + +#define HASHloop_TYPE(bi, h, hb, v, TYPE) \ + for (hb = HASHget(h, hash_##TYPE(h, v)); \ + hb != HASHnil(h); \ + hb = HASHgetlink(h,hb)) \ + if (* (const TYPE *) (v) == * (const TYPE *) BUNtloc(bi, hb)) + +#define HASHloop_bte(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, bte) +#define HASHloop_sht(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, sht) +#define HASHloop_int(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, int) +#define HASHloop_lng(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, lng) +#ifdef HAVE_HGE +#define HASHloop_hge(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, hge) +#endif +#define HASHloop_flt(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, flt) +#define HASHloop_dbl(bi, h, hb, v) HASHloop_TYPE(bi, h, hb, v, dbl) + #endif /* _GDK_SEARCH_H_ */ _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list