cc: [email protected]
Subject: Re: [ast-users] Sort a very large array of compound variables?
--------

> Does anyone have a working algorithm to sort a very large array (>10
> million entries) of compound variables or filter whole entries?
> 
> Wendy
> 
> ---------- Forwarded message ----------
> From: Roland Mainz <[email protected]>
> Date: 21 April 2013 15:21
> Subject: [ast-developers] typeset -m to swap indexed array entries
> doesn't work with local namerefs...
> To: [email protected]
> 
> 
> Hi!
> 
> ----
> 
> Another "typeset -m" issue... the following example doesn't work if
> function "sortar" is declared using "function sortar" instead of
> "sortar():
> -- snip --
> compound c=(
>         compound -a ar=(
>                 ( float i=4 )
>                 ( float i=7 )
>                 ( float i=2 )
>                 ( float i=1 )
>                 ( float i=24 )
>                 ( float i=-1 )
>         )
> )
> 
> function sortar
> #sortar()
> {
>         nameref ar=$1
>         integer i
>         integer -r i_max=${#ar[@]}
> 
>         bool swapped=true
> 
>         while $swapped ; do
>                 swapped=false
>                 for (( i=1 ; i < i_max ; i++ )) ; do
>                         if (( ar[i].i > ar[i-1].i )) ; then
>                                 typeset -m "tmp=ar[i-1]"
>                                 typeset -m "ar[i-1]=ar[i]"
>                                 typeset -m "ar[i]=tmp"
>                                 swapped=true
>                         fi
>                 done
>         done
>         return 0
> }
> 
> # main
> set -o nounset
> 
> sortar c.ar
> 
> print -v c
> -- snip --
> 
> AFAIK the demo should print...
> -- snip --
> (
>         typeset -C -a ar=(
>                 [0]=(
>                         typeset -l -E i=24
>                 )
>                 [1]=(
>                         typeset -l -E i=7
>                 )
>                 [2]=(
>                         typeset -l -E i=4
>                 )
>                 [3]=(
>                         typeset -l -E i=2
>                 )
>                 [4]=(
>                         typeset -l -E i=1
>                 )
>                 [5]=(
>                         typeset -l -E i=-1
>                 )
>         )
> )
> -- snip --
> ... but ast-ksh.2013-04-09 on SuSE 12.2/AMD64/64bit prints this:
> -- snip --
> $ ksh sortc.sh
> sortc.sh[38]: sortar: line 24: ar[i-1].i : parameter not set
> (
>         typeset -C -a ar=(
>                 [0]=(
>                         typeset -l -E i=7
>                 )
>                 [2]=(
>                         typeset -l -E i=2
>                 )
>                 [3]=(
>                         typeset -l -E i=1
>                 )
>                 [4]=(
>                         typeset -l -E i=24
>                 )
>                 [5]=(
>                         typeset -l -E i=-1
>                 )
>         )
> )
> -- snip --
> 
> ----
> 
> Bye,
> Roland
> 
> --
>   __ .  . __
>  (o.\ \/ /.o) [email protected]
>   \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
>   /O /==\ O\  TEL +49 641 3992797
>  (;O/ \/ \O;)
> 
> -- 
> Wendy

Even if the typeset -m bugs are fixed, this algorithm for sorting is n squared.


I will investigate how fast 10 million compound variables can be sorted
in the shell, and report back.

David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to