queue container?

Steven Schveighoffer schveiguy at yahoo.com
Mon Oct 31 07:07:07 PDT 2011


On Sat, 29 Oct 2011 12:02:51 -0400, J Arrizza <cppgent0 at gmail.com> wrote:

> On Fri, Oct 28, 2011 at 6:55 PM, Steven Schveighoffer
> <schveiguy at yahoo.com>wrote:
>
>> I'd recommend using a linked list or a deque.  Both are available via
>> dcollections, though using dcollections' deque as a queue is equivalent  
>> to
>> using an array because of the implementation.  SList is not suited for a
>> queue, since you cannot have O(1) addition on one end and O(1) removal  
>> on
>> the other.
>>
>
> I'd like to use only Phobos because it's guaranteed to be there as part  
> of
> D, while dcollections may or may not persist, and may or may not be  
> merged
> into Phobos.

I personally guarantee that dcollections will persist as long as  
std.container's design is not modified to become like dcollections'.   
Simply because I need it for my projects :)  And I'm not going to some  
other language any time soon.

How much weight that pulls with you?  Not sure.

> For example, if Phobos comes out with a more comprehensive
> std.collections, then dcollections becomes redundant. If it is merged  
> into
> Phobos, then fine.

As long as std.container's design does not include cursors and  
removal-while-iterating, "more comprehensive" becomes dependent on what  
your needs are.  If something is more comprehensive, but doesn't satisfy  
the requirements, comprehensiveness is moot.

>
> When Jacob's central repository is put in place and the D community  
> accepts
> it ( as did the Perl community for CPAN), and dcollections is in there,
> then I'll use it.

I'll be one of the first to add my library to it when it's released.

>
>> It's also quite trivial to roll your own linked list-based queue.
> Yes.  I've gone down this route before in C++. I write my own and then a
> new version of the std.container comes out. The end result is a lot of  
> busy
> work converting from my queue implementation to the standard one.  
> Sometimes
> I'm even forced to convert because of name clashes. Then it's worse. It's
> busy work under pressure.

std.container's API is very well defined.  All you need to do is define  
your interface to be like std.container, and then when the  
std.container.queue type comes out, it's a simple switch of an import, or  
alias.

Best way to do this is to simply create your own version of std.container  
with your type in it.

> Enough reminiscing. My preference is to have a clear policy that Phobos  
> is
> the one and only (nicely comprehensive) standard library and there is a
> central repository for all the remaining esoteric and rare a la CPAN,  
> gems,
> PyPI, etc.

I certainly respect that position, and it's a good one to have.  But that  
does leave you with a queue-less container situation :)

-Steve


More information about the Digitalmars-d mailing list