Skip to content

Add pop_first and pop_last to RedBlackTreeSet - #115

Open
ChrisJr404 wants to merge 1 commit into
orium:mainfrom
ChrisJr404:pop-first-last-rbtset
Open

Add pop_first and pop_last to RedBlackTreeSet#115
ChrisJr404 wants to merge 1 commit into
orium:mainfrom
ChrisJr404:pop-first-last-rbtset

Conversation

@ChrisJr404

Copy link
Copy Markdown

This adds pop_first/pop_last (and their _mut counterparts) to RedBlackTreeSet, closing #35, so removing the smallest or largest element and getting it back can be done in one call instead of a first()/remove_mut() dance.

The immutable variants return the new set alongside the popped value, and the _mut variants remove in place and hand back the value, matching the Some(value) / None shape you'd expect from BTreeSet::pop_first. Everything is expressed in terms of the existing first/last/remove/remove_mut methods, so there are no changes to the tree internals; the extra T: Clone bound only applies to these methods since the element is returned by value. Tests cover the empty case, repeated popping down to empty, and that the immutable form leaves the original set untouched.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant