[Gambas-user] Accessing the nth item in a collection

Randall Morgan rmorgan62 at ...626...
Wed Jun 4 20:13:13 CEST 2014


In some languages, FOR EACH doesn't guaranty the order of the items
processed. It only guaranties you will process each item in the collection.
I think it is a bad habit to use For Each when order of processing is
important. Unless you are using an array or other data structure that is
known to maintain order. A linked list or array would be a better choice. I
haven't followed all this thread but I am sure that has already been
suggested... The other option is to implement your own ordered collection.
But wouldn't an array of object be easier?


On Wed, Jun 4, 2014 at 7:51 AM, Jussi Lahtinen <jussi.lahtinen at ...626...>
wrote:

> OK, thanks for the answer! But can you elaborate bit further? If the
> insertion order is no longer kept, then what dictates the order "For Each"
> will enumerate the items? Order of memory addresses?
>
> I mean would the enumeration order be unchanging, but when new item is
> added it would be inserted in random (practically from user perspective)
> position of the enumeration?
>
>
> Jussi
>
>
> On Wed, Jun 4, 2014 at 3:51 PM, Benoît Minisini <
> gambas at ...1...> wrote:
>
> > Le 04/06/2014 14:44, Jussi Lahtinen a écrit :
> > >> AFAIK, Collection is a hash table and of course, you cannot assume a
> > >> particular order of keys in a hash table.
> > >>
> > >
> > > That is my understanding also. But they always seems to be in order
> they
> > > have been added, when you iterate them with "For Each ...".
> > >
> > > What would cause the disorder?
> > >
> >
> > There are in order by design (the hash table elements are linked both by
> > hash slot *and* insertion order).
> >
> > But I don't guarantee that this non-official feature won't be removed.
> >
> > Regards,
> >
> > --
> > Benoît Minisini
> >
> >
> >
> ------------------------------------------------------------------------------
> > Learn Graph Databases - Download FREE O'Reilly Book
> > "Graph Databases" is the definitive new guide to graph databases and
> their
> > applications. Written by three acclaimed leaders in the field,
> > this first edition is now available. Download your free book today!
> > http://p.sf.net/sfu/NeoTech
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/NeoTech
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



-- 
If you ask me if it can be done. The answer is YES, it can always be done.
The correct questions however are... What will it cost, and how long will
it take?



More information about the User mailing list