WIP: add IndexList::move_to_last
to maintain ListIndex
#4
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.
This is a work in progress. I will need help discussing if you require something more than this. I need to write a doc example if you find the basics of this PR acceptable. I can also write unit tests for this method. I am holding off on those until I get a preliminary review. Thank you.
There is value for the API to allow an entry in the list to be moved to the end of the linked list while maintaining the same index.
An example use case is implementing an LRU algorithm.
When an entry is found in a separate
HashMap
, we need to move the corresponding LRU queue entry to the end of the linked list. When necessary, we evict from the head of the linked list.The current implementation requires a call to:
This requires a mutable reference to the entry in the
HashMap
which holds the index in the linked list.This new method,
move_to_last(index)
updates the linked list such that the entry atindex
is now the last entry in the linked list. The index of the entry remains the same.