⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 array.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
📖 第 1 页 / 共 2 页
字号:
@' 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 array@a A.R. van Ballegooij@+ Basic array supportThe array support library constructs the index arrays essentialfor the Relational Algebra Model language.The grid filler operation assumes that there is enough space.The shift variant multiplies all elements with a constant factor.It is a recurring operation for the RAM front-end and will savean additional copying.The optimization is captured in a contraction macro.@{@malmodule array;@= grid_mdefscommand grid(i:@1,j:@1,k:@1,l:@1) :bat[:oid,:@1] address ARRAYgrid_@1comment  "Generates an index BAT, (grpcount,grpsize,clustersize,offset)";command grid(i:@1,j:@1,k:@1,l:@1,s:@1) :bat[:oid,:@1] address ARRAYgridShift_@1comment  "Generates an index BAT, (grpcount,grpsize,clustersize,offset)and shift all elements with a factor s";command grid(b:bat[:oid,:@1],i:@1,j:@1,k:@1,l:@1) :bat[:oid,:@1] address ARRAYgridBAT_@1comment  "Fills an index BAT, (grpcount,grpsize,clustersize,offset)";command grid(b:bat[:oid,:@1],i:@1,j:@1,k:@1,l:@1,s:@1) :bat[:oid,:@1] address ARRAYgridBAT_@1comment  "Fills an index BAT, (grpcount,grpsize,clustersize,offset)and shift all elemenets with a factor s";@mal@:grid_mdefs(int)@@:grid_mdefs(lng)@command product(b:bat[:any_3,:any_1],c:bat[:any_4,:any_2]):bat[:any_1,:any_2]address ARRAYproductcomment "Produce an array product";command project(b:bat[:oid,:any_1],i:int):bat[:oid,:int]address ARRAYprojectcomment "Fill an array representation with constants ";pattern print(a:bat[:any_1,:any_2],b:bat[:any_1,:int]...) :void address ARRAYprintcomment "Prints an array, using 1 value bat and N aligned index bats";@- Implementation@include ../mal/prelude.mx@h/*============================================================================*/#ifndef __array_h__#define __array_h__#include <gdk.h>#include <algebra.h>		/* to include BATmin and BATmax */@= grid_hdefs#define new_@1_bat(b,s) {(b)=BATnew(TYPE_void,TYPE_@1,(size_t) (s)); \                         BATseqbase((b),0);                 }#define add_@1s(b,n)    {(b)->batBuns->free+=(size_t)(n)*sizeof(@1);\			                   (b)->batCount+=(size_t)n;\                         BATkey(BATmirror((b)),0);          \                         (b)->tsorted = 0;                  }#define get_@1_ptr(b)   ((@1*)(BUNfirst((b))))@h@:grid_hdefs(int)@@:grid_hdefs(lng)@/* The maximum number of dimensions that the print-function can handle... */#define MAX_ARRAY_DIM 16#endif/*============================================================================*/@c/*============================================================================*/#include "mal_config.h"#include "array.h"#include "gdk.h"#include <math.h>#include <time.h>/*----------------------------------------------------------------------------*/#ifdef WIN32#ifndef LIBARRAY#define array_export extern __declspec(dllimport)#else#define array_export extern __declspec(dllexport)#endif#else#define array_export extern#endifarray_export str ARRAYproduct(int *ret, int *bid, int *rid);array_export str ARRAYproject(int *ret, int *bid, int *cst);array_export str ARRAYprint(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);@= grid_implarray_export str ARRAYgrid_@1(@1 *ret, @1 *groups, @1 *groupsize, @1 *clustersize, @1 *offset);array_export str ARRAYgridShift_@1(@1 *ret, @1 *groups, @1 *groupsize, @1 *clustersize, @1 *offset, @1 *shift);array_export str ARRAYgridBAT_@1(@1 *ret, @1 *bid, @1 *groups, @1 *groupsize, @1 *clustersize, @1 *offset);array_export str ARRAYgridBATshift_@1(@1 *ret, @1 *bid, @1 *groups, @1 *groupsize, @1 *clustersize, @1 *offset, @1 *shift);intfillgrid_@1(BAT **out, @1 *groups, @1 *groupsize, @1 *clustersize, @1 *offset, @1 *shift){	register @1 *ptr;	@1 i = *groups;	@1 n = *groupsize + *offset;	@1 r = *clustersize;	@1 o = *offset;	@1 s = *shift;#ifdef EXCESSIVE_DEBUGGING	fprintf(stderr, "[grid] (%d,%d,%d,%d)", i, n, r, o);#endif	ptr = get_@1_ptr(*out);	while (i-- > 0) {		register int ni = (int) o;		while (ni < n) {			register int ri = (int) r;			while (ri-- > 0)				(*(ptr ++)) = ni * s;			ni++;		}	}#ifdef EXCESSIVE_DEBUGGING	fprintf(stderr, "- done\n");#endif	return GDK_SUCCEED;}intgrid_@1(BAT **out, @1 *groups, @1 *groupsize, @1 *clustersize, @1 *offset){	@1 i = *groups;	@1 n = *groupsize + *offset;	@1 r = *clustersize;	@1 o = *offset;	@1 s = 1;#ifdef EXCESSIVE_DEBUGGING	fprintf(stderr, "[grid] (%d,%d,%d,%d)", i, n, r, o);#endif	new_@1_bat(*out, (i * (n - o) * r));	if (*out == 0)		return GDK_FAIL;	add_@1s(*out, (i * (n - o) * r));	return fillgrid_@1(out, groups, groupsize, clustersize, offset, &s);}intgridShift_@1(BAT **out, @1 *groups, @1 *groupsize, @1 *clustersize, @1 *offset, @1 *shift){	@1 i = *groups;	@1 n = *groupsize + *offset;	@1 r = *clustersize;	@1 o = *offset;#ifdef EXCESSIVE_DEBUGGING	fprintf(stderr, "[grid] (%d,%d,%d,%d)", i, n, r, o);#endif	new_@1_bat(*out, (i * (n - o) * r));	if (*out == 0)		return GDK_FAIL;	add_@1s(*out, (i * (n - o) * r));	return fillgrid_@1(out, groups, groupsize, clustersize, offset, shift);}@c@:grid_impl(int)@@:grid_impl(lng)@@+The M5 wrapper code@c#include "mal.h"@= grid_wrapper_implstrARRAYgrid_@1(@1 *ret, @1 *groups, @1 *groupsize, @1 *clustersize, @1 *offset){	BAT *bn;	if (grid_@1(&bn, groups, groupsize, clustersize, offset) == GDK_FAIL)		throw(MAL, "array.grid", "Failed to create the grid");	if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); \	*ret = bn->batCacheid;	BBPkeepref((int)*ret);	return MAL_SUCCEED;}strARRAYgridShift_@1(@1 *ret, @1 *groups, @1 *groupsize, @1 *clustersize, @1 *offset, @1 *shift){	BAT *bn;	if (gridShift_@1(&bn, groups, groupsize, clustersize, offset, shift) == GDK_FAIL)		throw(MAL, "array.grid", "Failed to create the grid");	if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); \	*ret = bn->batCacheid;	BBPkeepref((int)*ret);	return MAL_SUCCEED;}strARRAYgridBAT_@1(@1 *ret, @1 *bid, @1 *groups, @1 *groupsize, @1 *clustersize, @1 *offset){	BAT *bn;	@1 shift = 1;	if ((bn = BATdescriptor(*bid)) == NULL) {		throw(MAL, "array.grid", "Cannot access descriptor");	}	if (fillgrid_@1(&bn, groups, groupsize, clustersize, offset, &shift) == GDK_FAIL)		throw(MAL, "array.grid", "Failed to create the grid");	if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); \	*ret = bn->batCacheid;	BBPkeepref((int)*ret);	return MAL_SUCCEED;}strARRAYgridBATshift_@1(@1 *ret, @1 *bid, @1 *groups, @1 *groupsize, @1 *clustersize, @1 *offset, @1 *shift){	BAT *bn;	if ((bn = BATdescriptor(*bid)) == NULL) {		throw(MAL, "array.grid", "Cannot access descriptor");	}	if (fillgrid_@1(&bn, groups, groupsize, clustersize, offset, shift) == GDK_FAIL)		throw(MAL, "array.grid", "Failed to create the grid");	if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); \	*ret = bn->batCacheid;	BBPkeepref((int)*ret);	return MAL_SUCCEED;}@c@:grid_wrapper_impl(int)@@:grid_wrapper_impl(lng)@@-@= arraymultiplyarray_export str ARRAYmultiply_@1_@2(int *ret, int *bid, int *rid);strARRAYmultiply_@1_@2(int *ret, int *bid, int *rid){	BAT *bn, *b, *r;	BUN p,q, s,t;	int x1,x2;	@2 val;	oid o= oid_nil;	if( (b= BATdescriptor(*bid)) == NULL ){		 throw(MAL, "array.*", "Cannot access descriptor");	}	if( (r= BATdescriptor(*rid)) == NULL ){		BBPreleaseref(b->batCacheid);		 throw(MAL, "array.*", "Cannot access descriptor");	}	bn= BATnew(TYPE_void, TYPE_@2, BATcount(b)*BATcount(r));	BATseqbase(bn,0);	BATloopFast(b,p,q,x1){		BATloopFast(r,s,t,x2){			val = (*(@1*) BUNtail(b,p)) * (*(@1*)BUNtail(r,s));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -