/* Compare two values in P and Q and return -1/0/1 depending on * whether P is less than, equal to, or larger than Q. Also return -1 * if P or Q is NULL or NIL, or if the types of P and Q are not * equal. */ int VALcmp(const ValRecord *p, const ValRecord *q) { int (*cmp)(const void *, const void *); int tpe; const void *nilptr, *pp, *pq; if (p == 0 || q == 0) return -1; if ((tpe = p->vtype) != q->vtype) return -1; if (tpe == TYPE_ptr) return 0; /* ignore comparing C pointers */ cmp = ATOMcompare(tpe); nilptr = ATOMnilptr(tpe); pp = VALptr(p); pq = VALptr(q); if ((*cmp)(pp, nilptr) == 0 && (*cmp)(pq, nilptr) == 0) return 0; /* eq nil val */ if ((*cmp)(pp, nilptr) == 0 || (*cmp)(pq, nilptr) == 0) return -1; return (*cmp)(pp, pq); }
/* Return TRUE if the value in V is NIL. */ int VALisnil(const ValRecord *v) { switch (v->vtype) { case TYPE_void: return 1; case TYPE_bte: return v->val.btval == bte_nil; case TYPE_sht: return v->val.shval == sht_nil; case TYPE_int: return v->val.ival == int_nil; case TYPE_wrd: return v->val.wval == wrd_nil; case TYPE_lng: return v->val.lval == lng_nil; #ifdef HAVE_HGE case TYPE_hge: return v->val.hval == hge_nil; #endif case TYPE_flt: return v->val.fval == flt_nil; case TYPE_dbl: return v->val.dval == dbl_nil; case TYPE_oid: return v->val.oval == oid_nil; case TYPE_bat: return v->val.bval == bat_nil || v->val.bval == 0; default: break; } return (*ATOMcompare(v->vtype))(VALptr(v), ATOMnilptr(v->vtype)) == 0; }
/* Return TRUE if the value in V is NIL. */ int VALisnil(const ValRecord *v) { switch (v->vtype) { case TYPE_void: return 1; case TYPE_bte: return is_bte_nil(v->val.btval); case TYPE_sht: return is_sht_nil(v->val.shval); case TYPE_int: return is_int_nil(v->val.ival); case TYPE_lng: return is_lng_nil(v->val.lval); #ifdef HAVE_HGE case TYPE_hge: return is_hge_nil(v->val.hval); #endif case TYPE_flt: return is_flt_nil(v->val.fval); case TYPE_dbl: return is_dbl_nil(v->val.dval); case TYPE_oid: return is_oid_nil(v->val.oval); case TYPE_bat: return is_bat_nil(v->val.bval); default: break; } return (*ATOMcompare(v->vtype))(VALptr(v), ATOMnilptr(v->vtype)) == 0; }
str MKEYbathash(bat *res, const bat *bid) { BAT *b, *dst; wrd *r; BUN n; if ((b = BATdescriptor(*bid)) == NULL) throw(SQL, "mkey.bathash", RUNTIME_OBJECT_MISSING); assert(BAThvoid(b) || BAThrestricted(b)); n = BATcount(b); dst = BATnew(TYPE_void, TYPE_wrd, n, TRANSIENT); if (dst == NULL) { BBPunfix(b->batCacheid); throw(SQL, "mkey.bathash", MAL_MALLOC_FAIL); } BATseqbase(dst, b->hseqbase); BATsetcount(dst, n); r = (wrd *) Tloc(dst, BUNfirst(dst)); switch (ATOMstorage(b->ttype)) { case TYPE_void: { oid o = b->tseqbase; if (o == oid_nil) while (n-- > 0) *r++ = wrd_nil; else while (n-- > 0) *r++ = (wrd) o++; break; } case TYPE_bte: { bte *v = (bte *) Tloc(b, BUNfirst(b)); while (n-- > 0) { *r++ = MKEYHASH_bte(v); v++; } break; } case TYPE_sht: { sht *v = (sht *) Tloc(b, BUNfirst(b)); while (n-- > 0) { *r++ = MKEYHASH_sht(v); v++; } break; } case TYPE_int: case TYPE_flt: { int *v = (int *) Tloc(b, BUNfirst(b)); while (n-- > 0) { *r++ = MKEYHASH_int(v); v++; } break; } case TYPE_lng: case TYPE_dbl: { lng *v = (lng *) Tloc(b, BUNfirst(b)); while (n-- > 0) { *r++ = MKEYHASH_lng(v); v++; } break; } #ifdef HAVE_HGE case TYPE_hge: { hge *v = (hge *) Tloc(b, BUNfirst(b)); while (n-- > 0) { *r++ = MKEYHASH_hge(v); v++; } break; } #endif default: { BATiter bi = bat_iterator(b); BUN (*hash)(const void *) = BATatoms[b->ttype].atomHash; int (*cmp)(const void *, const void *) = ATOMcompare(b->ttype); void *nil = ATOMnilptr(b->ttype); BUN i; const void *v; BATloop(b, i, n) { v = BUNtail(bi, i); if ((*cmp)(v, nil) == 0) *r++ = wrd_nil; else *r++ = (wrd) (*hash)(v); } break; } }