diff options
author | Charles Krinke | 2008-04-26 20:49:38 +0000 |
---|---|---|
committer | Charles Krinke | 2008-04-26 20:49:38 +0000 |
commit | 7cb78d73eb007eddbefb647d56a0e140640a7a9e (patch) | |
tree | 9cd5f57d8b97c2c58b1e4bd8bce692c189620d14 /OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | |
parent | * Tidy up and comments related to last inventory related commit (diff) | |
download | opensim-SC_OLD-7cb78d73eb007eddbefb647d56a0e140640a7a9e.zip opensim-SC_OLD-7cb78d73eb007eddbefb647d56a0e140640a7a9e.tar.gz opensim-SC_OLD-7cb78d73eb007eddbefb647d56a0e140640a7a9e.tar.bz2 opensim-SC_OLD-7cb78d73eb007eddbefb647d56a0e140640a7a9e.tar.xz |
Thank you Melanie for implementing
llListSort() in linear and strided modes.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/LSL_Types.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs index ec10157..aed591c 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | |||
@@ -560,6 +560,70 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
560 | } | 560 | } |
561 | } | 561 | } |
562 | 562 | ||
563 | public list Sort(int stride, int ascending) | ||
564 | { | ||
565 | if(Data.Length == 0) | ||
566 | return new list(); // Don't even bother | ||
567 | |||
568 | if(stride == 1) // The simple case | ||
569 | { | ||
570 | Object[] ret=new Object[Data.Length]; | ||
571 | |||
572 | Array.Copy(Data, 0, ret, 0, Data.Length); | ||
573 | |||
574 | Array.Sort(ret); | ||
575 | |||
576 | if(ascending == 0) | ||
577 | Array.Reverse(ret); | ||
578 | return new list(ret); | ||
579 | } | ||
580 | |||
581 | int src=0; | ||
582 | |||
583 | int len=(Data.Length+stride-1)/stride; | ||
584 | |||
585 | string[] keys=new string[len]; | ||
586 | Object[][] vals=new Object[len][]; | ||
587 | |||
588 | int i; | ||
589 | |||
590 | while(src < Data.Length) | ||
591 | { | ||
592 | Object[] o=new Object[stride]; | ||
593 | |||
594 | for(i=0;i<stride;i++) | ||
595 | { | ||
596 | if(src < Data.Length) | ||
597 | o[i]=Data[src++]; | ||
598 | else | ||
599 | { | ||
600 | o[i]=new Object(); | ||
601 | src++; | ||
602 | } | ||
603 | } | ||
604 | |||
605 | int idx=src/stride-1; | ||
606 | keys[idx]=o[0].ToString(); | ||
607 | vals[idx]=o; | ||
608 | } | ||
609 | |||
610 | Array.Sort(keys, vals); | ||
611 | if(ascending == 0) | ||
612 | { | ||
613 | Array.Reverse(vals); | ||
614 | } | ||
615 | |||
616 | Object[] sorted=new Object[stride*vals.Length]; | ||
617 | |||
618 | int j; | ||
619 | |||
620 | for(i=0;i<vals.Length;i++) | ||
621 | for(j=0;j<stride;j++) | ||
622 | sorted[i*stride+j]=vals[i][j]; | ||
623 | |||
624 | return new list(sorted); | ||
625 | } | ||
626 | |||
563 | #region CSV Methods | 627 | #region CSV Methods |
564 | 628 | ||
565 | public static list FromCSV(string csv) | 629 | public static list FromCSV(string csv) |