Thank you Melanie for implementing

llListSort() in linear and strided modes.
0.6.0-stable
Charles Krinke 2008-04-26 20:49:38 +00:00
parent b1632bd222
commit 7cb78d73eb
2 changed files with 65 additions and 36 deletions

View File

@ -2874,42 +2874,7 @@ namespace OpenSim.Region.ScriptEngine.Common
public LSL_Types.list llListSort(LSL_Types.list src, int stride, int ascending)
{
m_host.AddScriptLPS(1);
// SortedList<string, LSL_Types.list> sorted = new SortedList<string, LSL_Types.list>();
// Add chunks to an array
//int s = stride;
//if (s < 1)
// s = 1;
//int c = 0;
//LSL_Types.list chunk = new LSL_Types.list();
//string chunkString = String.Empty;
//foreach (string element in src)
//{
// c++;
// if (c > s)
// {
// sorted.Add(chunkString, chunk);
// chunkString = String.Empty;
// chunk = new LSL_Types.list();
// c = 0;
// }
// chunk.Add(element);
// chunkString += element.ToString();
//}
//if (chunk.Count > 0)
// sorted.Add(chunkString, chunk);
//LSL_Types.list ret = new LSL_Types.list();
//foreach (LSL_Types.list ls in sorted.Values)
//{
// ret.AddRange(ls);
//}
//if (ascending == LSL_BaseClass.TRUE)
// return ret;
//ret.Reverse();
//return ret;
NotImplemented("llListSort");
return new LSL_Types.list();
return src.Sort(stride, ascending);
}
public int llGetListLength(LSL_Types.list src)

View File

@ -560,6 +560,70 @@ namespace OpenSim.Region.ScriptEngine.Common
}
}
public list Sort(int stride, int ascending)
{
if(Data.Length == 0)
return new list(); // Don't even bother
if(stride == 1) // The simple case
{
Object[] ret=new Object[Data.Length];
Array.Copy(Data, 0, ret, 0, Data.Length);
Array.Sort(ret);
if(ascending == 0)
Array.Reverse(ret);
return new list(ret);
}
int src=0;
int len=(Data.Length+stride-1)/stride;
string[] keys=new string[len];
Object[][] vals=new Object[len][];
int i;
while(src < Data.Length)
{
Object[] o=new Object[stride];
for(i=0;i<stride;i++)
{
if(src < Data.Length)
o[i]=Data[src++];
else
{
o[i]=new Object();
src++;
}
}
int idx=src/stride-1;
keys[idx]=o[0].ToString();
vals[idx]=o;
}
Array.Sort(keys, vals);
if(ascending == 0)
{
Array.Reverse(vals);
}
Object[] sorted=new Object[stride*vals.Length];
int j;
for(i=0;i<vals.Length;i++)
for(j=0;j<stride;j++)
sorted[i*stride+j]=vals[i][j];
return new list(sorted);
}
#region CSV Methods
public static list FromCSV(string csv)