[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Looping through an array with FOR EACH


Le 17/01/2026 à 00:00, Brian G a écrit :
On 1/16/26 14:15, Jussi Lahtinen wrote:
Long time ago Benoit said about collections: "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.". So, For Each is not guaranteed to iterate the elements in the insertion order.


Jussi
Yes this is very obvious, as it is probably a hash table, or tree

Everything is in the source code. :-)

'Collection' is a hash table, whose nodes have three links:

- A link to the next element having the same hash, or NULL if it is the last one.

- A link to the element previously inserted or NULL if it is the first.

- A link to the next inserted element, or NULL if it is the last one.

The Collection itself maintain a link to the first inserted element, and slots for the different possible hashing values.

So having elements ordered in a collection requires two pointers (16 bytes on 64 bites) for each element.

This might be a problem if you need a collection with millions of elements and don't need to maintain the order of insertion.

But even if I said "order is not guaranted", I don't think this feature will be removed.

And if really an hash table with no order to save memory is required, I will add an "HashTable" class for that, to keep backward-compatibility.

So the "not guaranted" guaranty may become "guaranted" in the future.

Regards,

--
Benoît Minisini.


Follow-Ups:
Re: Looping through an array with FOR EACHGianluigi <gradobag@xxxxxxxxxxx>
Re: Looping through an array with FOR EACHBrian G <brian@xxxxxxxxxxxxxxxx>
References:
Looping through an array with FOR EACHGianluigi <gradobag@xxxxxxxxxxx>
Re: Looping through an array with FOR EACHBB <adamnt42@xxxxxxxxx>
Re: Looping through an array with FOR EACHGianluigi <gradobag@xxxxxxxxxxx>
Re: Looping through an array with FOR EACHBrian G <brian@xxxxxxxxxxxxxxxx>
Re: Looping through an array with FOR EACHGianluigi <gradobag@xxxxxxxxxxx>
Re: Looping through an array with FOR EACHBenoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
Re: Looping through an array with FOR EACHGianluigi <gradobag@xxxxxxxxxxx>
Re: Looping through an array with FOR EACHBrian G <brian@xxxxxxxxxxxxxxxx>
Re: Looping through an array with FOR EACHJussi Lahtinen <jussi.lahtinen@xxxxxxxxx>
Re: Looping through an array with FOR EACHGianluigi <gradobag@xxxxxxxxxxx>
Re: Looping through an array with FOR EACHJussi Lahtinen <jussi.lahtinen@xxxxxxxxx>
Re: Looping through an array with FOR EACHBrian G <brian@xxxxxxxxxxxxxxxx>