Kinds of containers
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Wed Oct 21 22:09:35 PDT 2015
On Thursday, 22 October 2015 at 02:13:12 UTC, bitwise wrote:
> I needed containers, so I implemented a few:
> https://github.com/bitwise-github/d-collections
>
> Currently included:
>
> List(T) - contiguous list like std::vector
> LinkedList(T) - doubly linked list like std::list
> Queue(T) - double-ended queue/contiguous circular buffer
> Stack(T) - contiguous fifo stack
>
You got such a good start with the first 2 ones, but somehow
missed on consistency. You should name the 2 other ones QueueList
and StackList.
> I initially had this reversed, where List(T) was a value type,
> and ListRef(T) was a reference type, but I flipped it the other
> way to avoid unneeded copying for naive usage. I'm still not
> sure this is the right direction though. Optimization is a job
> of it's own, and it's a job for a pro. I believe the amount of
> effort spent to idiot-proof(for lack of a better term) the
> containers should be limited. Especially with the power of D's
> ranges, I think containers should generally(and in my code,
> usually do) stay put. IMO, If someone wants to pass something
> around, they should pass a range, not the container itself. My
> solution, however, does support both(ref/value), if needed.
>
Reference types or COW are definitively the way to go for the
naive road. Think about it, 40% to 50% of chrome memory is
std::string . Eager copy is not a healthy default.
> There is still work to do, of course.
>
The elephant in the room: make the template parameter's type
qualifier transitive with the collection's qualifier.
More information about the Digitalmars-d
mailing list