digitalmars.D.dtl - mixin linked lists?
- Ben Hinkle (23/23) Nov 11 2004 Does anyone see a need for a mixin for a doubly or singly linked list? I...
- Ben Hinkle (2/7) Nov 11 2004 ack, that should be
- Regan Heath (8/36) Nov 11 2004 It seems like a cool idea. I was just thinking 'you could do that with a...
- Ant (6/8) Nov 12 2004 the cost is so low that would don't even need to ask.
- Ben Hinkle (2/4) Nov 12 2004 good point. The mixin can also be used for structs but an interface coul...
Does anyone see a need for a mixin for a doubly or singly linked list? I'm basically thinking of // mixin for linked list support template Node(Value) { Node next, prev; ... various linked-list member functions ... } // user data structure that wants to be stored in a list class MyClass { mixin Node!(MyClass); char[] a_string; int an_int; ... etc etc } The advantages are a smaller memory footprint and simplicity when the object lives in exactly one list. Sometimes you just want the list semantics to be built into the class or struct instead of having a separate List!(MyClass) type with its definition of nodes. Also an SNode template for singly-linked lists would be nice. I haven't completely decided what should go into the Node template - so far I just have about 5 functions to link, add, remove and opApply. Does this seem useful? -Ben
Nov 11 2004
// mixin for linked list support template Node(Value) { Node next, prev; ... various linked-list member functions ... }ack, that should be Value next, prev;
Nov 11 2004
On Thu, 11 Nov 2004 14:21:18 -0500, Ben Hinkle <bhinkle mathworks.com> wrote:Does anyone see a need for a mixin for a doubly or singly linked list? I'm basically thinking of // mixin for linked list support template Node(Value) { Node next, prev; ... various linked-list member functions ... } // user data structure that wants to be stored in a list class MyClass { mixin Node!(MyClass); char[] a_string; int an_int; .. etc etc } The advantages are a smaller memory footprint and simplicity when the object lives in exactly one list. Sometimes you just want the list semantics to be built into the class or struct instead of having a separate List!(MyClass) type with its definition of nodes. Also an SNode template for singly-linked lists would be nice. I haven't completely decided what should go into the Node template - so far I just have about 5 functions to link, add, remove and opApply. Does this seem useful?It seems like a cool idea. I was just thinking 'you could do that with an abstract base class' when I realised 'what if you want to add it to a class which is already deriving from something else'. Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 11 2004
In article <cn0e3e$km4$1 digitaldaemon.com>, Ben Hinkle says...Does anyone see a need for a mixin for a doubly or singly linked list? I'm basically thinking ofthe cost is so low that would don't even need to ask. just add it. but it will require an interface, right? I see (and use) mixins paired with interfaces. Ant
Nov 12 2004
but it will require an interface, right? I see (and use) mixins paired with interfaces.good point. The mixin can also be used for structs but an interface couldn't hurt, I suppose. I'll put one in.
Nov 12 2004