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

Copy/Contents of Methods #13

Open
stephen304 opened this issue Mar 19, 2015 · 1 comment
Open

Copy/Contents of Methods #13

stephen304 opened this issue Mar 19, 2015 · 1 comment

Comments

@stephen304
Copy link

I'd like to use lane to store a variable list of things where the oldest items are only the ones being removed and the newest go in front. Naturally, a queue from this package would work great, but when printing the contents of the queue, you have to destroy it by popping everything off. This makes my brain hurt when trying to figure out whether I can safely print the contents this way while another thread may be writing to the queue, as the locks are per operation (pop), and there's no way to lock the list for the duration of the copy process.

I would like to propose one of two things:

  • A copy method that would generate a new dequeue, stack, etc struct that is completely independent from the source object - this would allow me to store things in my dequeue and copy it before using dequeue repeatedly to print out the contents
  • A contents (or something) method that would return something like an array of the items in the list. This way I could extract the contents of my dequeue to display without modifying the dequeue.

What do you think?

@stephen304 stephen304 changed the title Copy/Contents Queue Feature Copy/Contents of Methods Mar 19, 2015
@oleiade
Copy link
Owner

oleiade commented Apr 24, 2016

Hey @stephen304

First of all, sorry for the looooooonnng reply delay :-)

That's an interesting point!

  • I really like the idea of a Copy method. That would bring a touch of immutability and indeed allow you keep track of what your doing easily. The only concern I would have in this case is how would that work out with the locks?
  • I'm not very fond of the idea to expose the items of the list as a method. The main reason is that I created this library to provide a higher level implementation compared to the standard library. Probably a bit more opinionated too :-) I think you should consider the standard library heap interface if you absolutely need to have control on the container.

Talking about this, I realize it might be a good idea to add a Lock and Unlock methods to the data structures. That would probably ease the interactions with the structs in concurrent algorithm context!

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

No branches or pull requests

2 participants