[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: Brian G <brian@xxxxxxxxxxxxxxxx>
- Date: Sun, 18 Jan 2026 14:30:06 -0800
- To: user@xxxxxxxxxxxxxxxxxxxxxx
On 1/16/26 16:01, Benoît Minisini wrote:
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,
Nice, So it will reflect the inserted order always. That is really nice!So a sort on the keys, then copy by the sorted keys into a new collection will produce a sorted collection that can be iterated. That is very cool!
-- ~~~~ Brian
Attachment:
OpenPGP_0x78BFB26402F48419.asc
Description: OpenPGP public key
Attachment:
OpenPGP_signature.asc
Description: OpenPGP digital signature