Class TPStringSort (unit mwPStringSort) |
Inherits from
TObject
constructor create;
- TPStringSort
function Add(Item: String):Integer;
procedure Clear;
procedure CombSortW(SorCompare: TPStringSortCompare);
Driver for the " Comb " routine.
destructor Destroy;
procedure MergeSort(SorCompare: TPStringSortCompare);
Non-recursive Mergesort.
procedure Pack;
procedure QuickSort(SorCompare: TPStringSortCompare);
Based on a non-recursive QuickSort from the SWAG-Archive.
procedure Tokenize(OriginPtr: PChar; StartCapacity: Integer);
function GetItems(Index: Integer):PString;
procedure SetItems(Index: Integer; Item: PString);
function Comb(jumpsize0: Integer; SorCompare: TPStringSortCompare): boolean;
Multipication by 0.
procedure Expand;
function GetToken(Index: Integer):String;
procedure Merge(PosA, PosB, PosLastA, PosLastB: LongInt; SorCompare: TPStringSortCompare);
Unfortunately the " Merge " routine needs additional memory
An Algorithm to perform merging in linear time without extra space
is described in:
B.
procedure SetCapacity(NewCapacity:Integer);
property Capacity : Integer
property Count : Integer
property Items : PString
property Origin : PChar
property Token : String
fCapacity : Integer;
FCount : Integer;
fOrigin : PChar;
FSorArray : PStringArray;
FString : PString;
SwapArray : PStringArray;
TempArray : PStringArray;
constructor create;
TPStringSort
function Add(Item: String):Integer;
procedure Clear;
procedure CombSortW(SorCompare: TPStringSortCompare);
Driver for the " Comb " routine.
Based on routines from the SWAG-Archive.
Very fast, for a smaller number of items with large keys
" Comb " may outperform Quicksort.
( Only a few thousends
destructor Destroy;
procedure MergeSort(SorCompare: TPStringSortCompare);
Non-recursive Mergesort.
Very fast, if enough memory available.
The number of comparisions used is nearly optimal, about 3/4 of QuickSort.
If comparision plays a very more important role than exchangement,
it outperforms QuickSort in any case.
( Large keys or a time intensive comparision like AnsiCompareText )
From all Algoritms with O(N lg N) it's the only stable, meaning it lefts
equal keys in the order of input. This may be important in some cases.
procedure Pack;
procedure QuickSort(SorCompare: TPStringSortCompare);
Based on a non-recursive QuickSort from the SWAG-Archive.
( TV Sorting Unit by Brad Williams )
procedure Tokenize(OriginPtr: PChar; StartCapacity: Integer);
function GetItems(Index: Integer):PString;
procedure SetItems(Index: Integer; Item: PString);
function Comb(jumpsize0: Integer; SorCompare: TPStringSortCompare): boolean;
Multipication by 0.76 gives a slightly better result than
division by 1.3.
Because of the FOR loop it runs faster on arrays starting with one
procedure Expand;
function GetToken(Index: Integer):String;
procedure Merge(PosA, PosB, PosLastA, PosLastB: LongInt; SorCompare: TPStringSortCompare);
Unfortunately the " Merge " routine needs additional memory
An Algorithm to perform merging in linear time without extra space
is described in:
B. Huang and M. Langston, " Practical In-place Merging ",
Communications of the ACM 31(1988), 348-352.
procedure SetCapacity(NewCapacity:Integer);
property Capacity : Integer
property Count : Integer
property Items : PString
property Origin : PChar
property Token : String
fCapacity : Integer;
FCount : Integer;
fOrigin : PChar;
FSorArray : PStringArray;
FString : PString;
SwapArray : PStringArray;
TempArray : PStringArray;