Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add IndexList::move_to_last to maintain ListIndex #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,16 @@ impl<T> IndexList<T> {
}
elem_opt
}
/// Move the element at the index to the end.
/// The index remains the same.
pub fn move_to_last(&mut self, index: ListIndex) {
if self.is_index_used(index) {
// unlink where it is
self.linkout_used(index);
// insert it as last
self.linkin_last(index);
}
}
/// Create a new iterator over all the elements.
///
/// Example:
Expand Down
1 change: 1 addition & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fn test_instantiate() {
list.split(null);
list.trim_safe();
list.trim_swap();
list.move_to_last(ListIndex::new())
}
#[test]
fn basic_insert_remove() {
Expand Down