Script Library: 1213 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Discussion posts for script multiple-key-sort.r

1
coccinelle
12-May-2006 14:58
Compare function are very slow. To achieve the same sort capability, 
a function like this is much more efficient :

multi-sort: func [
    serie [series!]
    order [block!]
    /local
][
    foreach local reverse order [
        either negative? local [

            serie: sort/skip/compare/reverse serie length? order abs local
        ] [

            serie: sort/skip/compare serie length? order reduce local
        ]
    ]
    serie
]

Example :
>> multi-sort [1 2 1 2 1 3 2 1 2 2] [-1 2]
== [2 1 2 2 1 2 1 2 1 3]
>> multi-sort [1 2 1 2 1 3 2 1 2 2] [1 -2]
== [1 3 1 2 1 2 2 2 2 1]
>>