Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- LOWEST = -250000;
- HIGHEST = 250000;
- function TIAByRange(aStart, aFinish: Integer): TIntArray;
- {==============================================================================]
- Explanation: Returns a TIA that contains all the value from start value (aStart) to finishing value (aFinish)..
- [==============================================================================}
- var
- i, s, f: Integer;
- begin
- if (aStart <> aFinish) then
- begin
- s := Integer(aStart);
- f := Integer(aFinish);
- SetLength(Result, (IAbs(aStart - aFinish) + 1));
- case (aStart > aFinish) of
- True:
- for i := s downto f do
- Result[(s - i)] := i;
- False:
- for i := s to f do
- Result[(i - s)] := i;
- end;
- end else
- Result := [Integer(aStart)];
- end;
- function TIAByRange2bit(aStart, aFinish: Integer): TIntArray;
- {==============================================================================]
- Explanation: Returns a TIA that contains all the value from start value (aStart) to finishing value (aFinish)..
- NOTE: Works with 2-bit method, that cuts loop in half.
- [==============================================================================}
- var
- g, l, i, s, f: Integer;
- begin
- if (aStart <> aFinish) then
- begin
- s := Integer(aStart);
- f := Integer(aFinish);
- l := (IAbs(aStart - aFinish) + 1);
- SetLength(Result, l);
- g := ((l - 1) div 2);
- case (aStart < aFinish) of
- True:
- begin
- for i := 0 to g do
- begin
- Result[i] := (s + i);
- Result[((l - 1) - i)] := (f - i);
- end;
- if ((l mod 2) <> 0) then
- Result[i] := (s + i);
- end;
- False:
- begin
- for i := 0 to g do
- begin
- Result[i] := (s - i);
- Result[((l - 1) - i)] := (f + i);
- end;
- if ((l mod 2) <> 0) then
- Result[i] := (s - i);
- end;
- end;
- end else
- Result := [Integer(aStart)];
- end;
- var
- tmp: TIntArray;
- t: Integer;
- begin
- ClearDebug;
- t := GetSystemTime;
- tmp := TIAByRange(LOWEST, HIGHEST);
- t := (GetSystemTime - t);
- WriteLn('[' + IntToStr(tmp[0]) + '..' + IntToStr(tmp[High(tmp)]) + '] built in ' + IntToStr(t) + ' ms. using TIAByRange()');
- SetLength(tmp, 0);
- t := GetSystemTime;
- tmp := TIAByRange(HIGHEST, LOWEST);
- t := (GetSystemTime - t);
- WriteLn('[' + IntToStr(tmp[0]) + '..' + IntToStr(tmp[High(tmp)]) + '] built in ' + IntToStr(t) + ' ms. using TIAByRange()');
- SetLength(tmp, 0);
- t := GetSystemTime;
- tmp := TIAByRange2bit(LOWEST, HIGHEST);
- t := (GetSystemTime - t);
- WriteLn('[' + IntToStr(tmp[0]) + '..' + IntToStr(tmp[High(tmp)]) + '] built in ' + IntToStr(t) + ' ms. using TIAByRange2bit()');
- SetLength(tmp, 0);
- t := GetSystemTime;
- tmp := TIAByRange2bit(HIGHEST, LOWEST);
- t := (GetSystemTime - t);
- WriteLn('[' + IntToStr(tmp[0]) + '..' + IntToStr(tmp[High(tmp)]) + '] built in ' + IntToStr(t) + ' ms. using TIAByRange2bit()');
- SetLength(tmp, 0);
- end.
Advertisement
Add Comment
Please, Sign In to add comment