From: <tw...@us...> - 2020-09-05 17:29:34
|
Revision: 3286 http://sourceforge.net/p/gexperts/code/3286 Author: twm Date: 2020-09-05 17:29:31 +0000 (Sat, 05 Sep 2020) Log Message: ----------- updated to latest dzlib version from OSDN Modified Paths: -------------- trunk/ExternalSource/dzlib/u_dzGraphicsUtils.pas trunk/ExternalSource/dzlib/u_dzQuicksort.pas trunk/ExternalSource/dzlib/u_dzSortUtils.pas trunk/ExternalSource/dzlib/u_dzStringArrayUtils.pas trunk/ExternalSource/dzlib/u_dzVclUtils.pas Modified: trunk/ExternalSource/dzlib/u_dzGraphicsUtils.pas =================================================================== --- trunk/ExternalSource/dzlib/u_dzGraphicsUtils.pas 2020-09-05 17:18:23 UTC (rev 3285) +++ trunk/ExternalSource/dzlib/u_dzGraphicsUtils.pas 2020-09-05 17:29:31 UTC (rev 3286) @@ -274,6 +274,21 @@ inline; {$ENDIF} +///<summary> abbreviation for StretchBlt that takes TCanvas and TPoint values. </summary> +function dzStretchBlt(_DestCnv: TCanvas; _DestTopLeft: TPoint; _DestSize: TPoint; + _SrcCnv: TCanvas; _SrcTopLeft: TPoint; _SrcSize: TPoint; _Rop: DWORD = SRCCOPY): BOOL; overload; +{$IFDEF SUPPORTS_INLINE}inline; {$ENDIF} + +///<summary> abbreviation for StretchBlt that takes TCanvas, TBitmap and TPoint values. </summary> +function dzStretchBlt(_DestCnv: TCanvas; _DestTopLeft: TPoint; _DestSize: TPoint; + _SrcBmp: TBitmap; _SrcTopLeft: TPoint; _SrcSize: TPoint; _Rop: DWORD = SRCCOPY): BOOL; overload; +{$IFDEF SUPPORTS_INLINE}inline; {$ENDIF} + +///<summary> abbreviation for StretchBlt that takes two TBitmap and TPoint values. </summary> +function dzStretchBlt(_DestBmp: TBitmap; _DestTopLeft: TPoint; _DestSize: TPoint; + _SrcBmp: TBitmap; _SrcTopLeft: TPoint; _SrcSize: TPoint; _Rop: DWORD = SRCCOPY): BOOL; overload; +{$IFDEF SUPPORTS_INLINE}inline; {$ENDIF} + ///<summary> abbreviation for StretchBlt that takes TRect </summary> function dzStretchBlt(_DestHandle: Hdc; _DestRect: TRect; _SrcHandle: Hdc; _SrcRect: TRect; _Rop: DWORD = SRCCOPY): LongBool; overload; @@ -657,6 +672,31 @@ Result := dzDGetText(_s, 'dzlib'); end; +function dzStretchBlt(_DestCnv: TCanvas; _DestTopLeft: TPoint; _DestSize: TPoint; + _SrcCnv: TCanvas; _SrcTopLeft: TPoint; _SrcSize: TPoint; _Rop: DWORD): BOOL; +begin + Result := StretchBlt(_DestCnv.Handle, + _DestTopLeft.x, _DestTopLeft.y, + _DestSize.x, _DestSize.y, + _SrcCnv.Handle, + _SrcTopLeft.x, _SrcTopLeft.y, + _SrcSize.x, _SrcSize.y, _Rop); +end; + +function dzStretchBlt(_DestCnv: TCanvas; _DestTopLeft: TPoint; _DestSize: TPoint; + _SrcBmp: TBitmap; _SrcTopLeft: TPoint; _SrcSize: TPoint; _Rop: DWORD = SRCCOPY): BOOL; +begin + Result := dzStretchBlt(_DestCnv, _DestTopLeft, _DestSize, + _SrcBmp.Canvas, _SrcTopLeft, _SrcSize, _Rop); +end; + +function dzStretchBlt(_DestBmp: TBitmap; _DestTopLeft: TPoint; _DestSize: TPoint; + _SrcBmp: TBitmap; _SrcTopLeft: TPoint; _SrcSize: TPoint; _Rop: DWORD = SRCCOPY): BOOL; overload; +begin + Result := dzStretchBlt(_DestBmp.Canvas, _DestTopLeft, _DestSize, + _SrcBmp.Canvas, _SrcTopLeft, _SrcSize, _Rop); +end; + function dzStretchBlt(_DestHandle: Hdc; _DestRect: TRect; _SrcHandle: Hdc; _SrcRect: TRect; _Rop: DWORD): LongBool; begin Result := StretchBlt(_DestHandle, _DestRect.Left, _DestRect.Top, TRect_Width(_DestRect), TRect_Height(_DestRect), Modified: trunk/ExternalSource/dzlib/u_dzQuicksort.pas =================================================================== --- trunk/ExternalSource/dzlib/u_dzQuicksort.pas 2020-09-05 17:18:23 UTC (rev 3285) +++ trunk/ExternalSource/dzlib/u_dzQuicksort.pas 2020-09-05 17:29:31 UTC (rev 3286) @@ -67,11 +67,14 @@ I, J, P: Integer; begin if _Left >= _Right then - exit; + Exit; //==> repeat I := _Left; J := _Right; - P := (_Left + _Right) shr 1; +// P := (_Left + _Right) shr 1; + // Chosing the pivot element can make a big difference: + // In my unit tests its factor 100 for the TestPartSortedPartReverse test + P := GetPivot(I, J, _DataHandler); repeat while _DataHandler.Compare(I, P) < 0 do Inc(I); @@ -100,11 +103,14 @@ I, J, P: Integer; begin if _Left >= _Right then - exit; + Exit; //==> repeat I := _Left; J := _Right; - P := (_Left + _Right) shr 1; +// P := (_Left + _Right) shr 1; + // Chosing the pivot element can make a big difference: + // In my unit tests its factor 100 for the TestPartSortedPartReverse test + P := GetPivot(I, J, _CompareMeth); repeat while _CompareMeth(I, P) < 0 do Inc(I); Modified: trunk/ExternalSource/dzlib/u_dzSortUtils.pas =================================================================== --- trunk/ExternalSource/dzlib/u_dzSortUtils.pas 2020-09-05 17:18:23 UTC (rev 3285) +++ trunk/ExternalSource/dzlib/u_dzSortUtils.pas 2020-09-05 17:29:31 UTC (rev 3286) @@ -42,6 +42,59 @@ {$ENDIF} ; +///<summary> +/// Try to optimize the pivot by chosing the median of Left, Right and ((Left + Right) shr 1) </summary> +function GetPivot(_Left, _Right: Integer; _CompareMeth: TCompareItemsMeth): Integer; inline; overload; +///<summary> +/// Try to optimize the pivot by chosing the median of Left, Right and ((Left + Right) shr 1) </summary> +function GetPivot(_Left, _Right: Integer; _DataHandler: ISortDataHandler): Integer; inline; overload; + implementation +function GetPivot(_Left, _Right: Integer; _CompareMeth: TCompareItemsMeth): Integer; +begin + Result := (_Left + _Right) shr 1; + // try to optimize the pivot by chosing the + // median of Left, Right and Result: + if _CompareMeth(_Left, Result) > 0 then begin + if _CompareMeth(Result, _Right) > 0 then begin + // Result is already the median + end else if _CompareMeth(_Right, _Left) > 0 then begin + Result := _Left; + end else + Result := _Right; + end else begin + if _CompareMeth(_Right, Result) > 0 then begin + // Result is already the median + end else if _CompareMeth(_Left, _Right) > 0 then begin + Result := _Left; + end else begin + Result := _Right; + end; + end; +end; + +function GetPivot(_Left, _Right: Integer; _DataHandler: ISortDataHandler): Integer; +begin + Result := (_Left + _Right) shr 1; + // try to optimize the pivot by chosing the + // median of Left, Right and Result: + if _DataHandler.Compare(_Left, Result) > 0 then begin + if _DataHandler.Compare(Result, _Right) > 0 then begin + // Result is already the median + end else if _DataHandler.Compare(_Right, _Left) > 0 then begin + Result := _Left; + end else + Result := _Right; + end else begin + if _DataHandler.Compare(_Right, Result) > 0 then begin + // Result is already the median + end else if _DataHandler.Compare(_Left, _Right) > 0 then begin + Result := _Left; + end else begin + Result := _Right; + end; + end; +end; + end. Modified: trunk/ExternalSource/dzlib/u_dzStringArrayUtils.pas =================================================================== --- trunk/ExternalSource/dzlib/u_dzStringArrayUtils.pas 2020-09-05 17:18:23 UTC (rev 3285) +++ trunk/ExternalSource/dzlib/u_dzStringArrayUtils.pas 2020-09-05 17:29:31 UTC (rev 3286) @@ -22,6 +22,9 @@ /// @raises ERangeCheck if Index or Count < 0 </summary> procedure TStringArray_Delete(var _arr: TStringArray; _Index: Integer; _Count: Integer); +function TStringArray_Contains(const _arr: TStringArray; const _s: string; out _Idx: Integer): Boolean; overload; +function TStringArray_Contains(const _arr: TStringArray; const _s: string): Boolean; overload; + function TStringArray_FromStrings(_sl: TStrings): TStringArray; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF} @@ -133,6 +136,26 @@ Setlength(_arr, len - _Count); end; +function TStringArray_Contains(const _arr: TStringArray; const _s: string; out _Idx: Integer): Boolean; +var + i: Integer; +begin + for i := Low(_arr) to High(_arr) do begin + if _arr[i] = _s then begin + Result := True; + Exit; //==> + end; + end; + Result := False; +end; + +function TStringArray_Contains(const _arr: TStringArray; const _s: string): Boolean; +var + Idx: Integer; +begin + Result := TStringArray_Contains(_arr, _s, Idx); +end; + function TStringArray_Concat(const _Arr1, _Arr2: array of string): TStringArray; var Len1: Integer; Modified: trunk/ExternalSource/dzlib/u_dzVclUtils.pas =================================================================== --- trunk/ExternalSource/dzlib/u_dzVclUtils.pas 2020-09-05 17:18:23 UTC (rev 3285) +++ trunk/ExternalSource/dzlib/u_dzVclUtils.pas 2020-09-05 17:29:31 UTC (rev 3286) @@ -46,7 +46,7 @@ type ///<summary> Ancestor to all exceptions raised in this unit. </summary> - EdzVclUtils = class(Exception); + EdzVclUtils = class(EdzException); ///<summary> raised if the Combobox passed to SetOwnerDrawComboItemCount is not owner drawn. </summary> EdzComboBoxNotOwnerDraw = class(EdzVclUtils); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |