Fix bug in split_before and split_after for first and last node edge cases#19
Open
morlinbrot wants to merge 1 commit intocontain-rs:masterfrom
Open
Fix bug in split_before and split_after for first and last node edge cases#19morlinbrot wants to merge 1 commit intocontain-rs:masterfrom
morlinbrot wants to merge 1 commit intocontain-rs:masterfrom
Conversation
Author
|
Note the differences in implementation between this and the same fix over at too-many-lists. |
|
I've checked your new solution - it looks like all stuff works fine:
|
Contributor
|
I'll look into this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18
The
split_beforeandsplit_aftermethods don't handle the edge case of being at the first or last node correctly.Example
split_before:In the current implementation,
output_frontwill be set to the list's head before checking if there actually is a node before where the cursor currently is, which in the case of being at the first node will not be the case. In this case, we want to return an empty list which can be done by simply not setting a new head.I tried to implement a fix as unobtrusive to the original implementation as possible, since I assume that the methods are written with readability in mind for the too-many-lists project. In my implementation, I wrote the methods a bit more "cleverly" which may be not as easy to follow but shorter and more focused on all the edge cases that need to be covered, here's a snippet of it:
Let me know if you'd be interested in switching to my implementation, I'd be glad to update the PR.