📄 batmtime.mx
字号:
@' 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-2007 CWI.@' All Rights Reserved.@f batmtime@a M.L. Kersten@+ Time/Date multiplexes[TODO: property propagations]The collection of routines provided here are map operationsfor the atom time and date primitives. In line with the batcalc module, we assume thatif two bat operands are provided that they are alreadyaligned on the head. Moreover, the head of the BATsare limited to :void, which can be cheaply realized usingthe GRPsplit operation.@{@= compareOpcommand batcalc.@2( l:bat[:oid,:@1], r:bat[:oid,:@1]) :bat[:oid,:bit]address MTIME@1bat_@3;command batcalc.@2( l:bat[:void,:@1], r:bat[:void,:@1]) :bat[:void,:bit]address MTIME@1bat_@3comment "Compare a bat of @1 against each other";command batcalc.@2( l:bat[:oid,:@1], r:@1) :bat[:oid,:bit]address MTIME@1bat_@3cst;command batcalc.@2( l:bat[:void,:@1], r:@1) :bat[:void,:bit]address MTIME@1bat_@3cstcomment "Compare a bat of @1 against a singleton";@= compareGrp@:compareOp(@1,==,EQ)@@:compareOp(@1,!=,NEQ)@@:compareOp(@1,<,LT)@@:compareOp(@1,<=,LE)@@:compareOp(@1,>,GT)@@:compareOp(@1,>=,GE)@@mal@:compareGrp(date)@@:compareGrp(daytime)@@:compareGrp(timestamp)@@+ Implementation@c#include "mal_config.h"#include <gdk.h>#include "ctype.h"#include "mal_exception.h"#include "mtime.h"#include "batmtime.h"#define prepareOperand(X,Y,Z) \ if( (X= BATdescriptor(*Y)) == NULL ) \ throw(MAL, "batstr." Z, "Cannot access descriptor");#define prepareOperand2(X,Y,A,B,Z) \ if( (X= BATdescriptor(*Y)) == NULL ) \ throw(MAL, "batstr." Z, "Cannot access descriptor"); \ if( (A= BATdescriptor(*B)) == NULL ){\ BBPreleaseref(X->batCacheid); \ throw(MAL, "batstr."Z, "Cannot access descriptor"); \ }#define prepareResult(X,Y,T,Z) \ X= BATnew(Y->htype,T,BATcount(Y)); \ if( Y->htype== TYPE_void) \ BATseqbase(X, Y->hseqbase); \ if( X == NULL){ \ BBPreleaseref(Y->batCacheid); \ throw(MAL, "batstr." Z, "no space available "); \ } \ X->hsorted=Y->hsorted; \ X->tsorted=0; #define prepareResult2(X,Y,A,T,Z) \ X= BATnew(Y->htype,T,BATcount(Y)); \ if( Y->htype== TYPE_void) \ BATseqbase(X, Y->hseqbase); \ if( X == NULL){ \ BBPreleaseref(Y->batCacheid); \ BBPreleaseref(A->batCacheid); \ throw(MAL, "batstr." Z, "no space available "); \ } \ X->hsorted=Y->hsorted; \ X->tsorted=0; #define finalizeResult(X,Y,Z) \ if (!((Y)->batDirty&2)) (Y) = BATsetaccess((Y), BAT_READ); \ *X = (Y)->batCacheid; \ BBPkeepref(*(X));\ BBPreleaseref(Z->batCacheid);@-A general assumption in all cases is the bats are synchronized on theirhead column. This is not checked and may be mis-used to deploy theimplementation for shifted window arithmetic as well.@= chkSize if( BATcount(@1) != BATcount(@2) ) throw(MAL, "batcalc.@3", "requires bats of identical size");@= implDefbatmtime_export str MTIME@1bat_@2(int *ret, int *l, int *r);batmtime_export str MTIME@1bat_@2cst(int *ret, int *l, @1 *cst);@= implCmpOpstr MTIME@1bat_@3(int *ret, int *l, int *r){ BAT *bn, *left, *right; BUN o,p,q; bit *a; size_t xx,yy; prepareOperand2(left,l,right,r,"batcalc.@2"); @:chkSize(left,right,CMDcompare@1)@ prepareResult2(bn,left,right,TYPE_bit,"batcalc.@2"); if( BUNsize(left) != sizeof(@1) || BUNsize(right)!= sizeof(@1) ){ BBPreleaseref(right->batCacheid); BBPreleaseref(left->batCacheid); BBPreleaseref(bn->batCacheid); throw(MAL, "batmtime.@3","Unexpected input type"); } o = BUNtail(left,BUNfirst(left)); p = BUNtail(right,BUNfirst(right)); q = BUNtail(right,BUNlast(right)); a = (bit*)BUNtail(bn, BUNfirst(bn)); xx= BUNsize(left); yy= BUNsize(right); while(p<q) { MTIME@1_@3(a++, (@1*)o, (@1*)p); o+= xx; p+= yy; } BATsetcount(bn, BATcount(left)); bn->batBuns->free = ((char *)a) - bn->batBuns->base; BBPreleaseref(right->batCacheid); finalizeResult(ret,bn,left); return MAL_SUCCEED;}str MTIME@1bat_@3cst(int *ret, int *l, @1 *cst){ BAT *bn, *left; BUN p,q; bit *a; size_t xx; prepareOperand(left,l,"batcalc.@2"); prepareResult(bn,left,TYPE_bit,"batcalc.@2"); if( BUNsize(left) != sizeof(@1)) throw(MAL, "batmtime.@3","Unexpected input type"); p = BUNtail(left,BUNfirst(left)); q = BUNtail(left,BUNlast(left)); a = (bit*)BUNtail(bn, BUNfirst(bn)); xx= BUNsize(left); while(p<q) { MTIME@1_@3(a++, (@1*)p, cst); p+= xx; } BATsetcount(bn, BATcount(left)); bn->batBuns->free = ((char *)a) - bn->batBuns->base; finalizeResult(ret,bn,left); return MAL_SUCCEED;}@-The implementation section.@= implCmpGrpDef@:implDef(@1,EQ)@@:implDef(@1,NEQ)@@:implDef(@1,LT)@@:implDef(@1,LE)@@:implDef(@1,GT)@@:implDef(@1,GE)@@= implCmpGrp@:implCmpOp(@1,==,EQ)@@:implCmpOp(@1,!=,NEQ)@@:implCmpOp(@1,<,LT)@@:implCmpOp(@1,<=,LE)@@:implCmpOp(@1,>,GT)@@:implCmpOp(@1,>=,GE)@@h#ifdef WIN32#ifndef LIBBATMTIME#define batmtime_export extern __declspec(dllimport)#else#define batmtime_export extern __declspec(dllexport)#endif#else#define batmtime_export extern#endif@:implCmpGrpDef(date)@@:implCmpGrpDef(daytime)@@:implCmpGrpDef(timestamp)@@c@:implCmpGrp(daytime)@@:implCmpGrp(date)@@:implCmpGrp(timestamp)@@}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -