Sujet : Array indices are small integers? (Was: printing words without newlines?)
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : alt.comp.lang.awk comp.lang.awkDate : 14. May 2024, 14:40:21
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <v1vpk5$vbji$1@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
20240513162301.128@kylheku.com>,
Kaz Kylheku <
643-408-1753@kylheku.com> wrote:
...
Final note: In fact, it has been established (on this newsgroup as well as
empirically by me and others) that if the indices are small integers, you
get sorting for free (in GAWK, which, as noted, is all we care about). So,
you don't even really need to mess with PROCINFO[]...
>
Are you referring to the idea of just replacing the above for + if
structure with:
>
for (i in rank) {
>
}
>
and relying on the small integer indices being hashed in order?
Yes.
Where is that documented? The manual reiterates that this is not
specified: "By default, the order in which a for (indx in array) loop
scans an array is not defined; it is generally based upon the internal
implementation of arrays inside awk."
It is documented in this newsgroup (Google is your friend).
And assented to by one or both of the GAWK insiders who are known to post here.
It seems to be an attribute (i.e., quirk) of the particular hashing
algorithm used.
Now, of course it isn't guaranteed and could disappear in some future
version of GAWK - and, of course, one wouldn't rely on it in production
code, since it is so easy to make it right by including the line (shown in
this thread's OP) that sets PROCINFO[].
But it is true, nonetheless.
-- The key difference between faith and science is that in science, evidence thatdoesn't fit the theory tends to weaken the theory (that is, make it less likely tobe believed), whereas in faith, contrary evidence just makes faith stronger (onthe assumption that Satan is testing you - trying to make you abandon your faith).