PDA

View Full Version : ClearSameIntT2D



BraK
12-14-2011, 12:13 AM
It will probably never make it into SIMBA but here is my ClearSameIntT2D procedure. All it does is go through all the Integer arrays in the T2D Array compare them to each other as well as the previously deleted integers and clear out all like integers. I doesn't just get rid of duplicates it completely deletes any and all like integers.

@euphemism This is the first step towards my project we talke about the other night. ;)

Below is the test script for the procedure it will not have the writelns in the used version. I attached the test script in a .simba file for ease.

Any feedback is very much appreciated.

program T2DIntClearSame;

var
Test, T2I: T2DIntegerArray;

procedure ClearSameIntT2D(var T2DArray: T2DIntegerArray);
var
I, II, III: Integer;
ArrayOut: T2DIntegerArray;
DeleteSet: TIntegerArray;

begin
For I := 0 to High(T2DArray) do
ClearSameIntegers(T2DArray[I]);
SetArrayLength(ArrayOut, Length(T2DArray));
Writeln('Starting T2D Array After ClearSameIntegers := ' + tostr(T2DArray));
for I := 0 to High(T2DArray) do
for II := 0 to High(T2DArray[I]) do
for III := 0 to High(T2DArray) do
If I = III then
continue
else if InIntArray(T2DArray[III],T2DArray[I][II]) or InIntArray(DeleteSet, T2DArray[I][II]) then
begin
SetArrayLength(DeleteSet, Length(DeleteSet) + 1);
DeleteSet[Length(DeleteSet) - 1] := T2DArray[I][II];
end else
begin
SetArrayLength(ArrayOut[I], Length(ArrayOut[I]) + 1);
ArrayOut[I][Length(ArrayOut[I]) - 1] := T2DArray[I][II];
end;
ClearSameIntegers(DeleteSet);
writeln('Deleted Integers := ' + tostr(DeleteSet));
For I := 0 to High(ArrayOut) do
ClearSameIntegers(ArrayOut[I]);
T2DArray := ArrayOut;
end;

begin
SetArrayLength(T2I, 3);
T2I[0] := [1,1,2,4,4,5,6];
T2I[1] := [2,3,4,5,5,9,9];
T2I[2] := [2,4,6,7,8,8];
ClearSameIntT2D(T2I);
writeln('Output T2D Array := ' + tostr(T2I));
end.

euphemism
12-14-2011, 12:39 AM
Looks intense. Not sure what to say, the test seemed to be successful.

BraK
12-14-2011, 12:44 AM
Getting the Inside for the Triple For To Do loop working correctly was fun. That chewed up only a hour worth of time. :( I still got 7 hours to go on duty with nothing to really do...

euphemism
12-14-2011, 01:44 AM
Getting the Inside for the Triple For To Do loop working correctly was fun. That chewed up only a hour worth of time. :( I still got 7 hours to go on duty with nothing to really do...

I know what you mean. I have a quadruple For To Do loop in the Object DTM Include. :p

BraK
12-14-2011, 01:49 AM
I know what you mean. I have a quadruple For To Do loop in the Object DTM Include. :p

lol nice. I'm actually quite happy I only set this up for a T2DIntegerArray and not a T3DIntegerArray. I would have had fun trying to work that in XD. Probably would have ended in 4 or 5 for to do loops. That indeed would have been a pain. This I can use as a sub procedure to make things easier.