void test24(void) { RowNode_handle pR1=0; int i,j; printf("\n===== DETERMINANT ==========================\n"); for(i=0;i<7;++i) { insert_element2(&pR1,i,i,2); for(j=i+1;j<7;++j) { insert_element2(&pR1,i,j,i+j); } } printf("Matrix \n"); printf_rows(pR1,"%i ",7); printf("\n"); printf("Determinant = %i\n",determinant(pR1,7)); free_rows(pR1); pR1=0; for(i=0;i<5;++i) { for(j=0;j<5;++j) { int s=i+j; if( s==2 || s==3 || s==7 || s==8 ) insert_element2(&pR1,i,j,1); } } printf("Matrix \n"); printf_rows(pR1,"%i ",5); printf("\n"); printf("Determinant = %i\n",determinant(pR1,5)); free_rows(pR1); }
/* * Convert rows from internal to db API representation */ int convert_rows(db_con_t* _h, db_res_t* _r) { int n, i; dbt_row_p _rp = NULL; if ((!_h) || (!_r)) { #ifdef DBT_EXTRA_DEBUG LOG(L_ERR, "DBT:convert_rows: Invalid parameter\n"); #endif return -1; } n = DBT_CON_RESULT(_h)->nrrows; RES_ROW_N(_r) = n; if (!n) { RES_ROWS(_r) = 0; return 0; } RES_ROWS(_r) = (struct db_row*)pkg_malloc(sizeof(db_row_t) * n); if (!RES_ROWS(_r)) { LOG(L_ERR, "DBT:convert_rows: No memory left\n"); return -2; } i = 0; _rp = DBT_CON_RESULT(_h)->rows; while(_rp) { DBT_CON_ROW(_h) = _rp; if (!DBT_CON_ROW(_h)) { LOG(L_ERR, "DBT:convert_rows: error getting current row\n"); RES_ROW_N(_r) = i; free_rows(_r); return -3; } if (convert_row(_h, _r, &(RES_ROWS(_r)[i])) < 0) { LOG(L_ERR, "DBT:convert_rows: Error while converting row #%d\n", i); RES_ROW_N(_r) = i; free_rows(_r); return -4; } i++; _rp = _rp->next; } return 0; }
void test21(void) { RowNode_handle pR=0; int i,j=0; printf("\n== OVERWRITE ENTIRE ROW 9 WITH ZEROES ==\n"); for(i=0;i<10;++i) { for(j=0;j<10;++j) { insert_element2(&pR,i,j,(i+j)%3); } } printf_rows(pR,"%i",10); printf("\n"); insert_element2(&pR,3*i,3*j,(3*i+2*j)%5); insert_element2(&pR,9,0,0); insert_element2(&pR,9,1,0); insert_element2(&pR,9,2,0); insert_element2(&pR,9,3,0); insert_element2(&pR,9,4,0); insert_element2(&pR,9,5,0); insert_element2(&pR,9,6,0); insert_element2(&pR,9,7,0); insert_element2(&pR,9,8,0); insert_element2(&pR,9,9,0); printf_rows(pR,"%i",10); printf("\n"); print_rows(pR); printf("\n"); free_rows(pR); }
void test18(void) { RowNode_handle pR=0; int i,j; printf("\n== INSERT ELEMENTS IN ROW LIST (WITH ZEROES AND OVERWRITES) ==\n"); for(i=0;i<30;++i) { for(j=0;j<30;++j) { insert_element2(&pR,i,j,(i+j)%2); } } printf_rows(pR,"%i",30); printf("\n"); /* overwrite some */ for(i=0;i<10;++i) { for(j=0;j<10;++j) { insert_element2(&pR,3*i,3*j,(3*i+2*j)%5); } } /* overwrite with 0 */ for(i=0;i<30;++i) { for(j=0;j<30;++j) { if ((i+j)%8==0) insert_element2(&pR,i,j,0); } } printf_rows(pR,"%i",30); printf("\n"); print_rows(pR); printf("\n"); free_rows(pR); }
void test15(void) { ElementNode_handle pE1=0,pE2=0,pE3=0; RowNode_handle pR=0; int i; printf("\n====== INSERT ROWS MIDDLE =========================\n"); for(i=0;i<5;++i) insert_element(&pE1,2*i,10*i-50); printf_elements(pE1,"%4d",10); printf("\n"); for(i=0;i<20;++i) insert_element(&pE2,20-i,i); printf_elements(pE2,"%4d",10); printf("\n"); for(i=0;i<10;++i) { if (i%2) insert_element(&pE3,i,i); else insert_element(&pE3,10-i,-i); } insert_row(&pR,8,pE3); printf("after insert:\n"); printf_rows(pR,"%4i",10); printf("\n"); insert_row(&pR,0,pE1); printf("after insert:\n"); printf_rows(pR,"%4i",10); printf("\n"); insert_row(&pR,5,pE2); printf("after insert:\n"); printf_rows(pR,"%4i",10); printf("\n"); free_rows(pR); }
void test23(void) { RowNode_handle pR1=0,pR2=0,pR3,pR4,pR5; int i; printf("\n===== MULTIPLICATION =======================\n"); for(i=0;i<7;++i) insert_element2(&pR1,i,i,1); insert_element2(&pR1,0,6,1); printf("Matrix 1\n"); printf_rows(pR1,"%i ",7); printf("\n"); for(i=0;i<7;++i) insert_element2(&pR2,i,i,1); insert_element2(&pR2,0,6,1); printf("Matrix 2\n"); printf_rows(pR2,"%i ",7); printf("\n"); pR3=mult(pR1,pR2); printf("Power 2\n"); printf_rows(pR3,"%i ",7); printf("\n"); pR4=mult(pR1,pR3); printf("Power 3\n"); printf_rows(pR4,"%i ",7); printf("\n"); pR5=mult(pR4,pR4); printf("Power 6\n"); printf_rows(pR5,"%i ",7); printf("\n"); /* for(i=0;i<1;++i) { printf("Power %d\n",i+3); temp=pR3; pR3=mult(pR1,pR3); free(temp); printf_rows(pR3,"%i ",7); printf("\n"); } */ free_rows(pR1); free_rows(pR2); free_rows(pR3); free_rows(pR4); free_rows(pR5); }
void test22( void ) { RowNode * pR=0, *pR2; int i,j; printf( "\n===== TRANSPOSITION ========================\n" ); for( i=0; i<10; ++i ) { for( j=0; j<10; ++j ) { if( ( i+j )%4 ) insert_element2( &pR,1000*i,1000*j,10*i+j ); } } pR2 = transpose( pR ); printf( "original as list of rows\n" ); print_rows( pR ); printf( "\n" ); printf( "transposed as list of rows\n" ); print_rows( pR2 ); printf( "\n" ); free_rows( pR ); free_rows( pR2 ); }
void test17(void) { RowNode_handle pR=0; int i,j; printf("\n====== INSERT ELEMENTS IN ROW LIST (WITH ZEROES) ===\n"); for(i=0;i<30;++i) { for(j=0;j<30;++j) { insert_element2(&pR,i,j,(i+j)%2); } } printf_rows(pR,"%i",30); printf("\n"); print_rows(pR); printf("\n"); free_rows(pR); }
/* * Release memory used by a result structure */ int free_result(db_res_t* _r) { if (!_r) { #ifdef DBT_EXTRA_DEBUG LOG(L_ERR, "DBT:free_result: Invalid parameter\n"); #endif return -1; } free_columns(_r); free_rows(_r); pkg_free(_r); return 0; }
void test16(void) { RowNode_handle pR=0; int i,j; printf("\n====== INSERT ELEMENTS IN ROW LIST =========\n"); for(i=0;i<15;++i) { for(j=0;j<10;++j) { insert_element2(&pR,2*i,3*j,1+7*( (i+j)%2) ); } } printf_rows(pR,"%i",30); printf("\n"); print_rows(pR); free_rows(pR); }
static void teardown_cb(void *data) { free_rows(&pi); input_free(&ds); }