Commit 01020cf2 authored by Giovanne Marcelo's avatar Giovanne Marcelo

add data prepare and matrix module

parent 6ae288fa
Pipeline #6342 passed with stage
in 4 minutes and 50 seconds
......@@ -38,8 +38,8 @@ CFLAGS = -std=c99 -g -O3 \
LFLAGS = -lpq -ljansson
INCL = -I./include
SRC = ./src
DEPS = ./include/db_interface.h ./include/log.h ./include/main.h
OBJ = db_interface.o log.o main.o
DEPS = ./include/db_interface.h ./include/log.h ./include/main.h ./include/data_prepare.h ./include/matrix.h
OBJ = db_interface.o log.o matrix.o data_prepare.o main.o
APP=recommender
all: $(APP)
......
#ifndef _DATA_PREPARE_H
#define _DATA_PREPARE_H
#include "matrix.h"
matrix cartesian_product(long unsigned int size_set_a, long unsigned int size_set_b);
#endif
......@@ -2,5 +2,6 @@
#define _MAIN_H
#include "db_interface.h"
#include "data_prepare.h"
#endif
#ifndef _MATRIX_H
#define _MATRIX_H
#include <stdlib.h>
#include <stdio.h>
typedef struct {
int ** data;
long unsigned int rows;
long unsigned int cols;
}matrix;
matrix matrix_alloc(long unsigned int rows, long unsigned int cols);
void print_matrix(matrix m);
#endif
/*
* Implementation of functions that building data structures from postgres database
*
* This source code is licensed under the GNU General Public License,
* Version 3. See the file LICENSE for more details.
*
*/
#include "data_prepare.h"
matrix cartesian_product(long unsigned int size_set_a, long unsigned int size_set_b) {
return matrix_alloc(size_set_a, size_set_b);
}
/*
* Implementation of functions that manipulate matrices
*
* This source code is licensed under the GNU General Public License,
* Version 3. See the file LICENSE for more details.
*
*/
#include "matrix.h"
matrix matrix_alloc(long unsigned int rows, long unsigned int cols) {
long unsigned int i;
matrix M;
M.rows = rows;
M.cols = cols;
M.data = (int **)malloc(M.rows * sizeof(int*));
for(i = 0; i < M.rows; i++) M.data[i] = (int *)malloc(M.cols * sizeof(int));
return M;
}
void print_matrix(matrix m) {
long unsigned int i,j;
for( i = 0; i < m.rows; i++) {
for( j = 0; j < m.cols; j++)
printf("%d ", m.data[i][j]);
printf("\n");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment