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 a
garbage collected language letting the reference float off
should be picked up by the GC.
I'm sorry. Writing on my mobile phone. Maybe this is what you
are looking for
https://dlang.org/phobos/std_container_dlist.html
I think what he is looking for are the general pop_front,
push_front, pop_back and push_back that you would find in
virtually any C++ STL container algorithms like list, vector
or map.
I think this is a good question as I don't really see any good
example in the documentation of the dynamic arrays about this.
This is very common use case for arrays. Is there any D
equivalent?
With the performance that you'd expect, I believe:
#! /usr/bin/env rdmd
[...]
I assume this is a little bit more complicated:
while popFront and popBack are ubiquitous in ranges in D, the
push functions can't be unified in terms of memory management.
For example, you cannot guarantee any performance, while using
GC. This opposed to complexity, which is, of course, known.
Maybe, this is the reason, why such containers are omitted in
Phobos (?)
But:
There is a priority queue, named binaryheap:
https://dlang.org/phobos/std_container_binaryheap.html
and there are hints, that for a stack you have to rely e.g., on
an array or a list implementation
http://www.cplusplus.com/reference/stack/stack/
both exist in phobos:
https://dlang.org/phobos/std_container_array.html
https://dlang.org/phobos/std_container_dlist.html
This gives rise to user implementations like
https://code.dlang.org/packages/queue
https://code.dlang.org/packages/mergearray
etc.
Maybe, there will be more soon? ;)