[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: Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
- Date: Sat, 17 Jan 2026 16:15:16 +0100
- To: user@xxxxxxxxxxxxxxxxxxxxxx
Le 17/01/2026 à 15:19, Gianluigi a écrit :
Il 17/01/26 14:48, Benoît Minisini ha scritto:No. As I explaines, the order comes from a specific feature added to the hash table. This feature is not mandatory for a hash table to be a hash table. I added it because it allows to use the hash table both as a hash table and a rudimentory ordered list. But it has a cost: 16 bytes by element!Hi Benoit,I apologize, but as I told Jussi, I'm working on another job and I didn't explain myself well. Let me put it this way: if someone asks me if the Gambas3 collections are in order and I say yes, am I wrong?
No. It's just that it is not "officially" guaranteed yet, even if I won't change that now, and if I want an unordered Collection, I will create another class.
I'm ignorant, I haven't studied math, and I don't know hash tables, so I can't talk about them.
This is not math, this is algorithms. A hash table is an array.But to be able to use indexes that are strings for storing an element, the string is transformed (we say "hashed", hence the name "hash table") into an integer lower than the size of the array, that is the index in that array where we want to store the element.
Then, as two strings may lead to the same index, we actually store another array in each element of the initial array. It's that second-level array that stores all elements of the hash table whose string key lead to same index.
Then things become a bit complex, because when you add more elements to the hash table (or remove them), it adapts the size of its first-level array and reorganizes everything so that there is not too many string keys leading to the same index, for performance reasons.
I don't know if it's clear for you. You will find for sure better explanations on the Internet with good examples.
Regards, -- Benoît Minisini.
| Re: Looping through an array with FOR EACH | Gianluigi <gradobag@xxxxxxxxxxx> |