Skip to content

Fixing our DoublyLinkedList#775

Merged
TheJJ merged 1 commit into
SFTtech:masterfrom
castilma:ddlfix
Apr 3, 2017
Merged

Fixing our DoublyLinkedList#775
TheJJ merged 1 commit into
SFTtech:masterfrom
castilma:ddlfix

Conversation

@castilma

@castilma castilma commented Apr 2, 2017

Copy link
Copy Markdown

Our (currently unused) DoublyLinkedList had some real issues.
While writing tests, I discovered many things, but the real interesting things were those, that should have raised a compilation error, but didn't. I guess they didn't, because we defined everything in a header and the functions containing uncompilable code were never called(referenced).

I'm not exactly sure, what we can learn from this.
I would suggest using header files for declaration and a separate file for definition. When trying to create doubly_linked_list.o from doubly_linked_list.cpp, that should have raised an error.
Besides that: If we keep everything in one header, doesn't that lead to every compilation unit recreating the machine code for that class?


if (this->last == node) {
this->last = new_node;
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like insert_after(), I'm not sure, if we want to make insert_*() check for this, or let the caller take responsibility for that case.

}
current = current->next;
} while (current != this->end);
} while (current != this->last);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last and first maybe should be callled back and front.

void clear() {
node_t *delete_now = this->first;
while (this->node_count > 0) {
node_t *deleted_next = this->first->next;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just wrong.

void erase(node_t *node) {
node->previous->next = node->next;
node->next->previous = node->previous;
assert(this->node_count != 0);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this assert?

* O(1)
* @pre \p node belongs to this list.
*/
void erase(node_t *node) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the erase() functions to correct the first/last pointer if necessary?
there can be a protected unlink() function, which does the same without setting first and last.

@TheJJ

TheJJ commented Apr 2, 2017

Copy link
Copy Markdown
Member

I added that list back when I was writing the heap, mainly as i was toying with fibonacci heaps. If it is unused now, we should just remove it?

@castilma

castilma commented Apr 2, 2017

Copy link
Copy Markdown
Author

I'm a fan of removing code. I'd say yes.

@TheJJ

TheJJ commented Apr 2, 2017

Copy link
Copy Markdown
Member

K, go for it :)

@castilma castilma changed the title [WIP] Fixing our DoublyLinkedList Fixing our DoublyLinkedList Apr 2, 2017
@TheJJ TheJJ merged commit 86fbd63 into SFTtech:master Apr 3, 2017
@TheJJ

TheJJ commented Apr 3, 2017

Copy link
Copy Markdown
Member

Fixed by removal 😛

@TheJJ TheJJ added bugfix Restores intended behavior lang: c++ Done in C++ code labels Apr 3, 2017
@castilma castilma deleted the ddlfix branch April 3, 2017 13:13
@castilma castilma restored the ddlfix branch April 3, 2017 13:13
@castilma castilma deleted the ddlfix branch April 3, 2017 13:13
@zuntrax

zuntrax commented Apr 6, 2017

Copy link
Copy Markdown
Contributor

Fix by removal is best fix indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Restores intended behavior lang: c++ Done in C++ code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants