From 3539cd9a718100482be7139f330038ebe3ae0b98 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Wed, 11 Dec 2019 10:52:39 +0100 Subject: [PATCH] Removed debug messages from hashtable --- chess_paths/chess_paths.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/chess_paths/chess_paths.c b/chess_paths/chess_paths.c index e19457d..facdf6c 100644 --- a/chess_paths/chess_paths.c +++ b/chess_paths/chess_paths.c @@ -155,8 +155,8 @@ struct position* bishop_positions(const struct chessboard* board, struct position* queen_positions(const struct chessboard* c, struct piece_position* p) { - struct position* malusa = bishop_positions(c, p); - return rook_positions(c, p, malusa); + struct position* canotaggio = bishop_positions(c, p); + return rook_positions(c, p, canotaggio); } struct position* get_positions(const struct chessboard* c, @@ -262,7 +262,10 @@ struct row_list { }; typedef struct row_list* visit_table; + +#if DEBUG unsigned long alloc = 0; +#endif unsigned long table_total_size(const struct chessboard*); unsigned long table_hash(const struct chessboard*, unsigned, unsigned); @@ -273,12 +276,18 @@ inline unsigned long table_total_size(const struct chessboard* c) { inline unsigned long table_hash(const struct chessboard* c, unsigned col, unsigned row) { - return (value_at(c, col, row) ^ 0xDEADBEEF) % table_total_size(c); + return (value_at(c, col, row) ^ (('C'|'a') << 24 | ('r'|'z') << 16 | + ('a'|'n') << 8 | ('i'|'g'|'a'))) + % table_total_size(c); } visit_table* table_new(const struct chessboard* c) { unsigned long table_size = table_total_size(c); + +#if DEBUG alloc += sizeof(struct row_list*) * table_size; +#endif + return calloc(table_size, sizeof(struct row_list*)); } @@ -287,7 +296,11 @@ void table_visit(const struct chessboard* c, visit_table* visited, unsigned long hash = table_hash(c, column, row); struct row_list* prev = hash[visited]; + +#if DEBUG alloc += sizeof(struct row_list); +#endif + hash[visited] = malloc(sizeof(struct row_list)); assert(hash[visited] != NULL); hash[visited]->row = row; @@ -316,8 +329,10 @@ void table_destroy(const struct chessboard* c, visit_table* visited) { } } +#if DEBUG printf("alloc = %lu\n", alloc); alloc = 0; +#endif free(visited); }