From 88ff17de1673575b247da3374dedf8561716238e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 27 Jul 2014 20:16:07 +0200 Subject: fix multiple clients bug: minor bug in linked_list caused removal of old clients + add dump method for linked list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsserver/linked-list.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/libmdsserver/linked-list.c') diff --git a/src/libmdsserver/linked-list.c b/src/libmdsserver/linked-list.c index 4755ad4..066414a 100644 --- a/src/libmdsserver/linked-list.c +++ b/src/libmdsserver/linked-list.c @@ -342,7 +342,7 @@ ssize_t linked_list_insert_before(linked_list_t* restrict this, size_t value, ss if (node == LINKED_LIST_UNUSED) return LINKED_LIST_UNUSED; this->values[node] = value; - this->previous[node] = this->next[successor]; + this->previous[node] = this->previous[successor]; this->previous[successor] = node; this->next[node] = successor; this->next[this->previous[node]] = node; @@ -469,3 +469,38 @@ int linked_list_unmarshal(linked_list_t* restrict this, char* restrict data) return 0; } + +/** + * Print the content of the list + * + * @param this The list + * @param output Output file + */ +void linked_list_dump(linked_list_t* restrict this, FILE* output) +{ + ssize_t i; + size_t j; + fprintf(output, "======= LINKED LIST DUMP =======\n"); + fprintf(output, "Capacity: %lu\n", this->capacity); + fprintf(output, "End: %lu\n", this->end); + fprintf(output, "Reuse head: %lu\n", this->reuse_head); + fprintf(output, "Edge: %li\n", this->edge); + fprintf(output, "--------------------------------\n"); + fprintf(output, "Node table (Next, Prev, Value):\n"); + i = this->edge; + fprintf(output, " %li: %li, %li, %lu\n", i, this->next[i], this->previous[i], this->values[i]); + foreach_linked_list_node((*this), i) + fprintf(output, " %li: %li, %li, %lu\n", i, this->next[i], this->previous[i], this->values[i]); + i = this->edge; + fprintf(output, " %li: %li, %li, %lu\n", i, this->next[i], this->previous[i], this->values[i]); + fprintf(output, "--------------------------------\n"); + fprintf(output, "Raw node table:\n"); + for (j = 0; j < this->end; j++) + fprintf(output, " %lu: %li, %li, %lu\n", i, this->next[i], this->previous[i], this->values[i]); + fprintf(output, "--------------------------------\n"); + fprintf(output, "Reuse stack:\n"); + for (j = 0; j < this->reuse_head; j++) + fprintf(output, " %lu: %li\n", j, this->reusable[j]); + fprintf(output, "================================\n"); +} + -- cgit v1.2.3-70-g09d2