Janilabo

Janilabo | TIAByRange() & TIAByRange2bit [SCAR Divi]

May 11th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.13 KB | None | 0 0
  1. const
  2.   LOWEST = -250000;
  3.   HIGHEST = 250000;
  4.  
  5. function TIAByRange(aStart, aFinish: Integer): TIntArray;
  6. {==============================================================================]  
  7.   Explanation: Returns a TIA that contains all the value from start value (aStart) to finishing value (aFinish)..                  
  8. [==============================================================================}
  9. var
  10.   i, s, f: Integer;
  11. begin
  12.   if (aStart <> aFinish) then
  13.   begin
  14.     s := Integer(aStart);
  15.     f := Integer(aFinish);
  16.     SetLength(Result, (IAbs(aStart - aFinish) + 1));
  17.     case (aStart > aFinish) of
  18.       True:
  19.       for i := s downto f do
  20.         Result[(s - i)] := i;
  21.       False:
  22.       for i := s to f do
  23.         Result[(i - s)] := i;
  24.     end;
  25.   end else
  26.     Result := [Integer(aStart)];
  27. end;
  28.  
  29. function TIAByRange2bit(aStart, aFinish: Integer): TIntArray;
  30. {==============================================================================]  
  31.   Explanation: Returns a TIA that contains all the value from start value (aStart) to finishing value (aFinish)..
  32.   NOTE: Works with 2-bit method, that cuts loop in half.                  
  33. [==============================================================================}
  34. var
  35.   g, l, i, s, f: Integer;
  36. begin
  37.   if (aStart <> aFinish) then
  38.   begin
  39.     s := Integer(aStart);
  40.     f := Integer(aFinish);
  41.     l := (IAbs(aStart - aFinish) + 1);            
  42.     SetLength(Result, l);    
  43.     g := ((l - 1) div 2);  
  44.     case (aStart < aFinish) of
  45.       True:
  46.       begin
  47.         for i := 0 to g do
  48.         begin                      
  49.           Result[i] := (s + i);
  50.           Result[((l - 1) - i)] := (f - i);
  51.         end;
  52.         if ((l mod 2) <> 0) then
  53.           Result[i] := (s + i);  
  54.       end;
  55.       False:
  56.       begin
  57.         for i := 0 to g do
  58.         begin                      
  59.           Result[i] := (s - i);
  60.           Result[((l - 1) - i)] := (f + i);
  61.         end;
  62.         if ((l mod 2) <> 0) then
  63.           Result[i] := (s - i);  
  64.       end;  
  65.     end;    
  66.   end else
  67.     Result := [Integer(aStart)];
  68. end;
  69.  
  70. var
  71.   tmp: TIntArray;
  72.   t: Integer;
  73.  
  74. begin
  75.   ClearDebug;
  76.   t := GetSystemTime;
  77.   tmp := TIAByRange(LOWEST, HIGHEST);
  78.   t := (GetSystemTime - t);
  79.   WriteLn('[' + IntToStr(tmp[0]) + '..' + IntToStr(tmp[High(tmp)]) + '] built in ' + IntToStr(t) + ' ms. using TIAByRange()');
  80.   SetLength(tmp, 0);
  81.   t := GetSystemTime;
  82.   tmp := TIAByRange(HIGHEST, LOWEST);
  83.   t := (GetSystemTime - t);
  84.   WriteLn('[' + IntToStr(tmp[0]) + '..' + IntToStr(tmp[High(tmp)]) + '] built in ' + IntToStr(t) + ' ms. using TIAByRange()');
  85.   SetLength(tmp, 0);        
  86.   t := GetSystemTime;
  87.   tmp := TIAByRange2bit(LOWEST, HIGHEST);
  88.   t := (GetSystemTime - t);
  89.   WriteLn('[' + IntToStr(tmp[0]) + '..' + IntToStr(tmp[High(tmp)]) + '] built in ' + IntToStr(t) + ' ms. using TIAByRange2bit()');
  90.   SetLength(tmp, 0);
  91.   t := GetSystemTime;
  92.   tmp := TIAByRange2bit(HIGHEST, LOWEST);
  93.   t := (GetSystemTime - t);
  94.   WriteLn('[' + IntToStr(tmp[0]) + '..' + IntToStr(tmp[High(tmp)]) + '] built in ' + IntToStr(t) + ' ms. using TIAByRange2bit()');
  95.   SetLength(tmp, 0);  
  96. end.
Advertisement
Add Comment
Please, Sign In to add comment