Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <20240513162301.128@kylheku.com>
Deutsch   English   Français   Italiano  
<20240513162301.128@kylheku.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: alt.comp.lang.awk,comp.lang.awk
Subject: Re: printing words without newlines?
Date: Mon, 13 May 2024 23:33:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <20240513162301.128@kylheku.com>
References: <v1pi7c$2b87j$1@dont-email.me> <20240513100418.652@kylheku.com>
 <v1tih0$u8kt$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 14 May 2024 01:33:08 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="70ea83c966d77830013f93e036db08ae";
	logging-data="3945010"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/gu0eqPpHWQUTT9ESMrO+065m61BRYCUY="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:P9DiHBetzNMEJgstMV1wJBco9lk=
Bytes: 2916

On 2024-05-13, Kenny McCormack <gazelle@shell.xmission.com> wrote:
> In article <20240513100418.652@kylheku.com>,
> Kaz Kylheku  <643-408-1753@kylheku.com> wrote:
> ...
> (This version more complicated than it needs to be, but essentially the
> same as what I posted earlier)
>>$ awk '{
>>  if ($1 > max) max = $1;
>>  rank[$1] = $2
>>}
>>
>>END {
>>  for (i = 1; i <= max; i++)
>>    if (i in rank) {
>>      printf("%s%s", sep, rank[i]);
>>      sep = " "
>>    }
>>  print ""
>>}' data.txt
>>all your base are belong to us
>>
>>We do not perform any sort, and so we don't require GNU extensions. Sorting is
>
> But GNU extensions are good - especially since OP specifically mentioned
> using GAWK.  And much more on-topic than Lisp (et al).

The above performs O(N) steps, whereas sorting is O(N log N),
and sometimes worse due to degenerate cases in some algorithms.

Why use an extension that only makes the program more verbose and brings
in an unnecessary algorithm.

> 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?

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."

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca