Does D have a Queue and Stack container?
bearophile
bearophileHUGS at lycos.com
Sun Jan 13 21:24:04 PST 2013
ponce:
> I wrote a Queue/RingBuffer here:
> https://github.com/p0nce/gfm/blob/master/common/queue.d
You have code like:
return _data[(_first + _count - 1) % _data.length];
Take a look here:
http://rosettacode.org/wiki/Queue/Usage#Faster_Version
It keeps another instance field:
private uint power2 = 0;
And instead of the modulus uses an And, that is supposed to be
faster:
tail = (tail + 1) & ((cast(size_t)1 << power2) - 1);
This is usable if the growth rate is 2. This is almost true in
your code:
size_t newCapacity = capacity * 2;
if (newCapacity < 8)
newCapacity = 8;
Bye,
bearophile
More information about the Digitalmars-d
mailing list