[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Looping through an array with FOR EACH
[Thread Prev] | [Thread Next]
- Subject: Re: Looping through an array with FOR EACH
- From: Gianluigi <gradobag@xxxxxxxxxxx>
- Date: Sat, 17 Jan 2026 14:41:38 +0100
- To: user@xxxxxxxxxxxxxxxxxxxxxx
Il 17/01/26 01:01, Benoît Minisini ha scritto:
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.JussiYes this is very obvious, as it is probably a hash table, or treeEverything 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,
Hi Benoit, So collections also guarantee insertion order. Also because you can only add, right?Speaking of adding, there was a mistake in the example (Add) that I took the liberty of correcting.
Regards Gianluigi
| Re: Looping through an array with FOR EACH | Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx> |