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

Feature: TakeSlice method #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Andrew-Morozko
Copy link

TakeSlice() allows to retrieve the underlying buffer as a slice, with all elements placed in the correct order and extra capacity preserved. It clears the internal state of the deque.

There are a few optimisations possible if you are ok with wasting some capacity at the start of the buffer (for example this one) and using 3 rotations is not the most optimal way to reorder elements, but it's simple and it works.

Perhaps an extra method that copies the deque into a new slice may also be useful, but this one seems semantically simpler

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