www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is there a queue class in phobos?

reply Trass3r <un known.com> writes:
Container has List, BinaryHeap etc. but no Queue. Is there anything like  
that in Phobos?
Aug 10 2010
next sibling parent Jonathan M Davis <jmdavisprog gmail.com> writes:
On Tuesday, August 10, 2010 09:22:16 Trass3r wrote:
 Container has List, BinaryHeap etc. but no Queue. Is there anything like
 that in Phobos?
At the moment, I believe that what you see is what you get. std.container is quite young, and there are definitely going to be more containers in it, but for the moment, it's a bit sparse. It's a definite improvement over no containers, but it's new enough that it's still lacking in the number of containers that it has. - Jonathan M Davis
Aug 10 2010
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2010-08-10 18:22, Trass3r wrote:
 Container has List, BinaryHeap etc. but no Queue. Is there anything like
 that in Phobos?
Wouldn't a regular array with a couple of free functions work? -- /Jacob Carlborg
Aug 10 2010
parent Trass3r <un known.com> writes:
 Wouldn't a regular array with a couple of free functions work?
You will get a lot of reallocations. For non-trivial applications you need some more sophisticated approach to alter the size of the array and maybe also deterministic memory management. A queue is a commonly used technique so so it's justified to have it in the standard library, just like lists, heaps etc.
Aug 10 2010
prev sibling parent reply Mafi <mafi example.org> writes:
Am 10.08.2010 18:22, schrieb Trass3r:
 Container has List, BinaryHeap etc. but no Queue. Is there anything like
 that in Phobos?
Hi, I don't know if ther is one but I think D's arrays are powerful enough unless you avoid the GC. 1. a.front() => a[0] 2. a.popFront() => a = a[1..$] 3. a.pushBack(x) => a ~= x I think in phobos there must be front and popFront for arrays to make them ranges but I don't know where.
Aug 10 2010
parent Jonathan M Davis <jmdavisprog gmail.com> writes:
On Tuesday, August 10, 2010 12:06:55 Mafi wrote:
 Am 10.08.2010 18:22, schrieb Trass3r:
 Container has List, BinaryHeap etc. but no Queue. Is there anything like
 that in Phobos?
Hi, I don't know if ther is one but I think D's arrays are powerful enough unless you avoid the GC. 1. a.front() => a[0] 2. a.popFront() => a = a[1..$] 3. a.pushBack(x) => a ~= x I think in phobos there must be front and popFront for arrays to make them ranges but I don't know where.
If you want to treat an array like a range, use the functions in std.array. That's not a terribly cheap way to do things though since you keep resizing the array and will likely get a lot of reallocations. If efficiency isn't an issue, then it could be a nice, clean solution, but if efficiency is a priority, then that's probably not a good way to go. - Jonathan M Davis
Aug 10 2010