Пример #1
0
        public void SymmetricExceptWith(IEnumerable <T> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            // if set is empty, then symmetric difference is other
            if (hashSet.Count == 0)
            {
                UnionWith(other);
                return;
            }

            // special case this; the symmetric difference of a set with itself is the empty set
            if (other == this)
            {
                Clear();
                return;
            }

            // Use the same comparer for fastest operations
            var temp = new SCG.HashSet <T>(other, hashSet.EqualityComparer);

            temp.ExceptWith(this);

            // We separate this into ExceptWith and UnionWith at extra cost to ensure we call TrimExcess()
            // between the two operations (if needed), which in turn ensures we maintain insertion order.
            // IMPORTANT: Don't call the operations on the hashSet private variable!.
            ExceptWith(other);
            UnionWith(temp);
        }
Пример #2
0
        public static void PopulateCollections25_25_50PctUnique(int maxN, out int[] uniqueArray, out int[] mixedArray,
                                                                SCG.HashSet <int> h, FastHashSet <int> f = null, C5.HashSet <int> c5 = null, SCG.SortedSet <int> sortedSet = null, SCG.List <int> lst = null)
        {
            uniqueArray = new int[maxN];
            mixedArray  = new int[maxN];

            Random rand = new Random(89);

            BenchUtil.PopulateIntArray(uniqueArray, rand, int.MinValue, int.MaxValue, 1.0); // a array should have 100% unique values

            int uniqueValuesCount = maxN / 2;                                               // this should produce a c array that has 50% unique values (the other 50% are duplicates), but all are actually in the uniqueArray, so 1, 1, 2, 2 would be an example of this

            if (uniqueValuesCount == 0)
            {
                uniqueValuesCount = 1;
            }
            BenchUtil.PopulateIntArrayFromUniqueArray(mixedArray, rand, uniqueArray, uniqueValuesCount);
            BenchUtil.PopulateIntArrayAtRandomIndices(mixedArray, rand, int.MinValue, int.MaxValue, maxN - uniqueValuesCount);

            if (h != null)
            {
                for (int i = 0; i < maxN; i++)
                {
                    h.Add(uniqueArray[i]);
                }
            }

            if (f != null)
            {
                for (int i = 0; i < maxN; i++)
                {
                    f.Add(uniqueArray[i]);
                }
            }

            if (c5 != null)
            {
                for (int i = 0; i < maxN; i++)
                {
                    c5.Add(uniqueArray[i]);
                }
            }

            if (sortedSet != null)
            {
                for (int i = 0; i < maxN; i++)
                {
                    sortedSet.Add(uniqueArray[i]);
                }
            }

            if (lst != null)
            {
                for (int i = 0; i < maxN; i++)
                {
                    lst.Add(uniqueArray[i]);
                }
                lst.Sort();
            }
        }
Пример #3
0
    public void OnStartButtonPressed()
    {
        SCG.HashSet <int> selectedSpecialistKeySet = new SCG.HashSet <int>();
        Array             slotList;
        int specialistColorIndex;
        int autoSelect;

        string[] skills = new string[] { "", "P", "L", "S" };

        globalData.Call(this.GetMethodClear());         // NOTE: This clears all entries inside GlobalData.
        PutGlobal("specialistAmountIndex", specialistAmountIndex);
        PutGlobal("firstToIndex", firstToIndex);
        PutGlobal("levelIndex", locationIndex);
        PutGlobal("roundTimeIndex", roundTimeIndex);
        PutGlobal("skillIndex", skillIndex);

        PutGlobal("sceneToLoad", GetLevelScenePath());
        PutGlobal("levelScenePathList", levelScenePathList);
        PutGlobal("firstTo", firstToIndex + 1);
        PutGlobal("levelIndex", locationIndex);
        PutGlobal("battleRound", 1);
        PutGlobal("specialistAmount", specialistAmountIndex + 2);
        PutGlobal("battleRoundTime", 180f + (roundTimeIndex * 60f));
        PutGlobal("battleStartingSkill", skills[skillIndex]);

        for (int i = 0; i < specialistControls.Length; i++)
        {
            specialistColorIndex = specialistColorIndexes[i];
            autoSelect           = 0;
            slotList             = new Array();
            slotList.Add("S");
            slotList.Add("S");

            while (selectedSpecialistKeySet.Contains(specialistColorIndex))
            {
                specialistColorIndex = autoSelect++;
            }

            selectedSpecialistKeySet.Add(specialistColorIndex);
            PutGlobal("winsSpecialistIndex" + i, 0);
            PutGlobal("livesSpecialistIndex" + i, 0);
            PutGlobal("healthSpecialistIndex" + i, 100);
            PutGlobal("speedLevelSpecialistIndex" + i, 1);
            PutGlobal("laserRayLevelSpecialistIndex" + i, 2);
            PutGlobal("laserDeviceAmountSpecialistIndex" + i, 1);
            PutGlobal("detonateTimeLevelSpecialistIndex" + i, 1);
            PutGlobal("slotListSpecialistIndex" + i, slotList);
            PutGlobal("selectedSlotSpecialistIndex" + i, 0);
            PutGlobal("skillSpecialistIndex" + i, skills[skillIndex]);
            PutGlobal("colorSpecialistIndex" + i, specialistColorIndex);
        }

        GetTree().ChangeScene(this.GetScenePath(loadScreenScenePath));
    }
Пример #4
0
        public void SetComparer_SetEqualsTests()
        {
            SCG.List <T> objects = new SCG.List <T>()
            {
                CreateT(1), CreateT(2), CreateT(3), CreateT(4), CreateT(5), CreateT(6)
            };

            var set = new SCG.HashSet <SortedSet <T> >()
            {
                new SortedSet <T> {
                    objects[0], objects[1], objects[2]
                },
                new SortedSet <T> {
                    objects[3], objects[4], objects[5]
                }
            };

            var noComparerSet = new SCG.HashSet <SortedSet <T> >()
            {
                new SortedSet <T> {
                    objects[0], objects[1], objects[2]
                },
                new SortedSet <T> {
                    objects[3], objects[4], objects[5]
                }
            };

            var comparerSet1 = new SCG.HashSet <SortedSet <T> >(SortedSet <T> .CreateSetComparer())
            {
                new SortedSet <T> {
                    objects[0], objects[1], objects[2]
                },
                new SortedSet <T> {
                    objects[3], objects[4], objects[5]
                }
            };

            var comparerSet2 = new SCG.HashSet <SortedSet <T> >(SortedSet <T> .CreateSetComparer())
            {
                new SortedSet <T> {
                    objects[3], objects[4], objects[5]
                },
                new SortedSet <T> {
                    objects[0], objects[1], objects[2]
                }
            };

            Assert.True(noComparerSet.SetEquals(set)); // Unlike .NET's SortedSet, ours is structurally equatable by default
            Assert.True(comparerSet1.SetEquals(set));
            Assert.True(comparerSet2.SetEquals(set));
        }
Пример #5
0
    private void RankGameplayDataMap()
    {
        Dictionary currentDataMap;
        string     currentKey;
        long       currentValue;
        string     biggestRankKey = null;
        long       biggestValue   = long.MinValue;
        int        iterations     = gameplayDataMap.Count < 10 ? gameplayDataMap.Count : 10;

        SCG.HashSet <string> selectedMapSet = new SCG.HashSet <string>();
        rankedGameplayDataMap = new Dictionary();

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < iterations; j++)
            {
                currentKey = j.ToString();

                if (gameplayDataMap.Contains(currentKey) &&
                    !selectedMapSet.Contains(currentKey))
                {
                    currentDataMap = gameplayDataMap[currentKey] as Dictionary;

                    if (this.Call <bool>(gameplayData, this.GetMethodIsValidDataMap(),
                                         currentDataMap, gameplayDataKeyList, gameMode))
                    {
                        currentValue = long.Parse(currentDataMap[rankKey] as string);

                        if (currentValue > biggestValue)
                        {
                            biggestValue   = currentValue;
                            biggestRankKey = currentKey;
                        }
                    }
                }
            }

            if (gameplayDataMap.Contains(biggestRankKey) &&
                !selectedMapSet.Contains(biggestRankKey))
            {
                rankedGameplayDataMap.Add(i.ToString(), gameplayDataMap[biggestRankKey]);
                selectedMapSet.Add(biggestRankKey);
            }

            biggestValue   = long.MinValue;
            biggestRankKey = null;
        }
    }
Пример #6
0
    public void OnStartButtonPressed()
    {
        globalData.Call(this.GetMethodClear());         // NOTE: This clears all entries inside GlobalData.
        PutGlobal("totalTime", totalTime.ToString());
        PutGlobal("p1Deaths", p1Deaths);
        PutGlobal("p2Deaths", p2Deaths);
        PutGlobal("continues", continues);
        PutGlobal("levelScenePathList", locationScenePathList);
        PutGlobal("locationIndex", locationIndex);
        PutGlobal("specialistAmount", specialistAmountIndex + 1);
        PutGlobal("gameMode", (specialistAmountIndex + 1) + "P Story Mode");
        PutGlobal("sceneToLoad", this.GetScenePath(dialogueScreenScenePath));

        SCG.HashSet <int> selectedSpecialistKeySet = new SCG.HashSet <int>();
        Array             slotList;
        int specialistColorIndex;
        int autoSelect;

        for (int i = 0; i < specialistAmountIndex + 1; i++)
        {
            specialistColorIndex = specialistColorIndexes[i];
            autoSelect           = 0;
            slotList             = new Array();
            slotList.Add("S");
            slotList.Add("S");

            while (selectedSpecialistKeySet.Contains(specialistColorIndex))
            {
                specialistColorIndex = autoSelect++;
            }

            selectedSpecialistKeySet.Add(specialistColorIndex);

            PutGlobal("livesSpecialistIndex" + i, 4);
            PutGlobal("healthSpecialistIndex" + i, 100);
            PutGlobal("speedLevelSpecialistIndex" + i, 1);
            PutGlobal("laserRayLevelSpecialistIndex" + i, 1);
            PutGlobal("laserDeviceAmountSpecialistIndex" + i, 1);
            PutGlobal("detonateTimeLevelSpecialistIndex" + i, 1);
            PutGlobal("slotListSpecialistIndex" + i, slotList);
            PutGlobal("selectedSlotSpecialistIndex" + i, 0);
            PutGlobal("skillSpecialistIndex" + i, "");
            PutGlobal("colorSpecialistIndex" + i, specialistColorIndex);
        }

        GetTree().ChangeScene(this.GetScenePath(loadScreenScenePath));
    }
        public void TestEqualsTypeMismatch()
        {
            var list = new SCG.List <int> {
                1, 2, 3, 4, 5
            };
            var set = new SCG.HashSet <int> {
                1, 2, 3, 4, 5
            };
            var dictionary = new SCG.Dictionary <int, int> {
                { 1, 0 }, { 2, 0 }, { 3, 0 }, { 4, 0 }, { 5, 0 }
            };
            var array = new int[] { 1, 2, 3, 4, 5 };

            Assert.IsFalse(CollectionUtil.Equals(list, set));
            Assert.IsFalse(CollectionUtil.Equals(list, dictionary));
            Assert.IsTrue(CollectionUtil.Equals(list, array)); // Types are compatible - array implements IList<T>

            Assert.IsFalse(CollectionUtil.Equals(set, dictionary));
            Assert.IsFalse(CollectionUtil.Equals(set, array));
        }
Пример #8
0
    private void InitializeSpecialistsColor()
    {
        int specialistColor;
        int autoSelect;

        SCG.HashSet <int> selectedSpecialistKeySet = new SCG.HashSet <int>();

        for (int i = 0; i < specialistControls.Length; i++)
        {
            specialistColor = GetGlobal <int>("colorSpecialistIndex" + i);
            autoSelect      = 0;

            while (selectedSpecialistKeySet.Contains(specialistColor))
            {
                specialistColor = autoSelect++;
            }

            selectedSpecialistKeySet.Add(specialistColor);
            specialistColorIndexes[i] = specialistColor;
        }
    }
Пример #9
0
        public static bool ItemsAreUnique <T>(this SCG.IEnumerable <T> items)
        {
            #region Code Contracts

            // Must not be null
            Requires(items != null);

            #endregion

            // TODO: Replace with C5's HashTable once implemented
            var set = new SCG.HashSet <T>();
            foreach (var item in items)
            {
                if (set.Contains(item))
                {
                    return(false);
                }
                set.Add(item);
            }

            return(true);
        }
Пример #10
0
    private void RecoverAllWays(RecoveryParser rp)
    {
      // ReSharper disable once RedundantAssignment
      int maxPos = rp.MaxPos;
      var failPositions = new HashSet<int>();
      var deleted = new List<Tuple<int, ParsedSequence>>();


      do
      {

        var tmpDeleted = FindMaxFailPos(rp);
        if (rp.MaxPos != rp.ParseResult.Text.Length)
          UpdateParseErrorCount();

        if (!CheckUnclosedToken(rp))
          deleted.AddRange(tmpDeleted);
        else
        { }


        maxPos = rp.MaxPos;
        failPositions.Add(maxPos);

        var records = new SCG.Queue<ParseRecord>(rp.Records[maxPos]);
        var prevRecords = new SCG.HashSet<ParseRecord>(rp.Records[maxPos]);

        do
        {
          if (_parseResult.TerminateParsing)
            throw new OperationCanceledException();

          while (records.Count > 0)
          {
            var record = records.Dequeue();

            if (record.IsComplete)
            {
              rp.StartParseSubrule(maxPos, record);
              continue;
            }
            if (record.Sequence.IsToken)
              continue;

            foreach (var state in record.ParsingState.Next)
            {
              var newRecord = new ParseRecord(record.Sequence, state, maxPos);
              if (!rp.Records[maxPos].Contains(newRecord))
              {
                records.Enqueue(newRecord);
                prevRecords.Add(newRecord);
              }
            }

            rp.SubruleParsed(maxPos, maxPos, record);
            rp.PredictionOrScanning(maxPos, record, false);
          }

          rp.Parse();

          foreach (var record in rp.Records[maxPos])
            if (!prevRecords.Contains(record))
              records.Enqueue(record);
          prevRecords.UnionWith(rp.Records[maxPos]);
        }
        while (records.Count > 0);
      }
      while (rp.MaxPos > maxPos);

      foreach (var del in deleted)
        DeleteTokens(rp, del.Item1, del.Item2, NumberOfTokensForSpeculativeDeleting);
      rp.Parse();
    }
        public void TestEqualitySet()
        {
            var control = new SCG.HashSet <IDictionary <string, string> >
            {
                new SCG.Dictionary <string, string> {
                    { "1", "one" }, { "2", "two" }, { "3", "three" }
                },
                new SCG.Dictionary <string, string> {
                    { "4", "four" }, { "5", "five" }, { "6", "six" }
                },
                new SCG.Dictionary <string, string> {
                    { "7", "seven" }, { "8", "eight" }, { "9", "nine" }
                },
            };
            var equal = new SCG.HashSet <IDictionary <string, string> >
            {
                new SCG.Dictionary <string, string> {
                    { "1", "one" }, { "2", "two" }, { "3", "three" }
                },
                new SCG.Dictionary <string, string> {
                    { "4", "four" }, { "5", "five" }, { "6", "six" }
                },
                new SCG.Dictionary <string, string> {
                    { "7", "seven" }, { "8", "eight" }, { "9", "nine" }
                },
            };
            var equalDifferentType = new MockHashSet <IDictionary <string, string> >
            {
                new SCG.Dictionary <string, string> {
                    { "1", "one" }, { "2", "two" }, { "3", "three" }
                },
                new SCG.Dictionary <string, string> {
                    { "4", "four" }, { "5", "five" }, { "6", "six" }
                },
                new SCG.Dictionary <string, string> {
                    { "7", "seven" }, { "8", "eight" }, { "9", "nine" }
                },
            };
            var equalDifferentOrder = new SCG.HashSet <IDictionary <string, string> >
            {
                new SCG.Dictionary <string, string> {
                    { "7", "seven" }, { "8", "eight" }, { "9", "nine" }
                },
                new SCG.Dictionary <string, string> {
                    { "1", "one" }, { "2", "two" }, { "3", "three" }
                },
                new SCG.Dictionary <string, string> {
                    { "4", "four" }, { "5", "five" }, { "6", "six" }
                },
            };
            var level1EqualLevel2Unequal = new SCG.HashSet <IDictionary <string, string> >
            {
                new SCG.Dictionary <string, string> {
                    { "1", "one" }, { "2", "two" }, { "3", "three" }
                },
                new SCG.Dictionary <string, string> {
                    { "4", "four" }, { "5", "five" }, { "6", "six" }
                },
                new SCG.Dictionary <string, string> {
                    { "7", "seven" }, { "8", "eight" }, { "9", "nine99" }
                },
            };

            Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(control));
            Assert.IsTrue(CollectionUtil.Equals(control, control));

            Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equal));
            Assert.IsTrue(CollectionUtil.Equals(control, equal));

            Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equalDifferentType));
            Assert.IsTrue(CollectionUtil.Equals(control, equalDifferentType));

            // Sets are not order-sensitive
            Assert.AreEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(equalDifferentOrder));
            Assert.IsTrue(CollectionUtil.Equals(control, equalDifferentOrder));

            Assert.AreNotEqual(CollectionUtil.GetHashCode(control), CollectionUtil.GetHashCode(level1EqualLevel2Unequal));
            Assert.IsFalse(CollectionUtil.Equals(control, level1EqualLevel2Unequal));
        }
