コード例 #1
0
ファイル: TclList.cs プロジェクト: ekicyou/pasta
        /// <summary> Sorts the list according to the sort mode and (optional) sort command.
        /// The resulting list will contain no duplicates, if argument unique is
        /// specifed as true.
        /// If tobj is not a list object, an attempt will be made to
        /// convert it to a list.
        ///
        /// </summary>
        /// <param name="interp">the current interpreter.
        /// </param>
        /// <param name="tobj">the list to sort.
        /// </param>
        /// <param name="sortMode">the sorting mode.
        /// </param>
        /// <param name="sortIncreasing">true if to sort the elements in increasing order.
        /// </param>
        /// <param name="command">the command to compute the order of two elements.
        /// </param>
        /// <param name="unique">true if the result should contain no duplicates.
        /// </param>
        /// <exception cref=""> TclException if tobj is not a valid list.
        /// </exception>

        internal static void sort(Interp interp, TclObject tobj, int sortMode, int sortIndex, bool sortIncreasing, string command, bool unique)
        {
            setListFromAny(interp, tobj);
            tobj.invalidateStringRep();
            TclList tlist = (TclList)tobj.InternalRep;

            int size = tlist.vector.Count;

            if (size <= 1)
            {
                return;
            }

            TclObject[] objArray = new TclObject[size];
            for (int i = 0; i < size; i++)
            {
                objArray[i] = (TclObject)tlist.vector[i];
            }

            QSort s       = new QSort();
            int   newsize = s.sort(interp, objArray, sortMode, sortIndex, sortIncreasing, command, unique);

            for (int i = 0; i < size; i++)
            {
                if (i < newsize)
                {
                    tlist.vector[i] = objArray[i];
                    objArray[i]     = null;
                }
                else
                {
                    tlist.vector.RemoveAt(newsize);
                }
            }
        }
コード例 #2
0
ファイル: TclList.cs プロジェクト: Belxjander/Asuna
    /// <summary> Sorts the list according to the sort mode and (optional) sort command.
    /// The resulting list will contain no duplicates, if argument unique is
    /// specifed as true.
    /// If tobj is not a list object, an attempt will be made to
    /// convert it to a list.
    /// 
    /// </summary>
    /// <param name="interp">the current interpreter.
    /// </param>
    /// <param name="tobj">the list to sort.
    /// </param>
    /// <param name="sortMode">the sorting mode.
    /// </param>
    /// <param name="sortIncreasing">true if to sort the elements in increasing order.
    /// </param>
    /// <param name="command">the command to compute the order of two elements.
    /// </param>
    /// <param name="unique">true if the result should contain no duplicates.
    /// </param>
    /// <exception cref=""> TclException if tobj is not a valid list.
    /// </exception>

    internal static void sort( Interp interp, TclObject tobj, int sortMode, int sortIndex, bool sortIncreasing, string command, bool unique )
    {
      setListFromAny( interp, tobj );
      tobj.invalidateStringRep();
      TclList tlist = (TclList)tobj.InternalRep;

      int size = tlist.vector.Count;

      if ( size <= 1 )
      {
        return;
      }

      TclObject[] objArray = new TclObject[size];
      for ( int i = 0 ; i < size ; i++ )
      {
        objArray[i] = (TclObject)tlist.vector[i];
      }

      QSort s = new QSort();
      int newsize = s.sort( interp, objArray, sortMode, sortIndex, sortIncreasing, command, unique );

      for ( int i = 0 ; i < size   ; i++ )
      {
        if ( i < newsize )
        {
          tlist.vector[i] = objArray[i];
          objArray[i] = null;
        }
        else tlist.vector.RemoveAt( newsize  );
      }
    }