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


C# HashSet.Clear方法代码示例

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


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

示例1: FilterEntities

    // filter out by if targets are within range
    public void FilterEntities(BattleEntity sourceEntity, HashSet<BattleEntity> entities)
    {
        // first row filter
        PCCharacter.RowPosition rowPosition = PCCharacter.RowPosition.FRONT;
        switch(mRowCondition) {
        case AISkillRule.RowCondition.BACK_COUNT_GT:
        case AISkillRule.RowCondition.BACK_COUNT_LT:
            rowPosition = PCCharacter.RowPosition.BACK;
            break;
        case AISkillRule.RowCondition.FRONT_COUNT_GT:
        case AISkillRule.RowCondition.FRONT_COUNT_LT:
            rowPosition = PCCharacter.RowPosition.FRONT;
            break;
        case AISkillRule.RowCondition.MIDDLE_COUNT_GT:
        case AISkillRule.RowCondition.MIDDLE_COUNT_LT:
            rowPosition = PCCharacter.RowPosition.MIDDLE;
            break;
        }

        // then remove all entries are not that row
        entities.RemoveWhere(delegate(BattleEntity obj) {
            if(obj is PCBattleEntity && ((PCBattleEntity)obj).pcCharacter.rowPosition == rowPosition) {
                return false;
            }
            return true;
        });

        // finally see if it meets the condition, if it does, leave them, if it doesnt, remove all
        switch(mRowCondition) {
        case AISkillRule.RowCondition.BACK_COUNT_GT:
        case AISkillRule.RowCondition.FRONT_COUNT_GT:
        case AISkillRule.RowCondition.MIDDLE_COUNT_GT:
            if(entities.Count > mFilterCount) {
                // ok
            }
            else {
                entities.Clear();
            }
            break;
        case AISkillRule.RowCondition.BACK_COUNT_LT:
        case AISkillRule.RowCondition.FRONT_COUNT_LT:
        case AISkillRule.RowCondition.MIDDLE_COUNT_LT:
            if(entities.Count < mFilterCount) {
                // ok
            }
            else {
                entities.Clear();
            }
            break;
        }
    }
开发者ID:riftgarret,项目名称:alphac,代码行数:52,代码来源:AIRowConditionFilter.cs

示例2: IsValidSudoku

 public bool IsValidSudoku(int[,] board)
 {
     HashSet<int> hset = new HashSet<int>();
     // row validation
     for (int r = 0; r < 9; r++)
     {
         hset.Clear();
         for (int c = 0; c < 9; c++)
         {
             int cell = board[c, r];
             if (cell != 0 && !hset.Add(cell))
             {
                 return false;
             }
         }
     }
     // column validation
     for (int c = 0; c < 9; c++)
     {
         hset.Clear();
         for (int r = 0; r < 9; r++)
         {
             int cell = board[c, r];
             if (cell != 0 && !hset.Add(cell))
             {
                 return false;
             }
         }
     }
     // 9 blocks validation
     for (int b = 0; b < 9; b++)
     {
         int cStart = (b % 3) * 3;
         int rStart = (b / 3) * 3;
         hset.Clear();
         for (int c = cStart; c < cStart + 3; c++)
         {
             for (int r = rStart; r < rStart + 3; r++)
             {
                 int cell = board[c, r];
                 if (cell != 0 && !hset.Add(cell))
                 {
                     return false;
                 }
             }
         }
     }
     return true;
 }
开发者ID:dullcat,项目名称:leetcode_csharp,代码行数:49,代码来源:Q036_ValidSudoku.cs

示例3: UnRepeat

        public static void UnRepeat(string file)
        {
            var fi = new FileInfo(file);
            if (fi.Exists == false) return;
            HashSet<int> hs = new HashSet<int>();
            int repeat = 0;
            using (StreamWriter sw = new StreamWriter(fi.FullName + "U.txt"))
            {
                using (var sr = new StreamReader(file))
                {
                    string line = sr.ReadLine();
                    while (line != null)
                    {
                        int hash = line.GetHashCode();
                        if (!hs.Contains(hash))
                        {
                            hs.Add(hash);
                            sw.WriteLine(line);
                        }

                        line = sr.ReadLine();
                    }
                }
            }
            hs.Clear();
        }
开发者ID:howbigbobo,项目名称:DailyCode,代码行数:26,代码来源:FileCounter.cs

示例4: FilterEntities

 public void FilterEntities(BattleEntity sourceEntity, HashSet<BattleEntity> entities)
 {
     // leftover targets should already be in the party, we should just count and filter out the rest if its needed
     switch(mPartyCondition) {
     case AISkillRule.PartyCondition.PARTY_COUNT_GT:
         if(entities.Count <= mPartyCount) {
             entities.Clear();
         }
         break;
     case AISkillRule.PartyCondition.PARTY_COUNT_LT:
         if(entities.Count >= mPartyCount) {
             entities.Clear();
         }
         break;
     }
 }
开发者ID:riftgarret,项目名称:alphac,代码行数:16,代码来源:AIPartyConditionFilter.cs

示例5: GetPrefixSuffixSetCount

        public int GetPrefixSuffixSetCount(int[] set)
        {
            int output = 0;

            var prefixesNumbersUsed = new HashSet<int>();
            var suffixNumbersUsed = new HashSet<int>();

            foreach (var rangePair in GetPrefixSuffixIndexRanges(set))
            {
                var prefixRange = rangePair.Prefix;
                var suffixRange = rangePair.Suffix;

                prefixesNumbersUsed.Add(prefixRange.Number);
                suffixNumbersUsed.Add(suffixRange.Number);

                if (prefixesNumbersUsed.SetEquals(suffixNumbersUsed))
                {
                    //No need to keep comparing values that worked already
                    prefixesNumbersUsed.Clear();
                    suffixNumbersUsed.Clear();
                    output += (prefixRange.Range * suffixRange.Range);
                }

                if (output > TOO_LARGE)
                    return TOO_LARGE;
            }

            return output;
        }
开发者ID:reifnir,项目名称:CodingProblems,代码行数:29,代码来源:PrefixSuffixSets.cs

示例6: Closure

        public static ParseState Closure(this IEnumerable<Item> items, Grammar grammar)
        {
            HashSet<Item> closure = new HashSet<Item>(items);
            HashSet<Item> toAdd = new HashSet<Item>();

            do
            {
                toAdd.Clear();
                foreach (var item in closure)
                {
                    if (item.Position == item.Production.Body.Length)
                        continue;

                    BnfTerm term = item.Production.Body[item.Position];

                    if (term is NonTerminal)
                    {
                        NonTerminal nonTerm = term as NonTerminal;
                        foreach (var production in grammar.Productions.Where(a => a.Head.Equals(nonTerm)))
                            toAdd.Add(new Item(production, 0));
                    }
                }
            }
            while (closure.UnionWithAddedCount(toAdd) > 0);

            return new ParseState(closure, IsAcceptingState(closure, grammar));
        }
开发者ID:martindevans,项目名称:Hermes,代码行数:27,代码来源:IEnumerableExtension.cs

示例7: brute_force_test_each_number_for_match

        /// <summary>
        /// first construct a prime list up to 1k(using seive)
        /// and check each number after 647 to see if it matches with criteria given by the question
        /// 1. for each number, first find out all the prime factors, and add them to a hashset
        /// 2. if prime factors added are not exactly 4, reset the hashset
        /// 3  (start variable is used to make sure the numbers are continuous, if there is a gap between numbers, reset the hashset)
        /// 4. if prime factors added are exactly 4, check the hashset count, if it is 16 return the answer
        /// 5. if it is not 16, continues to next number
        /// </summary>
        /// <returns></returns>
        static int brute_force_test_each_number_for_match()
        {
            var max = 1000; //randomly chose, it works :P
            var bound = (int)Math.Sqrt(max);
            bool[] primes = new bool[max];
            primes[0] = true;
            primes[1] = true;
            int s, m;
            for (s = 2; s <= bound; s++)
            {
                if (primes[s] == false)
                {
                    for (m = s * s; m < max; m += s)
                    {
                        primes[m] = true;
                    }
                }
            }
            var factor = 4;
            var start = 0;
            var num = 0;
            var pwr = 1;
            var set = new HashSet<int>();
            var count = 1;
            for (s = 647; s < 200000; s++)
            {
                num = s;
                for (m = 2; m < max; m++)
                {
                    if (primes[m] == false)
                    {
                        pwr = 1;
                        while (num % m == 0)
                        {
                            pwr *= m;
                            num /= m;
                        }
                        if (pwr != 1)
                            set.Add(pwr);
                        if (num <= 1)
                            break;
                    }
                }
                if (set.Count == factor * count && (s == start + 1 || start == 0))
                {
                    if (count == factor)
                        return s - 3;

                    start = s;
                    count++;
                }
                else
                {
                    set.Clear();
                    count = 1;
                    start = 0;
                }
            }
            return 0;
        }
