Skip to content
New issue

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

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

Already on GitHub? # to your account

Enhance CircularBuffer with insertFirst and popFirst/Last #279

Closed
helje5 opened this issue Apr 4, 2018 · 9 comments
Closed

Enhance CircularBuffer with insertFirst and popFirst/Last #279

helje5 opened this issue Apr 4, 2018 · 9 comments
Assignees
Milestone

Comments

@helje5
Copy link
Contributor

helje5 commented Apr 4, 2018

I'd like to abuse the CircularBuffer as a CoW data structure w/ linked list behaviour (better index-0 insert/remove behaviour than ContiguousArray, which I currently use). Since the ivars are all private, I can't extend CircularBuffer with the operations I need. I think it would be those (also available in the stdlib, excluding insertFirst):

public mutating func popFirst() -> Element?
public mutating func popLast() -> Element?
public mutating func insertFirst(Element)

Would be great to get those (and a CoW linked list ;-) )

@weissi
Copy link
Member

weissi commented Apr 4, 2018

sure, we can totally just implement the missing methods. @Lukasa / @normanmaurer opinions?

@Lukasa
Copy link
Contributor

Lukasa commented Apr 5, 2018

Eh, sure, why not?

@normanmaurer
Copy link
Member

normanmaurer commented Apr 5, 2018 via email

@normanmaurer
Copy link
Member

@helje5 btw we love PRs :)

@helje5
Copy link
Contributor Author

helje5 commented Apr 16, 2018

Every one loves PRs! But then @Lukasa wants you to write tests for perfectly working code and a 2 minute patch becomes hours and hours. Been there, done that ;-)

But yes, I consider doing a PR. I need to fully understand it to do the insertFirst right, the only reason I didn't approach that yet (apart from the fact that it would probably take @weissi 2 minutes to do those 😉)

@Lukasa
Copy link
Contributor

Lukasa commented Apr 17, 2018

I'm a monster, I know. And yet I feel so little guilt!

@Lukasa
Copy link
Contributor

Lukasa commented Apr 17, 2018

(Also I'd definitely make @weissi write the tests too.)

@normanmaurer
Copy link
Member

@Lukasa maybe I should write the patch then as it seems I will not need to write tests 🤷‍♂️ ;)

@normanmaurer
Copy link
Member

I will take a stab on this once #313 is merged

normanmaurer added a commit to normanmaurer/swift-nio that referenced this issue Apr 23, 2018
Motivation:

Its often useful to be able to add / retrieve elements on both sides of a CircularBuffer.

Modifications:

Add last / addFirst to be able to act on both ends.
Add tests

Result:

Fixes apple#279
normanmaurer added a commit to normanmaurer/swift-nio that referenced this issue Apr 23, 2018
Motivation:

Its often useful to be able to add / retrieve elements on both sides of a CircularBuffer.

Modifications:

Add last / addFirst to be able to act on both ends.
Add tests

Result:

Fixes apple#279
normanmaurer added a commit to normanmaurer/swift-nio that referenced this issue Apr 24, 2018
Motivation:

Its often useful to be able to add / retrieve elements on both sides of a CircularBuffer.

Modifications:

Add last / addFirst to be able to act on both ends.
Add tests

Result:

Fixes apple#279
normanmaurer added a commit to normanmaurer/swift-nio that referenced this issue Apr 24, 2018
Motivation:

Its often useful to be able to add / retrieve elements on both sides of a CircularBuffer.

Modifications:

- Add last / prepend to be able to act on both ends.
- Add tests

Result:

Fixes apple#279
normanmaurer added a commit that referenced this issue Apr 24, 2018
Motivation:

Its often useful to be able to add / retrieve elements on both sides of a CircularBuffer.

Modifications:

- Add last / prepend to be able to act on both ends.
- Add tests

Result:

Fixes #279
@normanmaurer normanmaurer added this to the 1.6.0 milestone Apr 24, 2018
@normanmaurer normanmaurer self-assigned this Apr 24, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants