Changeset: c9ce122c2bb1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c9ce122c2bb1
Modified Files:
NT/monetdb_config.h.in
configure.ag
gdk/Makefile.ag
gdk/gdk.h
gdk/gdk_calc.c
Branch: headless
Log Message:
Implemented a bunch of unary and binary operators on COLs.
Implemented are
isnil(COL)
negate(COL)
abs(COL)
COL {+,-,*,/,%,&,|,^,<<,>>} COL
Not all type combinations are allowed, but the ones that aren't
allowed don't make too much sense anyway (for example, sht+sht->lng is
not needed, only sht+sht->sht and sht+sht->int).
For now these functions are not used anywhere.
diffs (truncated from 4377 to 300 lines):
diff --git a/NT/monetdb_config.h.in b/NT/monetdb_config.h.in
--- a/NT/monetdb_config.h.in
+++ b/NT/monetdb_config.h.in
@@ -1004,9 +1004,11 @@
#ifdef HAVE_LONG_LONG
typedef long long lng;
+typedef unsigned long long ulng;
# define SIZEOF_LNG SIZEOF_LONG_LONG
#else
typedef __int64 lng;
+typedef unsigned __int64 ulng;
# define SIZEOF_LNG SIZEOF___INT64
#endif
diff --git a/configure.ag b/configure.ag
--- a/configure.ag
+++ b/configure.ag
@@ -3049,10 +3049,12 @@
#ifdef HAVE_LONG_LONG
typedef long long lng;
+typedef unsigned long long ulng;
# define SIZEOF_LNG SIZEOF_LONG_LONG
#else
# ifdef HAVE___INT64
typedef __int64 lng;
+typedef unsigned __int64 ulng;
# define SIZEOF_LNG SIZEOF___INT64
# endif
#endif
diff --git a/gdk/Makefile.ag b/gdk/Makefile.ag
--- a/gdk/Makefile.ag
+++ b/gdk/Makefile.ag
@@ -28,6 +28,7 @@
NAME = bat
SOURCES = \
gdk_cast.c \
+ gdk_calc.c \
gdk_colop.c \
gdk_search.c \
gdk_setop.c gdk_utils.c gdk_atoms.c \
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1639,6 +1639,20 @@
gdk_export COL *COLgroup(COL *b, oid start, int incr, int grpsize);
gdk_export COL *COLconvert(COL *b, int tp, int return_null_on_error);
+gdk_export COL *COLcalcnegate(COL *b);
+gdk_export COL *COLcalcabsolute(COL *b);
+gdk_export COL *COLcalcisnil(COL *b);
+gdk_export COL *COLcalcadd(COL *b1, COL *b2, int tp, int overflow_is_error);
+gdk_export COL *COLcalcsub(COL *b1, COL *b2, int tp, int overflow_is_error);
+gdk_export COL *COLcalcmul(COL *b1, COL *b2, int tp, int overflow_is_error);
+gdk_export COL *COLcalcdiv(COL *b1, COL *b2, int tp, int overflow_is_error);
+gdk_export COL *COLcalcmod(COL *b1, COL *b2, int overflow_is_error);
+gdk_export COL *COLcalcxor(COL *b1, COL *b2);
+gdk_export COL *COLcalcor(COL *b1, COL *b2);
+gdk_export COL *COLcalcand(COL *b1, COL *b2);
+gdk_export COL *COLcalclsh(COL *b1, COL *b2);
+gdk_export COL *COLcalcrsh(COL *b1, COL *b2);
+
/*
*
*
diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
new file mode 100644
--- /dev/null
+++ b/gdk/gdk_calc.c
@@ -0,0 +1,4306 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2011 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+#include "monetdb_config.h"
+#include "gdk.h"
+#include "gdk_private.h"
+
+/* Define symbol FULL_IMPLEMENTATION to get implementations for all
+ * sensible output types for +, -, *, /. Without the symbol, all
+ * combinations of input types are supported, but only output types
+ * that are either the largest of the input types or one size larger
+ * (if available) for +, -, *. For division the output type can be
+ * either input type of flt or dbl. */
+
+#define UNARY_TYPE_FUNC(TYPE, FUNC) \
+ do { \
+ const TYPE *src = COLelement(b, b->first); \
+ TYPE *dst = COLelement(bn, bn->first); \
+ if (b->nonil) { \
+ COLforloop(b, i) \
+ dst[i] = FUNC(src[i]); \
+ } else { \
+ COLforloop(b, i) { \
+ if (src[i] == TYPE##_nil) { \
+ nils++; \
+ dst[i] = TYPE##_nil; \
+ } else \
+ dst[i] = FUNC(src[i]); \
+ } \
+ } \
+ } while (0)
+
+#define BINARY_TYPE_FUNC(TYPE1, TYPE2, FUNC) \
+ do { \
+ const TYPE1 *lft = COLelement(b1, b1->first); \
+ const TYPE2 *rgt = COLelement(b2, b2->first); \
+ TYPE1 *dst = COLelement(bn, bn->first); \
+ if (b1->nonil && b2->nonil) { \
+ COLforloop(b1, i) \
+ dst[i] = FUNC(lft[i], rgt[i]); \
+ } else { \
+ COLforloop(b1, i) { \
+ if (lft[i] == TYPE1##_nil || \
+ rgt[i] == TYPE2##_nil) { \
+ nils++; \
+ dst[i] = TYPE1##_nil; \
+ } else \
+ dst[i] = FUNC(lft[i], rgt[i]); \
+ } \
+ } \
+ } while (0)
+
+#define NEGATE(x) (-(x))
+
+COL *
+COLcalcnegate(COL *b)
+{
+ COL *bn;
+ oid nils = 0;
+ oid i;
+
+ COLcheck(b, "COLcalcnegate");
+
+ bn = COLnew(b->type, b->count);
+ if (bn == NULL)
+ return NULL;
+
+ switch (ATOMstorage(b->type)) {
+ case TYPE_bte:
+ UNARY_TYPE_FUNC(bte, NEGATE);
+ break;
+ case TYPE_sht:
+ UNARY_TYPE_FUNC(sht, NEGATE);
+ break;
+ case TYPE_int:
+ UNARY_TYPE_FUNC(int, NEGATE);
+ break;
+ case TYPE_lng:
+ UNARY_TYPE_FUNC(lng, NEGATE);
+ break;
+ case TYPE_flt:
+ UNARY_TYPE_FUNC(flt, NEGATE);
+ break;
+ case TYPE_dbl:
+ UNARY_TYPE_FUNC(dbl, NEGATE);
+ break;
+ default:
+ CBPreclaim(bn);
+ GDKerror("COLcalcnegate: bad input type.\n");
+ return NULL;
+ }
+
+ COLsetcount(bn, b->count);
+ bn->sorted = b->revsorted && nils == 0;
+ bn->revsorted = b->sorted && nils == 0;
+ bn->nil = nils != 0;
+ bn->nonil = nils == 0;
+ bn->key = b->key & 1;
+
+ if (nils != 0 && !b->nil) {
+ b->nil = 1;
+ b->descdirty = 1;
+ }
+ if (nils == 0 && !b->nonil) {
+ b->nonil = 1;
+ b->descdirty = 1;
+ }
+
+ return bn;
+}
+
+#define ABSOLUTE(x) ((x) < 0 ? -(x) : (x))
+
+COL *
+COLcalcabsolute(COL *b)
+{
+ COL *bn;
+ oid nils= 0;
+ oid i;
+
+ COLcheck(b, "COLcalcabsolute");
+
+ bn = COLnew(b->type, b->count);
+ if (bn == NULL)
+ return NULL;
+
+ switch (ATOMstorage(b->type)) {
+ case TYPE_bte:
+ UNARY_TYPE_FUNC(bte, ABSOLUTE);
+ break;
+ case TYPE_sht:
+ UNARY_TYPE_FUNC(sht, ABSOLUTE);
+ break;
+ case TYPE_int:
+ UNARY_TYPE_FUNC(int, ABSOLUTE);
+ break;
+ case TYPE_lng:
+ UNARY_TYPE_FUNC(lng, ABSOLUTE);
+ break;
+ case TYPE_flt:
+ UNARY_TYPE_FUNC(flt, ABSOLUTE);
+ break;
+ case TYPE_dbl:
+ UNARY_TYPE_FUNC(dbl, ABSOLUTE);
+ break;
+ default:
+ CBPreclaim(bn);
+ GDKerror("COLcalcabsolute: bad input type.\n");
+ return NULL;
+ }
+
+ COLsetcount(bn, b->count);
+
+ bn->sorted = bn->count <= 1 || nils == bn->count;
+ bn->revsorted = bn->count <= 1 || nils == bn->count;
+ bn->key = bn->count <= 1;
+ bn->nil = nils != 0;
+ bn->nonil = nils == 0;
+
+ if (nils && !b->nil) {
+ b->nil = 1;
+ b->descdirty = 1;
+ }
+ if (nils == 0 && !b->nonil) {
+ b->nonil = 1;
+ b->descdirty = 1;
+ }
+
+ return bn;
+}
+
+#define ISNIL_TYPE(TYPE) \
+ do { \
+ const TYPE *src = COLelement(b, b->first); \
+ COLforloop(b, i) \
+ dst[i] = (bit) (src[i] == TYPE##_nil); \
+ } while (0)
+
+COL *
+COLcalcisnil(COL *b)
+{
+ COL *bn;
+ oid i;
+ bit *dst;
+
+ COLcheck(b, "COLcalcisnil");
+
+ if (b->nonil) {
+ bte zero = 0;
+
+ return COLconst(b->count, TYPE_bit, &zero);
+ }
+
+ bn = COLnew(TYPE_bit, b->count);
+ if (bn == NULL)
+ return NULL;
+
+ dst = COLelement(bn, bn->first);
+
+ switch (ATOMstorage(b->type)) {
+ case TYPE_bte:
+ ISNIL_TYPE(bte);
+ break;
+ case TYPE_sht:
+ ISNIL_TYPE(sht);
+ break;
+ case TYPE_int:
+ ISNIL_TYPE(int);
+ break;
+ case TYPE_lng:
+ ISNIL_TYPE(lng);
+ break;
+ case TYPE_flt:
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list