Using DList with capacity constraint (aka circular buffer)?

Seb via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 24 06:46:12 PST 2016


Hey all,

this is yet another post about phobos (missing) data structures 
;-)
I know this has been discussed quite a bit - [1,2,3] to name a 
few.

While it would be nice to have those "trivially to implement" 
wrappers for some common use cases (map, unordered map, set, 
multiset, ...) [1], this question focuses solely on dequeues.

It is great that we have DList, so having a circular buffer (aka 
constrained queue) should be easy.

I do understand that baking this into DList  (as e.g. Python 
does) might (a) make things more complex or (b) add overhead that 
isn't needed for every user.

However my question is: why is there not a neat wrapper around 
DList with a capacity constraint?

Unfortunately we don't have inheritance for structs, but proxying 
most methods should work too (see e.g [4]).

1) Has anyone else missed deque with capacity constraints?
2) Would such a wrapper fit into phobos?
3) Would you prefer (a) a wrapper around DList [4], (b) around 
arrays [5] or (c) a "vanilla" circular queue?
(b is slower, but allows indexing)

Best wishes,

[1] 
https://stackoverflow.com/questions/7162274/why-is-d-missing-container-classes
[2] 
http://forum.dlang.org/thread/mailman.852.1359488662.22503.digitalmars-d@puremagic.com
[3] 
http://forum.dlang.org/post/mailman.394.1358112013.22503.digitalmars-d@puremagic.com
[4] http://dpaste.dzfl.pl/d8de9325e9a3
[5] http://rosettacode.org/wiki/Queue/Usage#Faster_Version


More information about the Digitalmars-d mailing list