Minisini così risponde:
« Hi Tobi,
If Deque, Stack... classes can be useful, I'm not sure about your List
and ListRoot classes.
I think you tried to mimic in Gambas the way linked list are implemented
in C: consequently, the Gambas interface is over-complicated.
First, you must know that linked list are far less useful nowadays. As
they trash the CPU cache, using an array is way faster, the speed gain
usually compensating the need for reallocation. Bet let's ignore that point.
I think a List class should have the following interface:
- Create a new List. (_new)
- Put one Variant at the beginning. (Add / Append)
- Put one Variant at the end. (Prepend)
- Enumerate the contents. (_next)
- Have an internal cursor, on which we could do a MoveNext() and
MovePrevious(). (MoveNext, MovePrevious, MoveFirst, MoveLast).
- Have a current item, and be allow to retrieve it. (Current)
- A Count property. (Count)
- An array method to retrieve the i-th element (slowly of course).
(_get), and eventually to modify it (_put)
- Take the current element from the list (i.e. removing it from the list
and returning it). (Take)
- Find a value inside the list. (Find or FindFirst, maybe FindLast too)
- Find a value from the current one, forward or backward. (FindNext,
FindPrevious).
Internally, the List can be managed with a double-linked list of nodes,
each node having a GB_VARIANT_VALUE inside.
But, for performance reasons, it can later be implemented as a
double-linked list of arrays of Variant. Faster, but harder to implement.
As for "embedding" the list inside an object, i.e. doing what we usually
do in C, I think I understood what you want to do, but I don't think it
is really useful in Gambas.
The only advantage I see is being able to find the next (or previous)
object of the list as soon as you have a reference on the object. Which
is not possible with the previous List class.
To do that, maybe I would create another class (something like
'StaticList'). But anyway it will not be easy to have a practical interface!
As for having a list interface in the interpreter API: why not. But it
would be done if this is really useful, as implementation of linked list
is done in a few lines of codes, and usually need to be adapted for
performance reasons. Anyway see '/trunk/main/share/gb_list.h'
and '/trunk/main/share/gb_list_temp.h', which is my own implementation
of embedded linked lists in C.
So tell me what you think.
Regards,
--
Benoît Minisini »