<commit_before>/*
 * 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://www.monetdb.org/Legal/MonetDBLicense
 *
 * 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-2014 MonetDB B.V.
 * All Rights Reserved.
 */

/*
 * M.L. Kersten
 */
#include "monetdb_config.h"
#include "manifold.h"
#include "mal_resolve.h"
#include "mal_builder.h"

//#define _DEBUG_MANIFOLD_

/* The default iterator over known scalar commands.
 * It can be less efficient then the vector based implementations,
 * but saves quite some hacking in non-essential cases or
 * expensive user defined functions..
 *
 * To keep things simple and reasonably performant we limit the
 * implementation to those cases where a single BAT is returned.
 * Arguments may be of any type. The MAL signature should be a COMMAND.
 *
 */

typedef struct{
	BAT *b;
	void *first;
	void *last;
	int	size;
	int type;
	BATiter bi;
	BUN  o;
	BUN  q;
	str *s;
} MULTIarg;

typedef struct{
	Client cntxt;
	MalBlkPtr mb;
	MalStkPtr stk;
	InstrPtr pci;
	int fvar,lvar;
	MULTIarg *args;
} MULTItask;


// Loop through the first BAT
// keep the last error message received
#define ManifoldLoop(Type, ...) {			\
	Type *v = (Type*) mut->args[0].first; 		\
	for( ; p<q ; p += mut->args[mut->fvar].size){ 	\
		msg = (*mut->pci->fcn)(v, __VA_ARGS__); \
		if (msg) 				\
			break;				\
		for( i = mut->fvar; i<= mut->lvar; i++) {	\
			if( ATOMstorage(mut->args[i].type) != TYPE_str){ \
				args[i] += mut->args[i].size;		 \
			} else {			\
				mut->args[i].o++;	\
				mut->args[i].s = (str *) BUNtail(mut->args[i].bi, mut->args[i].o); \
				args[i] = (void*)  &mut->args[i].s;	 \
			}				\
		}					\
		v++;					\
	}						\
}

// The target BAT tail type determines the result variable
#define Manifoldbody(...) \
switch(ATOMstorage(mut->args[0].b->T->type)){\
case TYPE_bte: ManifoldLoop(bit,__VA_ARGS__); break;\
case TYPE_sht: ManifoldLoop(sht,__VA_ARGS__); break;\
case TYPE_int: ManifoldLoop(int,__VA_ARGS__); break;\
case TYPE_lng: ManifoldLoop(lng,__VA_ARGS__); break;\
case TYPE_oid: ManifoldLoop(oid,__VA_ARGS__); break;\
case TYPE_flt: ManifoldLoop(flt,__VA_ARGS__); break;\
case TYPE_dbl: ManifoldLoop(dbl,__VA_ARGS__); break;\
case TYPE_str: \
	for( ; p< q ; p += mut->args[mut->fvar].size){ 		\
		msg = (*mut->pci->fcn)(&y, __VA_ARGS__); 	\
		if (msg)					\
			break;					\
		bunfastapp(mut->args[0].b, (void*) y);	\
		for( i = mut->fvar; i<= mut->lvar; i++) {	\
			if( ATOMstorage(mut->args[i].type) !=  TYPE_str){\
				args[i] += mut->args[i].size;	\
			} else {				\
				mut->args[i].o++;		\
				mut->args[i].s = (str*) BUNtail(mut->args[i].bi, mut->args[i].o);\
				args[i] =  (void*) & mut->args[i].s; 	\
			}					\<commit_msg>manifold.c: fixed type: bit -> bte<commit_after>/*
 * 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://www.monetdb.org/Legal/MonetDBLicense
 *
 * 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-2014 MonetDB B.V.
 * All Rights Reserved.
 */

/*
 * <NAME>
 */
#include "monetdb_config.h"
#include "manifold.h"
#include "mal_resolve.h"
#include "mal_builder.h"

//#define _DEBUG_MANIFOLD_

/* The default iterator over known scalar commands.
 * It can be less efficient then the vector based implementations,
 * but saves quite some hacking in non-essential cases or
 * expensive user defined functions..
 *
 * To keep things simple and reasonably performant we limit the
 * implementation to those cases where a single BAT is returned.
 * Arguments may be of any type. The MAL signature should be a COMMAND.
 *
 */

typedef struct{
	BAT *b;
	void *first;
	void *last;
	int	size;
	int type;
	BATiter bi;
	BUN  o;
	BUN  q;
	str *s;
} MULTIarg;

typedef struct{
	Client cntxt;
	MalBlkPtr mb;
	MalStkPtr stk;
	InstrPtr pci;
	int fvar,lvar;
	MULTIarg *args;
} MULTItask;


// Loop through the first BAT
// keep the last error message received
#define ManifoldLoop(Type, ...) {			\
	Type *v = (Type*) mut->args[0].first; 		\
	for( ; p<q ; p += mut->args[mut->fvar].size){ 	\
		msg = (*mut->pci->fcn)(v, __VA_ARGS__); \
		if (msg) 				\
			break;				\
		for( i = mut->fvar; i<= mut->lvar; i++) {	\
			if( ATOMstorage(mut->args[i].type) != TYPE_str){ \
				args[i] += mut->args[i].size;		 \
			} else {			\
				mut->args[i].o++;	\
				mut->args[i].s = (str *) BUNtail(mut->args[i].bi, mut->args[i].o); \
				args[i] = (void*)  &mut->args[i].s;	 \
			}				\
		}					\
		v++;					\
	}						\
}

// The target BAT tail type determines the result variable
#define Manifoldbody(...) \
switch(ATOMstorage(mut->args[0].b->T->type)){\
case TYPE_bte: ManifoldLoop(bte,__VA_ARGS__); break;\
case TYPE_sht: ManifoldLoop(sht,__VA_ARGS__); break;\
case TYPE_int: ManifoldLoop(int,__VA_ARGS__); break;\
case TYPE_lng: ManifoldLoop(lng,__VA_ARGS__); break;\
case TYPE_oid: ManifoldLoop(oid,__VA_ARGS__); break;\
case TYPE_flt: ManifoldLoop(flt,__VA_ARGS__); break;\
case TYPE_dbl: ManifoldLoop(dbl,__VA_ARGS__); break;\
case TYPE_str: \
	for( ; p< q ; p += mut->args[mut->fvar].size){ 		\
		msg = (*mut->pci->fcn)(&y, __VA_ARGS__); 	\
		if (msg)					\
			break;					\
		bunfastapp(mut->args[0].b, (void*) y);	\
		for( i = mut->fvar; i<= mut->lvar; i++) {	\
			if( ATOMstorage(mut->args[i].type) !=  TYPE_str){\
				args[i] += mut->args[i].size;	\
			} else {				\
				mut->args[i].o++;		\
				mut->args[i].s = (str*) BUNtail(mut->args[i].bi, mut->args[i].o);\
				args[i] =  (void*) & mut->args[i].s; 	\
			}					\
{'fraction_non_alphanumeric': 0.1547600678907576, 'fraction_numerical': 0.006480481407190248, 'mean_word_length': 3.1954692556634305, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4309302', 'n_tokens_mistral': 2639, 'n_tokens_neox': 2401, 'n_words': 691}