当前位置: 首页>>代码示例>>C#>>正文


C# HashSet.TrimExcess方法代码示例

本文整理汇总了C#中HashSet.TrimExcess方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.TrimExcess方法的具体用法?C# HashSet.TrimExcess怎么用?C# HashSet.TrimExcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HashSet的用法示例。


在下文中一共展示了HashSet.TrimExcess方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TrimExcess_Test3

        public static void TrimExcess_Test3()
        {
            HashSet<int> hashSet;
            int[] values;

            hashSet = new HashSet<int>();
            AddItemsInt(hashSet, 197, out values);
            hashSet.Clear();
            hashSet.TrimExcess();
            hashSet.TrimExcess();

            HashSetTestSupport<int>.VerifyHashSet(hashSet, new int[0], EqualityComparer<int>.Default);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:13,代码来源:HashSet_TrimExcessTests.cs

示例2: TrimExcess_Test1

        public static void TrimExcess_Test1()
        {
            HashSet<int> hashSet;

            hashSet = new HashSet<int>();
            hashSet.TrimExcess();

            HashSetTestSupport<int>.VerifyHashSet(hashSet, new int[0], EqualityComparer<int>.Default);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:9,代码来源:HashSet_TrimExcessTests.cs

示例3: TrimExcess_Test4

        public static void TrimExcess_Test4()
        {
            HashSet<int> hashSet;
            HashSet<int> hashSet2;
            int[] values;
            List<int> remainingValues;

            hashSet = new HashSet<int>();
            AddItemsInt(hashSet, 198, out values);
            remainingValues = new List<int>(values);
            hashSet.Remove(0);
            remainingValues.Remove(0);
            hashSet.TrimExcess();

            hashSet2 = new HashSet<int>();
            AddItemsInt(hashSet2, 197);

            HashSetTestSupport<int>.VerifyHashSet(hashSet, remainingValues, EqualityComparer<int>.Default);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:19,代码来源:HashSet_TrimExcessTests.cs

示例4: RemoveInterjections

        public string RemoveInterjections(string text)
        {
            if (_interjectionList == null)
            {
                var interjectionList = new HashSet<string>();
                foreach (var s in Configuration.Settings.Tools.Interjections.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (s.Length > 0)
                    {
                        interjectionList.Add(s);
                        var upper = s.ToUpper();
                        interjectionList.Add(upper);
                        var lower = s.ToLower();
                        interjectionList.Add(lower);
                        interjectionList.Add(lower.CapitalizeFirstLetter());
                    }
                }
                _interjectionList = new List<string>(interjectionList);
                interjectionList.Clear();
                interjectionList.TrimExcess();
                _interjectionList.Sort(CompareLength);
            }

            string oldText = text;
            bool doRepeat = true;
            while (doRepeat)
            {
                doRepeat = false;
                foreach (string s in _interjectionList)
                {
                    if (text.Contains(s))
                    {
                        var regex = new Regex("\\b" + Regex.Escape(s) + "\\b");
                        var match = regex.Match(text);
                        if (match.Success)
                        {
                            int index = match.Index;
                            string temp = text.Remove(index, s.Length);
                            while (index == 0 && temp.StartsWith("... ", StringComparison.Ordinal))
                            {
                                temp = temp.Remove(3, 1);
                            }
                            while (index == 3 && temp.StartsWith("<i>... ", StringComparison.Ordinal))
                            {
                                temp = temp.Remove(6, 1);
                            }
                            while (index > 2 && (" \r\n".Contains(text.Substring(index - 1, 1))) && temp.Substring(index).StartsWith("... ", StringComparison.Ordinal))
                            {
                                temp = temp.Remove(index + 3, 1);
                            }

                            if (temp.Remove(0, index) == " —" && temp.EndsWith("—  —", StringComparison.Ordinal))
                            {
                                temp = temp.Remove(temp.Length - 3);
                                if (temp.EndsWith(Environment.NewLine + "—", StringComparison.Ordinal))
                                    temp = temp.Remove(temp.Length - 1).TrimEnd();
                            }
                            else if (temp.Remove(0, index) == " —" && temp.EndsWith("-  —", StringComparison.Ordinal))
                            {
                                temp = temp.Remove(temp.Length - 3);
                                if (temp.EndsWith(Environment.NewLine + "-", StringComparison.Ordinal))
                                    temp = temp.Remove(temp.Length - 1).TrimEnd();
                            }
                            else if (index == 2 && temp.StartsWith("-  —", StringComparison.Ordinal))
                            {
                                temp = temp.Remove(2, 2);
                            }
                            else if (index == 2 && temp.StartsWith("- —", StringComparison.Ordinal))
                            {
                                temp = temp.Remove(2, 1);
                            }
                            else if (index == 0 && temp.StartsWith(" —", StringComparison.Ordinal))
                            {
                                temp = temp.Remove(0, 2);
                            }
                            else if (index == 0 && temp.StartsWith('—'))
                            {
                                temp = temp.Remove(0, 1);
                            }
                            else if (index > 3 && (temp.Substring(index - 2) == ".  —" || temp.Substring(index - 2) == "!  —" || temp.Substring(index - 2) == "?  —"))
                            {
                                temp = temp.Remove(index - 2, 1).Replace("  ", " ");
                            }
                            string pre = string.Empty;
                            if (index > 0)
                                doRepeat = true;

                            bool removeAfter = true;

                            if (index > s.Length)
                            {
                                if (temp.Length > index - s.Length + 3)
                                {
                                    int subIndex = index - s.Length + 1;
                                    string subTemp = temp.Substring(subIndex, 3);
                                    if (subTemp == ", !" || subTemp == ", ?" || subTemp == ", .")
                                    {
                                        temp = temp.Remove(subIndex, 2);
                                        removeAfter = false;
                                    }
//.........这里部分代码省略.........
开发者ID:LeonCheung,项目名称:subtitleedit,代码行数:101,代码来源:RemoveTextForHI.cs

示例5: TrimExcess_Test6

        public static void TrimExcess_Test6()
        {
            HashSet<int> hashSet;
            HashSet<int> hashSet2;
            int[] values;

            hashSet = new HashSet<int>();
            AddItemsInt(hashSet, 17519);
            hashSet.Clear();
            AddItemsInt(hashSet, 8419, out values);
            hashSet.TrimExcess();

            hashSet2 = new HashSet<int>();
            AddItemsInt(hashSet2, 8419);

            HashSetTestSupport<int>.VerifyHashSet(hashSet, values, EqualityComparer<int>.Default);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:17,代码来源:HashSet_TrimExcessTests.cs

示例6: EnumerableBreakAfterTrimExcess

 public void EnumerableBreakAfterTrimExcess()
 {
     var set = new HashSet<int>(Enumerable.Range(0, 10));
     foreach (var item in set)
     {
         set.TrimExcess();
     }
 }
开发者ID:Confirmit,项目名称:Students,代码行数:8,代码来源:HashSetUnitTest.cs

示例7: ImmutabilityAfterTrimExcessTest

 public void ImmutabilityAfterTrimExcessTest()
 {
     var set = new HashSet<int>(Enumerable.Range(0, 100));
     set.TrimExcess();
     Assert.AreEqual(set.Count, 100);
     for (int i = 0; i < 100; i++)
     {
         Assert.IsTrue(set.Contains(i));
     }
 }
开发者ID:Confirmit,项目名称:Students,代码行数:10,代码来源:HashSetUnitTest.cs

示例8: EmptySetTrimExcessTest

 public void EmptySetTrimExcessTest()
 {
     var set=new HashSet<int>();
     set.TrimExcess();
     Assert.AreEqual(set.Count, 0);
 }
开发者ID:Confirmit,项目名称:Students,代码行数:6,代码来源:HashSetUnitTest.cs

示例9: CollectionMetaToken

        static CollectionMetaToken()
        {
            var speciallySerializedTypes = new [] {
                typeof(List<>),
                typeof(ReadOnlyCollection<>),
                typeof(Dictionary<,>),
                typeof(HashSet<>),
                typeof(Queue<>),
                typeof(Stack<>),
                typeof(BlockingCollection<>),
                typeof(Hashtable)
            };
            SpeciallySerializedCollections = new HashSet<Type>(speciallySerializedTypes);
            SpeciallySerializedCollections.TrimExcess();

            SpeciallySerializedCollectionsAQNs = new HashSet<string>(speciallySerializedTypes.Select(x => x.AssemblyQualifiedName));
            SpeciallySerializedCollectionsAQNs.TrimExcess();
        }
开发者ID:StepWoodProductions,项目名称:Migrant,代码行数:18,代码来源:CollectionMetaToken.cs

示例10: ConstructFreeVariables

 protected static ICollection<Symbol> ConstructFreeVariables(SCode body, Symbol [] formals)
 {
     HashSet<Symbol> freeVariableSet = new HashSet<Symbol> ();
     body.CollectFreeVariables (freeVariableSet);
     foreach (Symbol formal in formals)
         freeVariableSet.Remove (formal);
     freeVariableSet.TrimExcess ();
     return freeVariableSet;
 }
开发者ID:NotJRM,项目名称:jrm-code-project,代码行数:9,代码来源:Lambda.cs

示例11: UpdateChildren

    private void UpdateChildren( DataGridContext dataGridContext, TableViewColumnVirtualizationManager columnVirtualizationManager, VirtualizingCellCollection parentRowCells )
    {
      //Prevent reentrance
      if( m_parentRowCells.AlreadyUpdating )
        return;

      m_parentRowCells.AlreadyUpdating = true;

      if( dataGridContext == null )
        throw new DataGridInternalException( "DataGridContext is null for FixedCellPanel" );

      if( columnVirtualizationManager == null )
        throw new DataGridInternalException( "ColumnVirtualizationManager is null for FixedCellPanel" );

      if( parentRowCells == null )
        return;

      this.ClearPermanentScrollingFieldNames();

      List<string> currentFieldsName = new List<string>();
      currentFieldsName.AddRange( columnVirtualizationManager.FixedFieldNames );
      currentFieldsName.AddRange( columnVirtualizationManager.ScrollingFieldNames );

      HashSet<Cell> unusedCells = new HashSet<Cell>( parentRowCells.BindedCells );

      //Idenfity the binded cells that aren't needed anymore.
      foreach( string fieldName in currentFieldsName )
      {
        ColumnBase column = dataGridContext.Columns[ fieldName ];
        Cell cell;

        if( parentRowCells.TryGetCell( column, out cell ) )
        {
          //Certain non recyclable cells like StatCells need their content binding to be updated when they become (or stay) in view.
          cell.AddContentBinding();
          unusedCells.Remove( cell );
        }
      }
      currentFieldsName.Clear();
      currentFieldsName.TrimExcess();

      //Release the unused binded cells now in order to minimize the number of cell's creation.
      foreach( Cell cell in unusedCells )
      {
        bool release = this.CanReleaseCell( cell );

        //We move the unused cell into the scrolling panel since there is more chance it will be reused there in the future.
        this.MoveCellToScrollingPanel( cell, release );

        if( release )
        {
          parentRowCells.Release( cell );
        }
        //Since the cell cannot be released, it will not be collapsed. We must keep the field name in order to let the scrolling sub-panel measure and arrange the cell out of view.
        else
        {
          //Certain non recyclable cells like StatCells needs their content binding to be removed when they become out of view.
          cell.RemoveContentBinding();
          this.AddPermanentScrollingFieldNames( cell.FieldName );
        }
      }
      unusedCells.Clear();
      unusedCells.TrimExcess();

      //Add the missing cells to the fixed region.
      foreach( string fieldName in columnVirtualizationManager.FixedFieldNames )
      {
        //The cell is created if it is missing.
        Cell cell = parentRowCells[ fieldName ];

        //Make sure the cell is in the appropriate panel.
        this.MoveCellToFixedPanel( cell );
      }

      //Add the missing cells to the scrolling region.
      foreach( string fieldName in columnVirtualizationManager.ScrollingFieldNames )
      {
        //The cell is created if it is missing.
        Cell cell = parentRowCells[ fieldName ];

        //Make sure the cell is in the appropriate panel.
        this.MoveCellToScrollingPanel( cell );
      }

      if( m_clearUnusedCellsDispatcherOperation == null )
      {
        m_clearUnusedCellsDispatcherOperation = this.Dispatcher.BeginInvoke( new Action( this.ClearUnusedCells ), DispatcherPriority.ApplicationIdle );
      }

      m_fixedPanel.InvalidateMeasure();
      m_scrollingCellsDecorator.InvalidateMeasure();
      m_scrollingPanel.InvalidateMeasure();

      m_parentRowCells.AlreadyUpdating = false;
    }
开发者ID:wangws556,项目名称:duoduo-chat,代码行数:95,代码来源:FixedCellPanel.cs

示例12: TrimExcess

        public void TrimExcess()
        {
            var set = new HashSet<int>();
              foreach (int item in Enumerable.Range(100, 1000))
            set.Add(item);

              Assert.AreEqual(1000, set.Count);

              set.TrimExcess();

              Assert.AreEqual(1000, set.Count);
              foreach (int item in Enumerable.Range(100, 1000))
            Assert.IsTrue(set.Contains(item));

              foreach (int item in Enumerable.Range(100, 1000).Where(i => i % 2 == 0))
            set.Remove(item);

              set.TrimExcess();
              Assert.AreEqual(500, set.Count);
              Assert.IsTrue(set.All(i => i % 2 == 1));
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:21,代码来源:HashSetTest.cs


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