aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs37
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_Types.cs64
2 files changed, 65 insertions, 36 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
index 1a3b6ce..09be26a 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
@@ -2874,42 +2874,7 @@ namespace OpenSim.Region.ScriptEngine.Common
2874 public LSL_Types.list llListSort(LSL_Types.list src, int stride, int ascending) 2874 public LSL_Types.list llListSort(LSL_Types.list src, int stride, int ascending)
2875 { 2875 {
2876 m_host.AddScriptLPS(1); 2876 m_host.AddScriptLPS(1);
2877 // SortedList<string, LSL_Types.list> sorted = new SortedList<string, LSL_Types.list>(); 2877 return src.Sort(stride, ascending);
2878 // Add chunks to an array
2879 //int s = stride;
2880 //if (s < 1)
2881 // s = 1;
2882 //int c = 0;
2883 //LSL_Types.list chunk = new LSL_Types.list();
2884 //string chunkString = String.Empty;
2885 //foreach (string element in src)
2886 //{
2887 // c++;
2888 // if (c > s)
2889 // {
2890 // sorted.Add(chunkString, chunk);
2891 // chunkString = String.Empty;
2892 // chunk = new LSL_Types.list();
2893 // c = 0;
2894 // }
2895 // chunk.Add(element);
2896 // chunkString += element.ToString();
2897 //}
2898 //if (chunk.Count > 0)
2899 // sorted.Add(chunkString, chunk);
2900
2901 //LSL_Types.list ret = new LSL_Types.list();
2902 //foreach (LSL_Types.list ls in sorted.Values)
2903 //{
2904 // ret.AddRange(ls);
2905 //}
2906
2907 //if (ascending == LSL_BaseClass.TRUE)
2908 // return ret;
2909 //ret.Reverse();
2910 //return ret;
2911 NotImplemented("llListSort");
2912 return new LSL_Types.list();
2913 } 2878 }
2914 2879
2915 public int llGetListLength(LSL_Types.list src) 2880 public int llGetListLength(LSL_Types.list src)
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)