Removed debug messages from hashtable
This commit is contained in:
parent
f1a0bd9614
commit
3539cd9a71
1 changed files with 18 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Reference in a new issue