From aba329310979832911cf0f93243e7c6d27a1fc5d Mon Sep 17 00:00:00 2001 From: olivier gayot Date: Thu, 13 Dec 2012 11:59:30 +0000 Subject: le_compte_est_bon: use const attribute with vectors We do not change the vectors at each reccursion, we create a new one instead, so we can set the source vectors to const. --- solver.c | 12 +++++++----- solver.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/solver.c b/solver.c index 27de4ca..d9eba10 100644 --- a/solver.c +++ b/solver.c @@ -30,10 +30,10 @@ typedef struct { } solution_t; static solution_t solution_g; -static vect_t *vect_g; +static const vect_t *vect_g; static int result; -static int closer = -1; +static int closer; /* {{{ display */ @@ -78,7 +78,7 @@ static void display_solution(void) /* }}} */ static inline -void construct_new_vect(vect_t *new_vect, vect_t *vect, unsigned v1, unsigned v2) +void construct_new_vect(vect_t *new_vect, const vect_t *vect, unsigned v1, unsigned v2) { unsigned j = 0; @@ -91,7 +91,7 @@ void construct_new_vect(vect_t *new_vect, vect_t *vect, unsigned v1, unsigned v2 } } -static void solve_rec(vect_t *vect) +static void solve_rec(const vect_t *vect) { vect_t new_vect; @@ -160,10 +160,12 @@ static void solve_rec(vect_t *vect) } /* public function to use */ -void solve(vect_t *vect, int _result) +void solve(const vect_t *vect, int _result) { + closer = -1; vect_g = vect; result = _result; + solution_g.computation = malloc(sizeof(computation_t) * vect->len); solution_g.level = 0; diff --git a/solver.h b/solver.h index 357cd91..7fe71b2 100644 --- a/solver.h +++ b/solver.h @@ -6,6 +6,6 @@ typedef struct { unsigned len; } vect_t; -void solve(vect_t *vect, int result); +void solve(const vect_t *vect, int result); #endif /* SOLVER_H */ -- cgit v1.2.3