Refactor (update|set|remove|swap|split)At for efficiency #55
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.
I refactored
updateAt
,setAt
,removeAt
,swapAt
, andsplitAt
to make them more efficient. All of the functions are now tail-recursive. In the case of success (i.e. the index is in range), the functions perform two passes over the elements from the start of the list up to and including the given index (and in the case ofswapAt
the larger index). In the case of failure, the functions require only a single pass over the list.Closes #1 and the second part of #30. I also have a fast implementation for the proposed insertAt function that uses the atHelper, which would close the rest of #30 and #43. I also have another version of the code that changes the return types of
updateAt
,setAt
, andswapAt
in accordance with #32 and #36. Just let me know what you need and I can submit additional PRs or add to this one.