Changeset: 0b442e839f1c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/0b442e839f1c
Modified Files:
        gdk/gdk_calc.c
        monetdb5/modules/mal/batcalc.c
        monetdb5/modules/mal/calc.c
Branch: inet4+6
Log Message:

Implemented bitwise NOT for inet types.


diffs (97 lines):

diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -36,6 +36,12 @@ checkbats(BATiter *b1i, BATiter *b2i, co
 
 #define NOT(x)         (~(x))
 #define NOTBIT(x)      (!(x))
+#define NOTINET4(x)    ((inet4) {.align = ~(x).align})
+#ifdef HAVE_HGE
+#define NOTINET6(x)    ((inet6) {.align = ~(x).align})
+#else
+#define NOTINET6(x)    ((inet6) {.align[0] = ~(x).align[0], .align[1] = 
~(x).align[1]})
+#endif
 
 BAT *
 BATcalcnot(BAT *b, BAT *s)
@@ -116,6 +122,12 @@ BATcalcnot(BAT *b, BAT *s)
                UNARY_2TYPE_FUNC_nilcheck(hge, hge, NOT, ON_OVERFLOW1(hge, 
"NOT"));
                break;
 #endif
+       case TYPE_inet4:
+               UNARY_2TYPE_FUNC_nilcheck(inet4, inet4, NOTINET4, nils++);
+               break;
+       case TYPE_inet6:
+               UNARY_2TYPE_FUNC_nilcheck(inet6, inet6, NOTINET6, nils++);
+               break;
        default:
                GDKerror("type %s not supported.\n", ATOMname(bi.type));
                goto bailout;
@@ -217,6 +229,18 @@ VARcalcnot(ValPtr ret, const ValRecord *
                }
                break;
 #endif
+       case TYPE_inet4:
+               if (is_inet4_nil(v->val.ip4val))
+                       ret->val.ip4val = inet4_nil;
+               else
+                       ret->val.ip4val = NOTINET4(v->val.ip4val);
+               break;
+       case TYPE_inet6:
+               if (is_inet6_nil(v->val.ip6val))
+                       ret->val.ip6val = inet6_nil;
+               else
+                       ret->val.ip6val = NOTINET6(v->val.ip6val);
+               break;
        default:
                GDKerror("bad input type %s.\n", ATOMname(v->vtype));
                return GDK_FAIL;
diff --git a/monetdb5/modules/mal/batcalc.c b/monetdb5/modules/mal/batcalc.c
--- a/monetdb5/modules/mal/batcalc.c
+++ b/monetdb5/modules/mal/batcalc.c
@@ -1270,10 +1270,13 @@ CMDifthen(Client cntxt, MalBlkPtr mb, Ma
 static str
 batcalc_init(void)
 {
-       int types[16], cur = 0, *tp;
+       int types[20], cur = 0, *tp;
        int specials[4];
-       int *integer, *floats, *extra;
+       int *bittype, *integer, *floats, *extra;
 
+       types[cur++] = TYPE_inet4;
+       types[cur++] = TYPE_inet6;
+       bittype = types+cur;
        types[cur++] = TYPE_bit;
        integer = types+cur;
        types[cur++] = TYPE_bte;
@@ -1306,7 +1309,7 @@ batcalc_init(void)
                err += melFunction(false, "batcalc", "iszero", 
(MALfcn)&CMDbatISZERO, "CMDbatISZERO", false, "Unary check for zero over the 
tail of the bat", 1, 2, ret, arg);
                err += melFunction(false, "batcalc", "iszero", 
(MALfcn)&CMDbatISZERO, "CMDbatISZERO", false, "Unary check for zero over the 
tail of the bat with candidates list", 1, 3, ret, arg, cand);
        }
-       for(tp = types; tp < floats && !err; tp++) { /* bit + numeric */
+       for(tp = types; tp < floats && !err; tp++) { /* inet + bit + numeric */
                mel_func_arg ret = { .type = *tp, .isbat =1 };
                mel_func_arg arg = { .type = *tp, .isbat =1 };
 
@@ -1568,7 +1571,7 @@ batcalc_init(void)
                }
        };
        for (int f=0; f<3; f++) {
-               for(tp = types+0; tp < extra && !err; tp++) {
+               for(tp = bittype+0; tp < extra && !err; tp++) {
                        mel_func_arg ret = { .type = *tp, .isbat =1 };
                        mel_func_arg arg = { .type = *tp, .isbat =1 };
                        mel_func_arg varg = { .type = *tp };
diff --git a/monetdb5/modules/mal/calc.c b/monetdb5/modules/mal/calc.c
--- a/monetdb5/modules/mal/calc.c
+++ b/monetdb5/modules/mal/calc.c
@@ -1551,6 +1551,8 @@ mel_func calc_init_funcs[] = {
  pattern("calc", "not", CMDvarNOT, false, "Unary bitwise not of V", args(1,2, 
arg("",sht),arg("v",sht))),
  pattern("calc", "not", CMDvarNOT, false, "Unary bitwise not of V", args(1,2, 
arg("",int),arg("v",int))),
  pattern("calc", "not", CMDvarNOT, false, "Unary bitwise not of V", args(1,2, 
arg("",lng),arg("v",lng))),
+ pattern("calc", "not", CMDvarNOT, false, "Unary bitwise not of V", args(1,2, 
arg("",inet4),arg("v",inet4))),
+ pattern("calc", "not", CMDvarNOT, false, "Unary bitwise not of V", args(1,2, 
arg("",inet6),arg("v",inet6))),
  pattern("calc", "sign", CMDvarSIGN, false, "Unary sign (-1,0,1) of V", 
args(1,2, arg("",bte),arg("v",bte))),
  pattern("calc", "sign", CMDvarSIGN, false, "Unary sign (-1,0,1) of V", 
args(1,2, arg("",bte),arg("v",sht))),
  pattern("calc", "sign", CMDvarSIGN, false, "Unary sign (-1,0,1) of V", 
args(1,2, arg("",bte),arg("v",int))),
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to