Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- RANGE1_START = -999999;
- RANGE1_FINISH = 999999;
- function TIAByRange(aStart, aFinish: Integer): TIntArray;
- var
- i: Integer;
- begin
- if (aStart <> aFinish) then
- begin
- SetLength(Result, (IAbs(aStart - aFinish) + 1));
- if (aStart > aFinish) then
- for i := aStart downto aFinish do
- Result[(aStart - i)] := i
- else
- for i := aStart to aFinish do
- Result[(i - aStart)] := i;
- end else
- Result := [aStart];
- end;
- function TIAByRange2bit(aStart, aFinish: Integer): TIntArray;
- var
- g, l, i: Integer;
- r: Boolean;
- begin
- if (aStart <> aFinish) then
- begin
- l := (IAbs(aStart - aFinish) + 1);
- SetLength(Result, l);
- g := ((l - 1) div 2);
- r := (aStart < aFinish);
- case r of
- True:
- begin
- for i := 0 to g do
- begin
- Result[i] := (aStart + i);
- Result[((l - 1) - i)] := (aFinish - i);
- end;
- if ((l mod 2) <> 0) then
- Result[i] := (aStart + i);
- end;
- False:
- begin
- for i := 0 to g do
- begin
- Result[i] := (aStart - i);
- Result[((l - 1) - i)] := (aFinish + i);
- end;
- if ((l mod 2) <> 0) then
- Result[i] := (aStart - i);
- end;
- end;
- end else
- Result := [aStart];
- end;
- const
- RANGE2_START = RANGE1_FINISH;
- RANGE2_FINISH = RANGE1_START;
- var
- t: Integer;
- TIA: TIntArray;
- begin
- ClearDebug;
- t := GetSystemTime;
- TIA := TIAByRange(RANGE1_START, RANGE1_FINISH);
- WriteLn('TIAByRange(' + IntToStr(RANGE1_START) + ', ' + IntToStr(RANGE1_FINISH) + '): ' + IntToStr(Length(TIA)) + ' items [' + IntToStr(GetSystemTime - t) + ' ms.]' );
- SetLength(TIA, 0);
- t := GetSystemTime;
- TIA := TIAByRange2Bit(RANGE1_START, RANGE1_FINISH);
- WriteLn('TIAByRange2bit(' + IntToStr(RANGE1_START) + ', ' + IntToStr(RANGE1_FINISH) + '): ' + IntToStr(Length(TIA)) + ' items [' + IntToStr(GetSystemTime - t) + ' ms.]' );
- SetLength(TIA, 0);
- t := GetSystemTime;
- TIA := TIAByRange(RANGE2_START, RANGE2_FINISH);
- WriteLn('TIAByRange(' + IntToStr(RANGE2_START) + ', ' + IntToStr(RANGE2_FINISH) + '): ' + IntToStr(Length(TIA)) + ' items [' + IntToStr(GetSystemTime - t) + ' ms.]' );
- SetLength(TIA, 0);
- t := GetSystemTime;
- TIA := TIAByRange2Bit(RANGE2_START, RANGE2_FINISH);
- WriteLn('TIAByRange2bit(' + IntToStr(RANGE2_START) + ', ' + IntToStr(RANGE2_FINISH) + '): ' + IntToStr(Length(TIA)) + ' items [' + IntToStr(GetSystemTime - t) + ' ms.]' );
- SetLength(TIA, 0);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement