• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IComparer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IComparer的典型用法代码示例。如果您正苦于以下问题:C# IComparer类的具体用法?C# IComparer怎么用?C# IComparer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IComparer类属于命名空间,在下文中一共展示了IComparer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Sort

        /// <summary>
        /// Rearranges the array in ascending order, using the natural order.
        /// </summary>
        /// <param name="a">a the array to be sorted</param>
        public static void Sort(IComparable[] a, IComparer c = null)
        {
            //make sure we have the comparer passed by argument or create default
            IComparer comparer = c ?? Comparer<object>.Default;

            int N = a.Length;

            int h = 1;

            //3*x +1 -> 1, 4, 13, 40, 121, 364, ..
            while (h < N / 3)
            {
                h = 3 * h + 1;
            }

            while (h >= 1)
            {

                //h- sort array
                for (int i = h; i < N; i++)
                {
                    for (int j = i; j >= h && less(comparer, a[j], a[j - h]); j -= h)
                    {
                        exch(a, j, j - h);
                    }
                }

                Debug.Assert(isHsorted(a, comparer, h));
                h = h / 3;
            }

            Debug.Assert(isSorted(a, comparer));
        }
开发者ID:kostasgrevenitis,项目名称:algs4,代码行数:37,代码来源:Shell.cs


示例2: Sort

 public void Sort(
     int index,
     int count,
     IComparer comparer)
 {
     theList.Sort(index, count, comparer);
 }
开发者ID:rogue-bit,项目名称:Triton-Framework,代码行数:7,代码来源:SortedList.cs


示例3: AddSort

 public override void AddSort(object expr, IComparer comparer)
 {
     // sort makes sense only when we are dealing with a query that
     // returns a nodeset.
     Query evalExpr;
     string query = expr as string;
     if (query != null)
     {
         evalExpr = new QueryBuilder().Build(query, out _needContext); // this will throw if expr is invalid
     }
     else
     {
         CompiledXpathExpr xpathExpr = expr as CompiledXpathExpr;
         if (xpathExpr != null)
         {
             evalExpr = xpathExpr.QueryTree;
         }
         else
         {
             throw XPathException.Create(SR.Xp_BadQueryObject);
         }
     }
     SortQuery sortQuery = _query as SortQuery;
     if (sortQuery == null)
     {
         _query = sortQuery = new SortQuery(_query);
     }
     sortQuery.AddSort(evalExpr, comparer);
 }
开发者ID:Corillian,项目名称:corefx,代码行数:29,代码来源:CompiledXPathExpr.cs


示例4: ListViewColumnSorter

        public ListViewColumnSorter(IComparer comparer)
        {
            SortColumn = 0;
            SortOrder = SortOrder.Ascending;

            mComparer = comparer;
        }
开发者ID:NathanW2,项目名称:PhotoMapper,代码行数:7,代码来源:ListViewColumnSorter.cs


示例5: LastWriteTimeComparator

 // Methods
 public LastWriteTimeComparator(bool bAscending, IComparer subComparer)
 {
     this._IsAscending = true;
     this._InnerComparer = null;
     this.IsAscending = bAscending;
     this.InnerComparer = subComparer;
 }
开发者ID:jihadbird,项目名称:firespider,代码行数:8,代码来源:LastWriteTimeComparator.cs


示例6: TreeWithPointProvider

 public void TreeWithPointProvider(CustomPoint[] point, CustomPoint[] resultPoint, IComparer<CustomPoint> comparer)
 {
     var tree = new BinaryTree<CustomPoint>(point, comparer);
     var pointCompare = new PointComparer();
     var enumeratorBook = tree.Preorder().ToArray();
     CollectionAssert.AreEqual(enumeratorBook, resultPoint, pointCompare);
 }
开发者ID:ZheldakArtem,项目名称:EPAM.Summer.Day10-11.Zheldak,代码行数:7,代码来源:BinaryTreeTest.cs


示例7: create

 public static PersistentTreeSet create(IComparer comp, ISeq init)
 {
     PersistentTreeSet ret = new PersistentTreeSet(null, new PersistentTreeMap(null, comp));
     for (ISeq s = init; s != null; s = s.next())
         ret = (PersistentTreeSet)ret.cons(s.first());
     return ret;
 }
开发者ID:TerabyteX,项目名称:clojure-clr,代码行数:7,代码来源:PersistentTreeSet.cs


示例8: SortedCollection

 //==========================================================================================
 // Constructors
 //==========================================================================================
 /// <summary>
 /// Initializes a new instance of the <see cref="SortedCollection"/> class.
 /// </summary>
 /// <param name="comparer">An <see cref="IComparer"/> to use for the sorting.</param>
 protected SortedCollection(IComparer comparer)
     : base(new ArrayList())
 {
     Tracer.VerifyNonNullArgument(comparer, "comparer");
     this.comparer = comparer;
     this.list = (ArrayList)this.InnerCollection;
 }
开发者ID:sillsdev,项目名称:FwSupportTools,代码行数:14,代码来源:SortedCollection.cs


示例9: StockMessageFactory

 public StockMessageFactory(IStockRepository repoA, IStockRepository repoB, IComparer<Stock> comparer, char userInput)
 {
     _repoA = repoA;
     _repoB = repoB;
     _comparer = comparer;
     _userInput = userInput;
 }
开发者ID:atifMalik,项目名称:SolidPrinciplesDemo,代码行数:7,代码来源:StockMessageFactory.cs


示例10: SetOp

		private SetOp() { } // disable construction

		/// <summary>
		/// Computes union of two sorted sequences.
		/// </summary>
		/// <remarks>
		/// <para>Both set1 and set2 must be sorted in ascending order with respect to comparer.</para>
		/// <para>Union contains elements present in one or both ranges.</para>
		/// <para>Result is written to the output iterator one member at a time</para>
		/// 
		/// <para>Union differs from <see cref="Merge">Merge</see> for multisets.</para>
		/// 
		/// <para>If k equal elements are present in set1 and m elements equal to those k
		/// are present in set2,then k elements from set1 are included in the output, 
		/// followed by max(m-k, 0) elements from set2. The total of max(k,m) are
		/// added to the output. If you'd like to have m+k elements, use Merge function.
		/// </para>
		/// <para>Complexity: linear on combined number of items in both sequences</para>
		/// </remarks>
		/// <example>
		/// <para>set1 = { "a", "test", "Test", "z" }</para>
		/// <para>set2 = { "b", "tEst", "teSt", "TEST", "Z" }</para>
		/// <para>comparer is a case-insensitive comparer</para>
		/// <para>The following elements will be added to output:
		/// {"a", "b", "test", "Test", "TEST", "z" }</para>
		/// </example>
		public static void Union(IEnumerable set1, IEnumerable set2, IComparer comparer, IOutputIterator output) {
			IEnumerator enum1 = set1.GetEnumerator();
			IEnumerator enum2 = set2.GetEnumerator();

			bool have1 = enum1.MoveNext();
			bool have2 = enum2.MoveNext();

			while (have1 && have2) {
				int compare = comparer.Compare(enum1.Current, enum2.Current);

				if (compare < 0) {
					output.Add(enum1.Current);
					have1 = enum1.MoveNext();
				} else if (compare > 0) {
					output.Add(enum2.Current);
					have2 = enum2.MoveNext();
				} else {
					output.Add(enum1.Current);
					have1 = enum1.MoveNext();
					have2 = enum2.MoveNext();
				}
			}

			while (have1) {
				output.Add(enum1.Current);
				have1 = enum1.MoveNext();
			}

			while (have2) {
				output.Add(enum2.Current);
				have2 = enum2.MoveNext();
			}
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:59,代码来源:SetOp.cs


示例11: SorterBase

		/// <summary>
		/// Initializes a new instance of the SorterBase class with the specified 
		/// TableModel, Column index, IComparer and SortOrder
		/// </summary>
		/// <param name="tableModel">The TableModel that contains the data to be sorted</param>
		/// <param name="column">The index of the Column to be sorted</param>
		/// <param name="comparer">The IComparer used to sort the Column's Cells</param>
		/// <param name="sortOrder">Specifies how the Column is to be sorted</param>
		public SorterBase(TableModel tableModel, int column, IComparer comparer, SortOrder sortOrder)
		{
			this.tableModel = tableModel;
			this.column = column;
			this.comparer = comparer;
			this.sortOrder = sortOrder;
		}
开发者ID:marinehero,项目名称:ThinkAway.net,代码行数:15,代码来源:SorterBase.cs


示例12: GEPEnvironment

 /// <summary>
 /// 
 /// </summary>
 /// <param name="identifier"></param>
 /// <param name="state"></param>
 /// <param name="metricsEvaluator"></param>
 /// <param name="endCriteriaEvaluator"></param>
 /// <param name="getCallableGenes">Gets the IGEPGenes that can be called by the given IGEPGene.</param>
 public GEPEnvironment(IEnvironmentIdentifier identifier, IEnvironmentState state, 
     IMetricsEvaluator metricsEvaluator, IEndCriteriaEvaluator endCriteriaEvaluator,
     IComparer<IOrganism> organismValueComparer,
     ICallableGenesProvider callableGenesProvider)
     : base(identifier, state, metricsEvaluator, endCriteriaEvaluator, callableGenesProvider: callableGenesProvider, organismValueComparer: organismValueComparer)
 {
 }
开发者ID:RossHartmann,项目名称:Biological-AI,代码行数:15,代码来源:GEPEnvironment.cs


示例13: SortHelper

        // Helper method for sorting an ArrayList.  If the comparer is a SortFieldComparer,
        // use the cached-value approach to avoid excessive reflection.  For other 
        // comparers, sort the usual way
        internal static void SortHelper(ArrayList al, IComparer comparer)
        {
            SortFieldComparer sfc = comparer as SortFieldComparer; 
            if (sfc == null)
            { 
                // sort the usual way 
                al.Sort(comparer);
            } 
            else
            {
                // Sort with cached values.
                // Step 1.  Copy the items into a list augmented with slots for 
                // the cached values.
                int n = al.Count; 
                int nFields = sfc._fields.Length; 
                CachedValueItem[] list = new CachedValueItem[n];
                for (int i=0; i<n; ++i) 
                {
                    list[i].Initialize(al[i], nFields);
                }
 
                // Step 2. Sort the augmented list.  The SortFieldComparer will
                // fill in the slots as necessary to perform its comparisons. 
                Array.Sort(list, sfc); 

                // Step 3. Copy the items back into the original list, now in 
                // sorted order
                for (int i=0; i<n; ++i)
                {
                    al[i] = list[i].OriginalItem; 
                }
            } 
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:36,代码来源:SortFieldComparer.cs


示例14: AreCollectionsEqual

        private static bool AreCollectionsEqual(ICollection expected, ICollection actual, IComparer comparer, ref string reason)
        {
            Assert.CheckParameterNotNull(comparer, "Assert.AreCollectionsEqual", "comparer", string.Empty, new object[0]);

            if (!object.ReferenceEquals(expected, actual))
            {
                if ((expected == null) || (actual == null))
                {
                    return false;
                }
                if (expected.Count != actual.Count)
                {
                    reason = (string)TestingResources.NumberOfElementsDiff;
                    return false;
                }
                IEnumerator enumerator = expected.GetEnumerator();
                IEnumerator enumerator2 = actual.GetEnumerator();
                for (int i = 0; enumerator.MoveNext() && enumerator2.MoveNext(); i++)
                {
                    if (0 != comparer.Compare(enumerator.Current, enumerator2.Current))
                    {
                        reason = (string)TestingResources.ElementsAtIndexDontMatch(i);
                        return false;
                    }
                }
                reason = (string)TestingResources.BothCollectionsSameElements;
                return true;
            }
            reason = (string)TestingResources.BothCollectionsSameReference(string.Empty);
            return true;
        }
开发者ID:jlyonsmith,项目名称:Toaster,代码行数:31,代码来源:CollectionAssert.cs


示例15: ServiceContainer

 /// <summary>
 /// 初始化服务容器
 /// </summary>
 /// <param name="serviceName"> 服务约定名称 </param>
 /// <param name="serviceType"> 服务约定基类或接口类型 </param>
 /// <param name="typeComparer"> 比较2个类型服务的优先级 </param>
 /// <param name="logger"> 日志记录器 </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="serviceName" /> and <paramref name="serviceType" /> is all
 /// <see langword="null" />.
 /// </exception>
 /// <exception cref="OverflowException"> 匹配插件数量超过字典的最大容量 (<see cref="F:System.Int32.MaxValue" />)。 </exception>
 protected ServiceContainer(string serviceName, Type serviceType, IComparer<Type> typeComparer, TraceSource logger = null)
 {
     TypeComparer = typeComparer;
     _logger = logger ?? LogServices.Logger;
     _items = new ConcurrentDictionary<Type, ServiceItem>();
     _logger?.Write(TraceEventType.Start, $"开始扫描服务插件 serviceName={serviceName},serviceType={serviceType}");
     foreach (var p in MEF.PlugIns.GetPlugIns(serviceName, serviceType).OrderByDescending(p => p.Priority))
     {
         var value = p.GetValue(serviceType);
         if (value == null)
         {
             continue;
         }
         var type = GetServiceType(p, value);
         if (type == null)
         {
             continue;
         }
         var item = new ServiceItem(this, type, value, p);
         item.MakeSystem(); //默认为系统插件
         if (_items.TryAdd(type, item) == false)
         {
             _logger?.Write(TraceEventType.Verbose, $"服务插件({value.GetType().FullName})因优先级({p.Priority})过低被抛弃");
         }
         else
         {
             _logger?.Write(TraceEventType.Verbose, $"服务插件({value.GetType().FullName}),优先级({p.Priority})装载完成");
         }
     }
     _logger?.Write(TraceEventType.Stop, $"服务插件装载完成,有效服务 {Count} 个");
 }
开发者ID:blqw,项目名称:blqw.IOC,代码行数:43,代码来源:ServiceContainer.cs


示例16: SurvivedTextTreeCreator

        public SurvivedTextTreeCreator(IComparer<string> comparer)
        {
            if (comparer == null)
                throw new ArgumentNullException();

            Comparer = comparer;
        }
开发者ID:a-doom,项目名称:MergeText,代码行数:7,代码来源:SurvivedTextTreeCreator.cs


示例17: ListViewTextColumnComparer

 /// <summary>
 /// Creates a new instance of the <see cref="ListViewTextColumnComparer"/> class
 /// with the specified string comparer.
 /// </summary>
 /// <param name="stringComparer">The string comparer used to compare the item texts.</param>
 public ListViewTextColumnComparer(IComparer<string> stringComparer)
 {
     if (stringComparer == null) {
         throw new ArgumentNullException("stringComparer");
     }
     this.stringComparer = stringComparer;
 }
开发者ID:Erguotou,项目名称:SharpDevelop,代码行数:12,代码来源:ListViewTextColumnComparer.cs


示例18: SimpleSort

    /// <summary>
    /// A simple bubble sort for two arrays, limited to some region of the arrays.
    /// This is a regular bubble sort, nothing fancy.
    /// </summary>
    public static void SimpleSort(Array array, Array items, int startingIndex, int length, IComparer comparer)
    {
        bool finished = false;
        while (!finished)
        {
            bool swapped = false;
            for (int g = startingIndex; g < startingIndex + length - 1; g++)
            {
                Object first = array.GetValue(g);
                Object second = array.GetValue(g + 1);
                int comparison = comparer.Compare(first, second);
                if (comparison == 1)
                {
                    Swap(g, g + 1, array, items);
                    swapped = true;

                    first = array.GetValue(g);
                    second = array.GetValue(g + 1);
                }
            }
            if (!swapped)
            {
                finished = true;
            }
        }
    }
开发者ID:nnyamhon,项目名称:corefx,代码行数:30,代码来源:Array.Util.cs


示例19: Sort

 public void Sort(int[][] array, IComparer comparer)
 {
     if (comparer == null || array == null)
         throw new ArgumentNullException("Arguments can't be null.");
     
     QuickSort(array, 0, array.GetLength(0) - 1, comparer.Compare);
 }
开发者ID:Dmitry-Karnitsky,项目名称:Epam_ASP.NET_Courses,代码行数:7,代码来源:CustomSorters.cs


示例20: SortedList

 public SortedList()
 {
     this.keys = emptyArray;
     this.values = emptyArray;
     this._size = 0;
     this.comparer = new Comparer(CultureInfo.CurrentCulture);
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:7,代码来源:SortedList.cs



注:本文中的IComparer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ICompilation类代码示例发布时间:2022-05-24
下一篇:
C# IComparable类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap