Changeset: e4a7a8670c92 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e4a7a8670c92
Modified Files:
sql/backends/monet5/bam/bam_loader.c
Branch: DVframework_bam
Log Message:
Used sht and bit datatypes instead of int whereever possible
diffs (truncated from 330 to 300 lines):
diff --git a/sql/backends/monet5/bam/bam_loader.c
b/sql/backends/monet5/bam/bam_loader.c
--- a/sql/backends/monet5/bam/bam_loader.c
+++ b/sql/backends/monet5/bam/bam_loader.c
@@ -31,8 +31,8 @@ typedef struct {
str schema_name; /* schema or vault name */
_temp_subcontainer *tables_columns; /* keeps tables: higher array */
str *table_names; /* names of tables that are kept in the higher array
*/
- int *num_columns; /* number of columns in each table in the higher
array */
- int num_tables;
+ sht *num_columns; /* number of columns in each table in the higher
array */
+ sht num_tables;
} _temp_container;
/*
@@ -46,7 +46,7 @@ typedef struct {
typedef struct {
char header_tag[3];
_bam_header_option *options;
- int num_options;
+ sht num_options;
} _bam_header_line;
@@ -56,11 +56,11 @@ FILE *_logfile = NULL; /* keep _logfile
/* since opening and closing every time something has
to be written turned out to be very slow */
/* SQL schema details that are common to every schema */
-int _num_col_files = 5;
-int _num_col_sq = 7;
-int _num_col_rg = 13;
-int _num_col_pg = 6;
-int _num_col_alignments_extra = 5;
+sht _num_col_files = 5;
+sht _num_col_sq = 7;
+sht _num_col_rg = 13;
+sht _num_col_pg = 6;
+sht _num_col_alignments_extra = 5;
str _coln_files[] = {"file_id", "file_location", "format_version",
"sorting_order", "comments"};
int _colt_files[] = {TYPE_sht , TYPE_str , TYPE_flt , TYPE_str
, TYPE_str };
@@ -82,24 +82,24 @@ int _colt_alignments_extra[] = {TYPE_st
/* File format specific functions */
static str _next_file_id(Client cntxt, MalBlkPtr mb, sht *next_file_id);
-static str _init_temp_container(_temp_container *ret_tc, int dbschema);
+static str _init_temp_container(_temp_container *ret_tc, sht dbschema);
static str _init_temp_container_simple(_temp_container *ret_tc);
-static str _loadfile(str filepath, _temp_container *ret_tc, int dbschema, int
file_id); /* load file and add contents to ret_tc */
-static str _process_bam_header(int file_id, str header, _temp_container
*ret_tc);
-static int _append_option_to_bat_cond_lng(_temp_container *ret_tc,
_bam_header_option *opt, str cmp, int table, int col, int *appendErr, int
*flag);
-static int _append_option_to_bat_cond_flt(_temp_container *ret_tc,
_bam_header_option *opt, str cmp, int table, int col, int *appendErr, int
*flag);
-static int _append_option_to_bat(_temp_container *ret_tc, ptr value, int
table, int col, int *appendErr, int *flag);
-static str _read_bam_header_line(str *header, _bam_header_line *ret_hl, int
*eof);
+static str _loadfile(str filepath, _temp_container *ret_tc, sht dbschema, sht
file_id); /* load file and add contents to ret_tc */
+static str _process_bam_header(sht file_id, str header, _temp_container
*ret_tc);
+static bit _append_option_to_bat_cond_lng(_temp_container *ret_tc,
_bam_header_option *opt, str cmp, sht table, sht col, bit *appendErr, bit
*flag);
+static bit _append_option_to_bat_cond_flt(_temp_container *ret_tc,
_bam_header_option *opt, str cmp, sht table, sht col, bit *appendErr, bit
*flag);
+static bit _append_option_to_bat(_temp_container *ret_tc, ptr value, sht
table, sht col, bit *appendErr, bit *flag);
+static str _read_bam_header_line(str *header, _bam_header_line *ret_hl, bit
*eof);
static void _free_bam_header_line(_bam_header_line *hl);
-static str _process_bam_alignment(int file_id, lng virtual_offset,
bam_header_t *header, bam1_t *alignment, _temp_container *ret_tc, int schema);
-static int _parse_alignment_str(str *sam_alig, str *dest);
-static int _parse_alignment_lng(str *sam_alig, lng *dest);
+static str _process_bam_alignment(sht file_id, lng virtual_offset,
bam_header_t *header, bam1_t *alignment, _temp_container *ret_tc, sht schema);
+static bit _parse_alignment_str(str *sam_alig, str *dest);
+static bit _parse_alignment_lng(str *sam_alig, lng *dest);
/* Generic functions */
-static str _init_temp_subcontainer(_temp_subcontainer *ret_tsc, str
*col_names, int *col_types, int num_cols);
+static str _init_temp_subcontainer(_temp_subcontainer *ret_tsc, str
*col_names, int *col_types, sht num_cols);
static str _insert_into_vault(Client cntxt, _temp_container* tc);
-static int _read_string_until_delim(str *src, str *ret, char *delims, int
num_delims);
-static int _parse_lng(str *src, lng *i);
+static int _read_string_until_delim(str *src, str *ret, char *delims, sht
num_delims);
+static bit _parse_lng(str *src, lng *i);
static void _append_to_log(str mssg);
static void _free_temp_container(_temp_container* tc);
@@ -115,8 +115,8 @@ bam_loader(Client cntxt, MalBlkPtr mb, M
/* function that e.g. receives the file format for which a DV should be
initialized as an argument */
str *repo_path = (str*) getArgReference(stk,pci,pci->retc); /* arg 1:
repo_path, used as filepath right now */
- int dbschema = *(int*) getArgReference(stk,pci,pci->retc+1); /* arg 2:
schema to use, see bam_loader.h for possible options */
- int num_threads = *(int*) getArgReference(stk,pci,pci->retc+2); /* arg
3: 1: no threads, >1: multi-threaded */
+ sht dbschema = *(sht*) getArgReference(stk,pci,pci->retc+1); /* arg 2:
schema to use, see bam_loader.h for possible options */
+ sht num_threads = *(sht*) getArgReference(stk,pci,pci->retc+2); /* arg
3: 1: no threads, >1: multi-threaded */
sht next_file_id = 0;
@@ -179,7 +179,7 @@ static str
}
static str
-_init_temp_container(_temp_container *ret_tc, int dbschema)
+_init_temp_container(_temp_container *ret_tc, sht dbschema)
{
if(dbschema == DBSCHEMA_SIMPLE)
return _init_temp_container_simple(ret_tc);
@@ -192,15 +192,15 @@ static str
{
str err = NULL;
- int num_tables = 6;
- int num_col_alignments = 13;
+ sht num_tables = 6;
+ sht num_col_alignments = 13;
_temp_subcontainer *tscs =
(_temp_subcontainer*)GDKmalloc(num_tables*sizeof(_temp_subcontainer));
str table_names[] = {"files" , "sq" , "rg" , "pg" ,
"alignments" , "alignments_extra" };
- int num_cols[] = {_num_col_files, _num_col_sq, _num_col_rg,
_num_col_pg, num_col_alignments, _num_col_alignments_extra};
+ sht num_cols[] = {_num_col_files, _num_col_sq, _num_col_rg,
_num_col_pg, num_col_alignments, _num_col_alignments_extra};
- int t; /* for loop var */
+ sht t; /* for loop var */
str coln_alignments[] = {"virtual_offset", "file_id", "qname" , "flag"
, "rname" , "pos" , "mapq" , "cigar" , "rnext" , "pnext" , "tlen" , "seq"
, "qual" };
int colt_alignments[] = {TYPE_lng , TYPE_sht , TYPE_str,
TYPE_sht, TYPE_str, TYPE_int, TYPE_sht, TYPE_str, TYPE_str, TYPE_int, TYPE_int,
TYPE_str, TYPE_str};
@@ -226,7 +226,7 @@ static str
/* set table_names and num_columns */
ret_tc->table_names = (str*) GDKmalloc(num_tables*sizeof(str));
- ret_tc->num_columns = (int*) GDKmalloc(num_tables*sizeof(int));
+ ret_tc->num_columns = (sht*) GDKmalloc(num_tables*sizeof(sht));
if(ret_tc->table_names == NULL || ret_tc->num_columns == NULL)
throw(MAL, "init_temp_container", MAL_MALLOC_FAIL);
@@ -244,7 +244,7 @@ static str
}
static str
-_loadfile(str filepath, _temp_container *ret_tc, int dbschema, int file_id)
+_loadfile(str filepath, _temp_container *ret_tc, sht dbschema, sht file_id)
{
bamFile input;
bam_header_t *header;
@@ -315,7 +315,7 @@ static str
}
static str
-_process_bam_header(int file_id, str header, _temp_container *ret_tc)
+_process_bam_header(sht file_id, str header, _temp_container *ret_tc)
{
/* TODO: consider checking whether or not floating point conversions
succeeded */
_bam_header_line *hl;
@@ -323,16 +323,16 @@ static str
str err = NULL;
/* declare variables for checking mandatory fields */
- int appendErr = FALSE;
+ bit appendErr = FALSE;
int num_hd_lines = 0; /* used to restrict the total number of header
fields */
str comment = "";
str commentRealloc;
int newCommentLength;
- int hd_fields_found[2];
- int sq_fields_found[6];
- int rg_fields_found[12];
- int pg_fields_found[5];
- int eof = FALSE;
+ bit hd_fields_found[2];
+ bit sq_fields_found[6];
+ bit rg_fields_found[12];
+ bit pg_fields_found[5];
+ bit eof = FALSE;
/* loop will run until no more header lines are found */
while(TRUE)
@@ -565,8 +565,8 @@ static str
}
-static int
-_append_option_to_bat_cond_lng(_temp_container *ret_tc, _bam_header_option
*opt, str cmp, int table, int col, int *appendErr, int *flag)
+static bit
+_append_option_to_bat_cond_lng(_temp_container *ret_tc, _bam_header_option
*opt, str cmp, sht table, sht col, bit *appendErr, bit *flag)
{
lng l;
if(strcmp(opt->tag, cmp) != 0)
@@ -576,7 +576,8 @@ static int
return _append_option_to_bat(ret_tc, (ptr)&l, table, col, appendErr, flag);
}
-static int _append_option_to_bat_cond_flt(_temp_container *ret_tc,
_bam_header_option *opt, str cmp, int table, int col, int *appendErr, int *flag)
+static bit
+_append_option_to_bat_cond_flt(_temp_container *ret_tc, _bam_header_option
*opt, str cmp, sht table, sht col, bit *appendErr, bit *flag)
{
float f;
if(strcmp(opt->tag, cmp) != 0)
@@ -585,8 +586,8 @@ static int _append_option_to_bat_cond_fl
return _append_option_to_bat(ret_tc, (ptr)&f, table, col, appendErr, flag);
}
-static int
-_append_option_to_bat(_temp_container *ret_tc, ptr value, int table, int col,
int *appendErr, int *flag)
+static bit
+_append_option_to_bat(_temp_container *ret_tc, ptr value, sht table, sht col,
bit *appendErr, bit *flag)
{
if(BUNappend(ret_tc->tables_columns[table].column_bats[col], value, TRUE)
== NULL)
{
@@ -599,10 +600,10 @@ static int
}
static str
-_read_bam_header_line(str *header, _bam_header_line *ret_hl, int *eof)
+_read_bam_header_line(str *header, _bam_header_line *ret_hl, bit *eof)
{
_bam_header_option *opt;
- int num_options = 0;
+ sht num_options = 0;
/* start by stripping \n, \r, \t and spaces */
while(**header == '\n' || **header == '\r' || **header == '\t' || **header
== ' ')
@@ -693,7 +694,7 @@ static str
static void
_free_bam_header_line(_bam_header_line *hl)
{
- int o;
+ sht o;
if(hl == NULL)
return;
@@ -708,7 +709,7 @@ static void
}
static str
-_process_bam_alignment(int file_id, lng virtual_offset, bam_header_t *header,
bam1_t *alignment, _temp_container *ret_tc, int dbschema)
+_process_bam_alignment(sht file_id, lng virtual_offset, bam_header_t *header,
bam1_t *alignment, _temp_container *ret_tc, sht dbschema)
{
str err = NULL;
str qname, rname, cigar, rnext, seq, qual;
@@ -791,7 +792,7 @@ static str
return MAL_SUCCEED;
}
-static int
+static bit
_parse_alignment_str(str *sam_alig, str *dest)
{
if(_read_string_until_delim(sam_alig, dest, "\t\n\0", 3) > 0)
@@ -805,7 +806,7 @@ static int
return FALSE;
}
-static int
+static bit
_parse_alignment_lng(str *sam_alig, lng *dest)
{
if(_parse_lng(sam_alig, dest))
@@ -823,11 +824,11 @@ static int
/* Generic functions */
static str
-_init_temp_subcontainer(_temp_subcontainer *ret_tsc, str *col_names, int
*col_types, int num_cols)
+_init_temp_subcontainer(_temp_subcontainer *ret_tsc, str *col_names, int
*col_types, sht num_cols)
{
/* generate empty bat for every column */
BAT **bats = (BAT **)GDKmalloc(num_cols*sizeof(BAT *));
- int c;
+ sht c;
if(bats == NULL)
throw(MAL, "_init_temp_subcontainer", MAL_MALLOC_FAIL);
@@ -858,7 +859,8 @@ static str
return MAL_SUCCEED;
}
-/*static str
+/* BAT** now stored explicitly in temp_container
+static str
_append_to_bat(bat cb, ptr val)
{
BAT *aBAT = NULL;
@@ -883,7 +885,7 @@ static str
/* form a sql query str like this: */
/* INSERT INTO bam.files SELECT * FROM bam_files_reg(ticket, table_idx); */
- int t;
+ sht t;
lng ticket = (lng) (size_t) tc;
str msg;
@@ -922,9 +924,9 @@ static str
str
register_table(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- int c;
+ sht c;
lng ticket = *(lng*) getArgReference(stk,pci,pci->retc); /* arg 1:
ticket to the _temp_container */
- int table_idx = *(int*) getArgReference(stk,pci,pci->retc+1); /* arg 2:
index of the table to be registered in the _temp_container */
+ sht table_idx = *(sht*) getArgReference(stk,pci,pci->retc+1); /* arg 2:
index of the table to be registered in the _temp_container */
_temp_container *tc = (_temp_container*) (size_t) ticket; /* filled
_temp_container taken */
@@ -947,7 +949,7 @@ register_table(Client cntxt, MalBlkPtr m
/* returns strlen(ret) or -1 when GDKmalloc on *ret fails */
static int
-_read_string_until_delim(str *src, str *ret, char *delims, int num_delims)
+_read_string_until_delim(str *src, str *ret, char *delims, sht num_delims)
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list