Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
August 10, 2010 Is there a queue class in phobos? | ||||
---|---|---|---|---|
| ||||
Container has List, BinaryHeap etc. but no Queue. Is there anything like that in Phobos? |
August 10, 2010 Re: Is there a queue class in phobos? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | 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
|
August 10, 2010 Re: Is there a queue class in phobos? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | 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 |
August 10, 2010 Re: Is there a queue class in phobos? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | 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.
|
August 10, 2010 Re: Is there a queue class in phobos? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mafi | 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
|
August 10, 2010 Re: Is there a queue class in phobos? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | > 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.
|
Copyright © 1999-2021 by the D Language Foundation