Skip to content

Commit

Permalink
added subsetting functionality to c approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad1991 committed Jul 11, 2024
1 parent ef03633 commit a840642
Show file tree
Hide file tree
Showing 21 changed files with 711 additions and 438 deletions.
22 changes: 22 additions & 0 deletions .development/cApproach/Colon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "Colon.h"

void colon_numeric(size_t vec_index, double start, double end,
VectorManager *vm) {
if (end == start) {
free(vm->numerics[vec_index].data);
vm->numerics[vec_index].data = NULL;
vm->numerics[vec_index].size = 0;
} else if (end > start) {
int size = end - start + 1;
alloc_numeric(vec_index, size, vm);
for (int i = 0; i < vm->numerics[vec_index].size; i++) {
vm->numerics[vec_index].data[i] = start + (double)(i);
}
} else if (start > end) {
int size = start - end + 1;
alloc_numeric(vec_index, size, vm);
for (int i = end; i >= start; i--) {
vm->numerics[vec_index].data[i] = (double)(i);
}
}
}
9 changes: 9 additions & 0 deletions .development/cApproach/Colon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "VectorManager.h"

#ifndef COLON_H
#define COLON_H

void colon_numeric(size_t vec_index, double start, double end,
VectorManager *vm);

#endif
6 changes: 4 additions & 2 deletions .development/cApproach/CreateSymbolTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ source("Utils.R")


check_expr <- function(code) {
if (grepl("EXPR", deparse(code)) || grepl("VAR", deparse(code))) {
stop("Variables are not allowed to have 'EXPR' or 'VAR' within their names")
if (grepl("EXPR", deparse(code)) || grepl("VAR", deparse(code)) ||
grepl("SUBSET", deparse(code))) {
stop("Variables are not allowed to have 'EXPR', 'SUBSET'
or 'VAR' within their names")
}
}

Expand Down
33 changes: 33 additions & 0 deletions .development/cApproach/DetermineSize.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "DetermineSize.h"

size_t determine_size(VectorManager *vm, int *num_vars, int *types_vars,
int n) {
if (n == 0)
return 0;

size_t size = 0;
if (types_vars[0] == 0) {
size = vm->logicals[num_vars[0]].size;
} else if (types_vars[1] == 1) {
size = vm->integers[num_vars[0]].size;
} else if (types_vars[2] == 2) {
size = vm->numerics[num_vars[0]].size;
}

for (int i = 0; i < n; i++) {
if (types_vars[i] == 0) {
if (vm->logicals[num_vars[i]].size > size) {
size = vm->logicals[num_vars[i]].size;
}
} else if (types_vars[i] == 1) {
if (vm->integers[num_vars[i]].size > size) {
size = vm->integers[num_vars[i]].size;
}
} else if (types_vars[i] == 2) {
if (vm->numerics[num_vars[i]].size > size) {
size = vm->numerics[num_vars[i]].size;
}
}
}
return size;
}
8 changes: 8 additions & 0 deletions .development/cApproach/DetermineSize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "VectorManager.h"

#ifndef DETERMINE_SIZE_H
#define DETERMINE_SIZE_H

size_t determine_size(VectorManager *vm, int *num_vars, int *types_vars, int n);

#endif
67 changes: 67 additions & 0 deletions .development/cApproach/GetAndSet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "GetAndSet.h"

double get_num(size_t index, size_t vec_index, VectorManager *vm) {
if (index >= vm->numerics[vec_index].size || index < 0) {
free_and_exit(vm, "Index out of bounds");
}
return vm->numerics[vec_index].data[index % vm->numerics[vec_index].size];
}

double *set_num(size_t index, size_t vec_index, VectorManager *vm) {
if (index >= vm->numerics[vec_index].size || index < 0) {
free_and_exit(vm, "Index out of bounds");
}
return &vm->numerics[vec_index].data[index % vm->numerics[vec_index].size];
}

double get_scalar_num(size_t vec_index, VectorManager *vm) {
return vm->scalarNums[vec_index];
}

double *set_scalar_num(size_t vec_index, VectorManager *vm) {
return &vm->scalarNums[vec_index];
}

int get_int(size_t index, size_t vec_index, VectorManager *vm) {
if (index >= vm->integers[vec_index].size || index < 0) {
free_and_exit(vm, "Index out of bounds");
}
return vm->integers[vec_index].data[index % vm->integers[vec_index].size];
}

int *set_int(size_t index, size_t vec_index, VectorManager *vm) {
if (index >= vm->integers[vec_index].size || index < 0) {
free_and_exit(vm, "Index out of bounds");
}
return &vm->integers[vec_index].data[index % vm->integers[vec_index].size];
}

int get_scalar_int(size_t vec_index, VectorManager *vm) {
return vm->scalarInts[vec_index];
}

int *set_scalar_int(size_t vec_index, VectorManager *vm) {
return &vm->scalarInts[vec_index];
}

bool get_log(size_t index, size_t vec_index, VectorManager *vm) {
if (index >= vm->logicals[vec_index].size || index < 0) {
free_and_exit(vm, "Index out of bounds");
}
return vm->logicals[vec_index].data[index % vm->logicals[vec_index].size];
}

bool *set_log(size_t index, size_t vec_index, VectorManager *vm) {
if (index >= vm->logicals[vec_index].size || index < 0) {
free_and_exit(vm, "Index out of bounds");
}
return &vm->logicals[vec_index].data[index % vm->logicals[vec_index].size];
}

bool get_scalar_log(size_t vec_index, VectorManager *vm) {
return vm->scalarLogs[vec_index];
}

bool *set_scalar_log(size_t vec_index, VectorManager *vm) {
return &vm->scalarLogs[vec_index];
}
20 changes: 20 additions & 0 deletions .development/cApproach/GetAndSet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "VectorManager.h"
#include "header.h"

#ifndef GET_SET_H
#define GET_SET_H

double get_num(size_t index, size_t vec_index, VectorManager *vm);
double *set_num(size_t index, size_t vec_index, VectorManager *vm);
double get_scalar_num(size_t vec_index, VectorManager *vm);
double *set_scalar_num(size_t vec_index, VectorManager *vm);
int get_int(size_t index, size_t vec_index, VectorManager *vm);
int *set_int(size_t index, size_t vec_index, VectorManager *vm);
int get_scalar_int(size_t vec_index, VectorManager *vm);
int *set_scalar_int(size_t vec_index, VectorManager *vm);
bool get_log(size_t index, size_t vec_index, VectorManager *vm);
bool *set_log(size_t index, size_t vec_index, VectorManager *vm);
bool get_scalar_log(size_t vec_index, VectorManager *vm);
bool *set_scalar_log(size_t vec_index, VectorManager *vm);

#endif
9 changes: 7 additions & 2 deletions .development/cApproach/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CC = gcc
CFLAGS = -Wall -g

SRCS = main.c SubsetManager.c VectorManager.c
SRCS = main.c Print.c VectorManager.c GetAndSet.c Colon.c DetermineSize.c Subsets.c
OBJS = $(SRCS:.c=.o)

TARGET = main
Expand All @@ -13,8 +13,13 @@ $(TARGET): $(OBJS)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

SubsetManager.o: VectorManager.h
Print.o: VectorManager.h
VectorManager.o: VectorManager.h
GetAndSet.o: VectorManager.h
Colon.o: VectorManager.h
DetermineSize.o: VectorManager.h
Subsets.o: VectorManager.h


# Clean up
clean:
Expand Down
31 changes: 31 additions & 0 deletions .development/cApproach/Print.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "Print.h"

void print_numeric(size_t vec_idx, VectorManager *vm) {
for (int i = 0; i < vm->numerics[vec_idx].size; i++) {
printf("%f\n", vm->numerics[vec_idx].data[i]);
}
}

void print_integer(size_t vec_idx, VectorManager *vm) {
for (int i = 0; i < vm->integers[vec_idx].size; i++) {
printf("%d\n", vm->integers[vec_idx].data[i]);
}
}

void print_logical(size_t vec_idx, VectorManager *vm) {
for (int i = 0; i < vm->logicals[vec_idx].size; i++) {
printf("%i\n", vm->logicals[vec_idx].data[i]);
}
}

void print_scalar_numeric(size_t vec_idx, VectorManager *vm) {
printf("%f\n", vm->scalarNums[vec_idx]);
}

void print_scalar_integer(size_t vec_idx, VectorManager *vm) {
printf("%d\n", vm->scalarInts[vec_idx]);
}

void print_scalar_logical(size_t vec_idx, VectorManager *vm) {
printf("%d\n", vm->scalarLogs[vec_idx]);
}
14 changes: 14 additions & 0 deletions .development/cApproach/Print.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "VectorManager.h"
#include "header.h"

#ifndef PRINT_H
#define PRINT_H

void print_numeric(size_t vec_idx, VectorManager *vm);
void print_integer(size_t vec_idx, VectorManager *vm);
void print_logical(size_t vec_idx, VectorManager *vm);
void print_scalar_numeric(size_t vec_idx, VectorManager *vm);
void print_scalar_integer(size_t vec_idx, VectorManager *vm);
void print_scalar_logical(size_t vec_idx, VectorManager *vm);

#endif
134 changes: 0 additions & 134 deletions .development/cApproach/SubsetManager.c

This file was deleted.

Loading

0 comments on commit a840642

Please sign in to comment.