Beispiel #1
0
        internal void DoSort(Node aNode, int[] aCols, SortDirection[] aDirections, OnCompareNodeDelegate aCompareFct, bool recurse)
        {
            Node run;

            if (aNode.ChildCount > 1)
            {
                Node[] children = aNode.Children;
                QuickSort(ref children, 0, children.Length - 1, aCols, aDirections, aCompareFct);
                //refaire les liaisons entre noeuds
                aNode.FirstChild        = children[0];
                children[0].PrevSibling = null;
                aNode.FirstChild.Index  = 0;
                for (int i = 1; i < children.Length; i++)
                {
                    children[i - 1].NextSibling = children[i];
                    children[i].PrevSibling     = children[i - 1];
                    children[i].Index           = i;
                }
                aNode.LastChild             = children[children.Length - 1];
                aNode.LastChild.NextSibling = null;
            }
            run = aNode.FirstChild;
            while (recurse && run != null)
            {
                DoSort(run, aCols, aDirections, aCompareFct, recurse);
                run = run.NextSibling;
            }
        }
Beispiel #2
0
 private int NodeComparison(Node A, Node B, int[] aCols, int[] multipliers, OnCompareNodeDelegate aFct)
 {
     for (int i = 0; i < aCols.Length; i++)
     {
         int Result = aFct(A, B, aCols[i]) * multipliers[i];
         if (Result != 0)
         {
             return(Result);
         }
     }
     return(0);
 }
Beispiel #3
0
        private void QuickSort(ref Node[] aTab, int L, int R, int[] aCols, SortDirection[] aDirections, int[] aMultipliers, OnCompareNodeDelegate aFct)
        {
            int I, J, P;

            do
            {
                I = L;
                J = R;
                P = (L + R) >> 1;
                do
                {
                    while (I <= P && NodeComparison(aTab[I], aTab[P], aCols, aMultipliers, aFct) < 0)
                    {
                        I++;
                    }
                    while (J >= P && NodeComparison(aTab[J], aTab[P], aCols, aMultipliers, aFct) > 0)
                    {
                        J--;
                    }
                    if (I <= J)
                    {
                        Node tmp = aTab[I];
                        aTab[I] = aTab[J];
                        aTab[J] = tmp;
                        if (P == I)
                        {
                            P = J;
                        }
                        else if (P == J)
                        {
                            P = I;
                        }
                        I++;
                        J--;
                    }
                }while (I <= J);
                if (L < J)
                {
                    QuickSort(ref aTab, L, J, aCols, aDirections, aMultipliers, aFct);
                }
                L = I;
            }while (I < R);
            #region quickSort Delphi
            //procedure TStringList.QuickSort(L, R: Integer; SCompare: TStringListSortCompare);
            //var
            //  I, J, P: Integer;
            //begin
            //  repeat
            //	I := L;
            //	J := R;
            //	P := (L + R) shr 1;
            //	repeat
            //	  while SCompare(Self, I, P) < 0 do Inc(I);
            //	  while SCompare(Self, J, P) > 0 do Dec(J);
            //	  if I <= J then
            //	  begin
            //		ExchangeItems(I, J);
            //		if P = I then
            //		  P := J
            //		else if P = J then
            //		  P := I;
            //		Inc(I);
            //		Dec(J);
            //	  end;
            //	until I > J;
            //	if L < J then QuickSort(L, J, SCompare);
            //	L := I;
            //  until I >= R;
            //end;
            #endregion
        }
Beispiel #4
0
 private void QuickSort(ref Node[] aTab, int L, int R, int[] aCols, SortDirection[] aDirections, OnCompareNodeDelegate aFct)
 {
     QuickSort(ref aTab, L, R, aCols, aDirections, QuickSortMultiplier(aDirections), aFct);
 }