Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

My asort fix!!

orvar ehn
2010-10-28
2013-04-22
  • orvar ehn
    orvar ehn
    2010-10-28

    Hi

    since awka sorts on the index I have this code to correct it:

    function arrsort(source,dest,   mode,s,value){
            if (argcount()==1){
                for (s in source){
                        value=source[s]
                        source[value,s]=value
                        delete source[s]
                }
                return asort(source)
            }else{
                for (s in source){
                        value=source[s]
                        dest[value,s]=value
                }
                return asort(dest)
            }
    }
    

    I have tested 4 different approaches to array sorting in awka ("using shell sort", implementing "quick-sort",using SORTTYPE,and this using awka asort). A comparison on the speed with an array of 100000 gave the following ranking
    1. using awka asort
    2. using SORTTYPE
    3. using shell sort
    4. quick sort.

    so I stick with the faulty awka asort..

    Btw I know that adding to an array inside a for (s in array) is NOT recommendable in POSIX "strange things might happen" but it seems to work in awka.. 

    The really irritating thing is that I can't call this function asort.. it won't compile!?!? .. according to the awka manpages asort alength etc should be "extra" functions and should be superseded by a user defined function with the same name..??

    Maybe I have to use an earlier version of awka when these two functions were still not core functions??.. Someday I will have to investigate this.. does anyone know of a change log somewhere??

    In the mean time I'm  using a awka script to "parse" the source and replace all asort with arrsort and all length with awkalength then I include these functions before compilation.. It actually works pretty good..

    I'm so sad that awka is not developed further.. it is in spite of its (small) faults a very impressive creation.. Maybe I have to finally take that dreaded course in C and try build an ELM library… gulp!

    /Still a big awka fan

     
  • orvar ehn
    orvar ehn
    2010-10-28

    Gahhhh.. stupid sourceforge look at my beautiful code.. It is strange that the code tags dosen't turn of the other tags..