Re: Dynamic Arrays as Stack and/or Queue

2019-10-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 8, 2019 2:42:22 PM MDT mipri via Digitalmars-d-learn wrote: > On Tuesday, 8 October 2019 at 10:48:45 UTC, Jonathan M Davis > > wrote: > > The result of this is that code like > > > > stack.popBack(); > > stack ~= foo; > > stack ~= bar; > > stack.popBack(); > > stack ~= baz; > >

Re: Dynamic Arrays as Stack and/or Queue

2019-10-08 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 08, 2019 at 08:42:22PM +, mipri via Digitalmars-d-learn wrote: > On Tuesday, 8 October 2019 at 10:48:45 UTC, Jonathan M Davis wrote: > > The result of this is that code like > > > > stack.popBack(); > > stack ~= foo; > > stack ~= bar; > > stack.popBack(); > > stack ~= baz; > > > >

Re: Dynamic Arrays as Stack and/or Queue

2019-10-08 Thread mipri via Digitalmars-d-learn
On Tuesday, 8 October 2019 at 10:48:45 UTC, Jonathan M Davis wrote: The result of this is that code like stack.popBack(); stack ~= foo; stack ~= bar; stack.popBack(); stack ~= baz; will end up allocating all over the place. Every time you append to the array after shrinking it, you're going to

Re: Dynamic Arrays as Stack and/or Queue

2019-10-08 Thread Just Dave via Digitalmars-d-learn
Thanks for the advice. I used a quick and dirty range solution as was suggested. It allowed me to move on as I really wasn't looking to fully implement a queue or stack. Just get something that semantically behaved as such. I'll return later and optimize it with the later suggestions if it's a

Re: Dynamic Arrays as Stack and/or Queue

2019-10-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, October 7, 2019 1:16:31 PM MDT IGotD- via Digitalmars-d-learn wrote: > On Monday, 7 October 2019 at 17:36:09 UTC, Ferhat Kurtulmuş wrote: > >> I'm not talking about memory deletion. I'm talking about push, > >> pop, enqueue, and dequeue behavior. I'd assume in a garbage > >> collected l

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread Ali Çehreli via Digitalmars-d-learn
On 10/07/2019 10:11 AM, Just Dave wrote: I need a stack and a queue There is a DoubleEndedQueue example under "Indexing Operators" here: http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.opIndexOpAssign It does not have the pop varieties but it should be trivial to

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread Alex via Digitalmars-d-learn
On Monday, 7 October 2019 at 19:38:50 UTC, mipri wrote: On Monday, 7 October 2019 at 19:16:31 UTC, IGotD- wrote: On Monday, 7 October 2019 at 17:36:09 UTC, Ferhat Kurtulmuş wrote: I'm not talking about memory deletion. I'm talking about push, pop, enqueue, and dequeue behavior. I'd assume in

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread mipri via Digitalmars-d-learn
On Monday, 7 October 2019 at 19:16:31 UTC, IGotD- wrote: On Monday, 7 October 2019 at 17:36:09 UTC, Ferhat Kurtulmuş wrote: I'm not talking about memory deletion. I'm talking about push, pop, enqueue, and dequeue behavior. I'd assume in a garbage collected language letting the reference float

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread IGotD- via Digitalmars-d-learn
On Monday, 7 October 2019 at 17:36:09 UTC, Ferhat Kurtulmuş wrote: I'm not talking about memory deletion. I'm talking about push, pop, enqueue, and dequeue behavior. I'd assume in a garbage collected language letting the reference float off should be picked up by the GC. I'm sorry. Writing on

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Monday, 7 October 2019 at 17:28:11 UTC, Just Dave wrote: On Monday, 7 October 2019 at 17:24:19 UTC, Ferhat Kurtulmuş wrote: On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: [...] Built-in D arrays rely on garbage collector, and you don't need an explicit delete. For nogc arrays

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread Just Dave via Digitalmars-d-learn
On Monday, 7 October 2019 at 17:24:19 UTC, Ferhat Kurtulmuş wrote: On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack a

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread Just Dave via Digitalmars-d-learn
On Monday, 7 October 2019 at 17:18:03 UTC, bachmeier wrote: On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queu

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread bachmeier via Digitalmars-d-learn
On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread mipri via Digitalmars-d-learn
On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread bachmeier via Digitalmars-d-learn
On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if