Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
November 11, 2004 mixin linked lists? | ||||
---|---|---|---|---|
| ||||
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 |
November 11, 2004 Re: mixin linked lists? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle |
> // mixin for linked list support
> template Node(Value) {
> Node next, prev;
> ... various linked-list member functions ...
> }
ack, that should be
Value next, prev;
|
November 11, 2004 Re: mixin linked lists? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | 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/ |
November 12, 2004 Re: mixin linked lists? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | 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 of the 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 |
November 12, 2004 Re: mixin linked lists? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant |
> 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.
|
Copyright © 1999-2021 by the D Language Foundation