1
0

Fix RSORT

This commit is contained in:
otya128
2017-07-28 23:08:09 +09:00
parent 3eae20517a
commit e405dc66e4
3 changed files with 49 additions and 24 deletions

View File

@@ -57,6 +57,8 @@ DEF SORTTEST
RSORT B$ RSORT B$
ASSERT__ B$[3]=="0","RSORT2" ASSERT__ B$[3]=="0","RSORT2"
SORTTEST2 SORTTEST2
STABLESORTTEST
STABLERSORTTEST
END END
DEF SORTTEST2 DEF SORTTEST2
DIM A[10] DIM A[10]
@@ -70,6 +72,39 @@ DEF SORTTEST2
ASSERT__ A[8]==-1,"RSORT" ASSERT__ A[8]==-1,"RSORT"
ASSERT__ B[8]==12345,"RSORT" ASSERT__ B[8]==12345,"RSORT"
END END
DEF STABLESORTTEST
DIM A[0],B[0]
PUSH A,2:PUSH B,3
PUSH A,3:PUSH B,4
PUSH A,1:PUSH B,1
PUSH A,1:PUSH B,2
SORT A,B
ASSERT__ A[0]==1,"STABLESORT"
ASSERT__ A[1]==1,"STABLESORT"
ASSERT__ A[2]==2,"STABLESORT"
ASSERT__ A[3]==3,"STABLESORT"
ASSERT__ B[0]==1,"STABLESORT"
ASSERT__ B[1]==2,"STABLESORT"
ASSERT__ B[2]==3,"STABLESORT"
ASSERT__ B[3]==4,"STABLESORT"
END
DEF STABLERSORTTEST
DIM A[0],B[0]
PUSH A,2:PUSH B,3
PUSH A,3:PUSH B,4
PUSH A,1:PUSH B,1
PUSH A,1:PUSH B,2
RSORT A,B
ASSERT__ A[0]==3,"STABLESORT"
ASSERT__ A[1]==2,"STABLESORT"
ASSERT__ A[2]==1,"STABLESORT"
ASSERT__ A[3]==1,"STABLESORT"
ASSERT__ B[0]==4,"STABLESORT"
ASSERT__ B[1]==3,"STABLESORT"
ASSERT__ B[2]==2,"STABLESORT"
ASSERT__ B[3]==1,"STABLESORT"
END
?"SORTTEST" ?"SORTTEST"
SORTTEST SORTTEST
?"SWAPTEST" ?"SWAPTEST"

View File

@@ -237,7 +237,7 @@ class BG
for(int i = x; i <= x2; i++) for(int i = x; i <= x2; i++)
{ {
chip[i + y * width] = BGChip(screendata[index] & 4095); chip[i + y * width] = BGChip(screendata[index] & 4095);
index = (index + 1) % screendata.length; index = (index + 1) % cast(int)screendata.length;
} }
} }
int get(int x, int y, int flag) int get(int x, int y, int flag)

View File

@@ -3590,42 +3590,32 @@ class BuiltinFunction
} }
static void RSORT(Value[] arg) static void RSORT(Value[] arg)
{ {
SORT(arg);
import std.range; import std.range;
int start, count; int start, count;
auto args = getSortArgument(arg, start, count); auto args = getSortArgument(arg, start, count);
import std.algorithm;
int[] iarray; int[] iarray;
double[] darray; double[] darray;
Array!wchar[] sarray; Array!wchar[] sarray;
if (args[0].type == ValueType.IntegerArray) foreach (a; args)
{ {
iarray = args[0].integerArray.array[start..start + count]; if (a.type == ValueType.IntegerArray)
}
if (args[0].type == ValueType.DoubleArray)
{
darray = args[0].doubleArray.array[start..start + count];
}
if (args[0].type == ValueType.StringArray)
{
sarray = args[0].stringArray.array[start..start + count];
}
if (args.length > 1)
{
mixin(sortGenerator!(8, "\"a[0]>b[0]\""));
}
else
{
if (args[0].type == ValueType.IntegerArray)
{ {
sort!("a > b", SwapStrategy.stable)(iarray); iarray = a.integerArray.array[start..start + count];
reverse(iarray);
} }
if (args[0].type == ValueType.DoubleArray) if (a.type == ValueType.DoubleArray)
{ {
sort!("a > b", SwapStrategy.stable)(darray); darray = a.doubleArray.array[start..start + count];
reverse(darray);
} }
if (args[0].type == ValueType.StringArray) if (a.type == ValueType.StringArray)
{ {
sort!("a > b", SwapStrategy.stable)(sarray); sarray = a.stringArray.array[start..start + count];
reverse(sarray);
} }
} }
} }