Пример #12
0
        private void RecoverAllWays(RecoveryParser rp)
        {
            // ReSharper disable once RedundantAssignment
            int maxPos        = rp.MaxPos;
            var failPositions = new HashSet <int>();
            var deleted       = new List <Tuple <int, ParsedSequence> >();


            do
            {
                var tmpDeleted = FindMaxFailPos(rp);
                if (rp.MaxPos != rp.ParseResult.Text.Length)
                {
                    UpdateParseErrorCount();
                }

                if (!CheckUnclosedToken(rp))
                {
                    deleted.AddRange(tmpDeleted);
                }
                else
                {
                }


                maxPos = rp.MaxPos;
                failPositions.Add(maxPos);

                var records     = new SCG.Queue <ParseRecord>(rp.Records[maxPos]);
                var prevRecords = new SCG.HashSet <ParseRecord>(rp.Records[maxPos]);

                do
                {
                    if (_parseResult.TerminateParsing)
                    {
                        throw new OperationCanceledException();
                    }

                    while (records.Count > 0)
                    {
                        var record = records.Dequeue();

                        if (record.IsComplete)
                        {
                            rp.StartParseSubrule(maxPos, record);
                            continue;
                        }
                        if (record.Sequence.IsToken)
                        {
                            continue;
                        }

                        foreach (var state in record.ParsingState.Next)
                        {
                            var newRecord = new ParseRecord(record.Sequence, state, maxPos);
                            if (!rp.Records[maxPos].Contains(newRecord))
                            {
                                records.Enqueue(newRecord);
                                prevRecords.Add(newRecord);
                            }
                        }

                        rp.SubruleParsed(maxPos, maxPos, record);
                        rp.PredictionOrScanning(maxPos, record, false);
                    }

                    rp.Parse();

                    foreach (var record in rp.Records[maxPos])
                    {
                        if (!prevRecords.Contains(record))
                        {
                            records.Enqueue(record);
                        }
                    }
                    prevRecords.UnionWith(rp.Records[maxPos]);
                }while (records.Count > 0);
            }while (rp.MaxPos > maxPos);

            foreach (var del in deleted)
            {
                DeleteTokens(rp, del.Item1, del.Item2, NumberOfTokensForSpeculativeDeleting);
            }
            rp.Parse();
        }