开发者ID:jtg2078,项目名称:ProjectEuler,代码行数:70,代码来源:Program.cs

示例8: Execute

        public int Execute()
        {
            var result = 0;
            _options.Reports.Information.WriteLine("List dependencies for {0} ({1})", _options.Project.Name, _options.Project.ProjectFilePath);

            var frameworks = new HashSet<FrameworkName>(_options.Project.GetTargetFrameworks().Select(f => f.FrameworkName));
            if (_options.Framework != null)
            {
                if (frameworks.Contains(_options.Framework))
                {
                    frameworks.Clear();
                    frameworks.Add(_options.Framework);
                }
                else
                {
                    _options.Reports.Error.WriteLine("Project doesn't support framework: {0}", _options.Framework.FullName);
                    return 0;
                }
            }

            foreach (var framework in frameworks)
            {
                _options.Reports.Information.WriteLine("[Target framework {0}]", framework.Identifier.ToString());

                var operation = new DependencyListOperation(_options, framework);

                if (!operation.Execute())
                {
                    _options.Reports.Error.WriteLine("There was an error listing the dependencies");
                    return 3;
                }
            }

            return result;
        }
开发者ID:nagyistoce,项目名称:dnx,代码行数:35,代码来源:DependencyListCommand.cs

示例9: Constructor_shall_not_call_within_short_timeframe_to_generate_unique_information

        public void Constructor_shall_not_call_within_short_timeframe_to_generate_unique_information()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var seeds = new HashSet<int>();
                PRandom.ConstructorInt32().Body = (@this, seed) =>
                {
                    IndirectionsContext.ExecuteOriginal(() =>
                    {
                        var ctor = typeof(Random).GetConstructor(new[] { typeof(int) });
                        ctor.Invoke(@this, new object[] { seed });
                    });
                    seeds.Add(seed);
                };
                new Random();  // preparing JIT
                seeds.Clear();


                // Act
                var vil1 = new Village();
                Thread.Sleep(TimeSpan.FromSeconds(1));
                var vil2 = new Village();


                // Assert
                Assert.AreEqual(2, seeds.Count);
            }
        }
开发者ID:urasandesu,项目名称:Prig.Samples,代码行数:29,代码来源:VillageTest.cs

示例10: CustomizeCodeDom

        public void CustomizeCodeDom(CodeCompileUnit codeUnit, IServiceProvider services)
        {
            var types = codeUnit.Namespaces[0].Types;
            var attributes = new HashSet<string>();
            foreach (var type in types.Cast<CodeTypeDeclaration>().
                                 Where(type => type.IsClass && !type.IsContextType()))
            {
                attributes.Clear();
                var @struct = new CodeTypeDeclaration {
                    Name = AttributeConstsStructName, 
                    IsStruct = true, 
                    TypeAttributes = TypeAttributes.Public
                };

                foreach (var member in from CodeTypeMember member in type.Members 
                                       let prop = member as CodeMemberProperty 
                                       where prop != null 
                                       select prop)
                {
                    CreateAttributeConstForProperty(@struct, member, attributes);
                }

                if (attributes.Any())
                {
                    type.Members.Insert(0, GenerateTypeWithoutEmptyLines(@struct));
                }
            }
        }
开发者ID:gitter-badger,项目名称:DLaB.Xrm.XrmToolBoxTools,代码行数:28,代码来源:AttributeConstGenerator.cs

示例11: Ensure_To_Not_Generate_Identical_Keys

        [Test] // See Bug #135
        public void Ensure_To_Not_Generate_Identical_Keys()
        {
            var passPhrase = "test";
            var privKeySet = new HashSet<string>();
            var pubKeySet = new HashSet<string>();

            // add well known key
            privKeySet.Add(
                "MIICITAjBgoqhkiG9w0BDAEDMBUEEF5Fx1gxrWd+0G10a7+UbxQCAQoEggH4SUUim2C3kcHApCKVgIeXpKlZQHcaRgfWt0rVEWr8zRnzO9xT5itU2Sw7j0N3oh6cPer/QGNCmAgnRyiDatruJznDPOmMzK5Yskj6mlCaY6JEjcol+E4SBZJDgvIejy8HVCy+DOIR42JXs9oxgeq8eqB+0RZwvDMBG2hrUjnZ4/hPKRPJY134cqTH68jLv6SXglIPcrL9OxOwdzJBaq0ngSBfqhBWbLRIy/Th2btl9Q/0b+sZxG6r2b80wOxIewlr6EUqXtMaA8Bo5dgVZt1itWYafIAbLWzjZavwdO+EkUMCjZhsfvbXSCmcLRmitdJ6beG7jg7R6m6Q92DpU3qZhEio9akX3MQmOTO63Er4T2t6HHYnTzPaZPjdn8D+8lcTUntp/0vD8SvC3+Cb7tZOHSVGMUDdj7WIW+Bl/5bhdmnChE83HSxR4OsBjLATuZOpYtOefWbXyT8qsUn1IouaCjH+BYejBIPrmFVVl0WZADtbyE0LAOyHCD2quAjCpIwXXONG/gXm+XVGst5clbcuxaG4TxKWA8ifIXaio3aJgLfI+D0Izt2GscKRg6oGTlbC3YFIJg+PAH3A4qufoRSPmtREz0oR1X1ZsS6m/IKezf8vl3S+fSpmR/mUuc6uBx9qI9yJIEW/In90r5vO9fKGusEElP6svlub");
            pubKeySet.Add(
                "MIIBKjCB4wYHKoZIzj0CATCB1wIBATAsBgcqhkjOPQEBAiEA/////wAAAAEAAAAAAAAAAAAAAAD///////////////8wWwQg/////wAAAAEAAAAAAAAAAAAAAAD///////////////wEIFrGNdiqOpPns+u9VXaYhrxlHQawzFOw9jvOPD4n0mBLAxUAxJ02CIbnBJNqZnjhE50mt4GffpAEIQNrF9Hy4SxCR/i85uVjpEDydwN9gS3rM6D0oTlF2JjClgIhAP////8AAAAA//////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABNVLQ1xKY80BFMgGXec++Vw7n8vvNrq32PaHuBiYMm0PEj2JoB7qSSWhfgcjxNVJsxqJ6gDQVWgl0r7LH4dr0KU=");

            for (int i = 0; i < 100; i++)
            {
                var keyGenerator = new KeyGenerator(256); //default key size
                var pair = keyGenerator.GenerateKeyPair();
                var privateKey = pair.ToEncryptedPrivateKeyString(passPhrase);
                var publicKey = pair.ToPublicKeyString();

                Assert.That(privKeySet.Add(privateKey), Is.True);
                Assert.That(pubKeySet.Add(publicKey), Is.True);
            }

            privKeySet.Clear();
            pubKeySet.Clear();
        }
开发者ID:ReyAleman,项目名称:Portable.Licensing,代码行数:27,代码来源:KeyGeneratorTests.cs

示例12: SolveProblem

        public static int SolveProblem()
        {
            HashSet<int> multiples = new HashSet<int>();
            //Find multples of 3 below 10
            foreach (int i in FindMultiplesBelow(3, 10))
            {
                multiples.Add(i);
            }

            foreach (int i in FindMultiplesBelow(5, 10))
            {
                multiples.Add(i);
            }

            if (multiples.Aggregate((total, i) => total + i) != 23)
            {
                Console.WriteLine("WOOPS -- " + string.Join(", ", multiples));
            }

            multiples.Clear();
            //Find multples of 3 below 10
            foreach (int i in FindMultiplesBelow(3, 1000))
            {
                multiples.Add(i);
            }

            foreach (int i in FindMultiplesBelow(5, 1000))
            {
                multiples.Add(i);
            }
            return multiples.Aggregate((total, i) => total + i);
        }
开发者ID:Baifamonv,项目名称:ProjectEuler,代码行数:32,代码来源:Problem1.cs

示例13: Scan

        public void Scan()
        {
            if (_db == null || FindByUserDatabase.DatabaseUnavailable)
                return;

            var sessionId = _session.Id;
            var currentDate = new DateTime(2000, 1, 1);
            var users = new HashSet<string>();

            // Iterate across all messages in this session fragment
            foreach (var message in _session.GetMessages())
            {
                // Handle the case of sessions that span multiple days
                var timestamp = message.Timestamp.ToLocalTime();
                if (timestamp.Date != currentDate)
                {
                    // Update the database with the users associated with this session on this date
                    if (users.Count > 0)
                    {
                        _db.AddUsers(sessionId, currentDate, users);
                        users.Clear();
                    }
                    currentDate = timestamp.Date;
                }
                users.Add(message.UserName);
            }

            // Update the database with the users associated with the last day of this session fragment
            if (users.Count > 0)
            {
                _db.AddUsers(sessionId, currentDate, users);
            }
        }
开发者ID:jwight1976,项目名称:Loupe.Samples,代码行数:33,代码来源:SessionScanner.cs

示例14: GetBetweenCount

 private ulong GetBetweenCount(int max)
 {
     ulong count = 0;
     HashSet<int> seived = new HashSet<int>();
     for (int denominator = 2; denominator <= max; denominator++) {
         seived.Clear();
         for (int numerator = 1; numerator < denominator; numerator++) {
             if (!seived.Contains(numerator)) {
                 if ((denominator % numerator != 0 || numerator == 1)
                     && IsFirstHigher(numerator, denominator, _numeratorBegin, _denominatorBegin)
                     && IsFirstHigher(_numeratorEnd, _denominatorEnd, numerator, denominator)) {
                     count++;
                 }
                 if (denominator % numerator == 0 && numerator != 1) {
                     int composite = numerator;
                     do {
                         seived.Add(composite);
                         composite += numerator;
                     } while (composite < denominator);
                 }
             }
         }
     }
     return count;
 }
开发者ID:enigmaticcam,项目名称:ProjectEuler,代码行数:25,代码来源:Problem73.cs

示例15: CreateAutomaton

        public static Automaton CreateAutomaton(Grammar g)
        {
            //initialise to closure of start item
            HashSet<ParseState> states = new HashSet<ParseState>();
            states.Add(g.Productions.Where(a => a.Head.Equals(g.Root)).Select(a => new Item(a, 0)).Closure(g));

            HashSet<ParseStateTransition> transitions = new HashSet<ParseStateTransition>();

            HashSet<ParseState> sToAdd = new HashSet<ParseState>();
            HashSet<ParseStateTransition> tToAdd = new HashSet<ParseStateTransition>();

            do
            {
                sToAdd.Clear();
                tToAdd.Clear();

                foreach (var state in states)
                {
                    foreach (var item in state)
                    {
                        if (item.Production.Body.Length == item.Position)
                            continue;

                        BnfTerm term = item.Production.Body[item.Position];
                        ParseState j = state.Goto(term, g);

                        sToAdd.Add(j);
                        tToAdd.Add(new ParseStateTransition(state, term, j));
                    }
                }
            }
            while (states.UnionWithAddedCount(sToAdd) != 0 | transitions.UnionWithAddedCount(tToAdd) != 0);

            return new Automaton(transitions, g);
        }
开发者ID:martindevans,项目名称:Hermes,代码行数:35,代码来源:LR0.cs


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