/// <summary>
        /// Registers all pending labels.
        /// Called once per frame during LateUpdate by the <see cref="PerceptionUpdater"/>.
        /// </summary>
        public void RegisterPendingLabels()
        {
            if (m_RegisteredLabels.Count == 0)
            {
                m_NextObjectIndex = k_StartingIndex;
            }

            foreach (var unregisteredLabel in m_LabelsPendingRegistration)
            {
                if (m_RegisteredLabels.Contains(unregisteredLabel))
                {
                    continue;
                }

                var instanceId = m_NextObjectIndex++;

                RecursivelyInitializeGameObjects(
                    unregisteredLabel.gameObject,
                    new MaterialPropertyBlock(),
                    unregisteredLabel,
                    instanceId);

                unregisteredLabel.SetInstanceId(instanceId);
                m_RegisteredLabels.Add(unregisteredLabel);
            }

            m_LabelsPendingRegistration.Clear();
        }
예제 #2
0
        public static ISet<string> AssignEventAsTagNumber(
            ISet<string> priorAllTags,
            EvalForgeNode evalForgeNode)
        {
            var allTagNamesOrdered = new LinkedHashSet<string>();
            var filterFactoryNodes = EvalNodeUtil.RecursiveGetChildNodes(
                evalForgeNode,
                StreamSpecCompiler.FilterForFilterFactoryNodes.INSTANCE);
            if (priorAllTags != null) {
                allTagNamesOrdered.AddAll(priorAllTags);
            }

            foreach (var filterNode in filterFactoryNodes) {
                var forge = (EvalFilterForgeNode) filterNode;
                int tagNumber;
                if (forge.EventAsName != null) {
                    if (!allTagNamesOrdered.Contains(forge.EventAsName)) {
                        allTagNamesOrdered.Add(forge.EventAsName);
                        tagNumber = allTagNamesOrdered.Count - 1;
                    }
                    else {
                        tagNumber = FindTagNumber(forge.EventAsName, allTagNamesOrdered);
                    }

                    forge.EventAsTagNumber = tagNumber;
                }
            }

            return allTagNamesOrdered;
        }
예제 #3
0
 public virtual void MarkSuspectBlock(ExtendedBlock block)
 {
     lock (this)
     {
         if (stopping)
         {
             Log.Debug("{}: Not scheduling suspect block {} for " + "rescanning, because this volume scanner is stopping."
                       , this, block);
             return;
         }
         bool recent = recentSuspectBlocks.GetIfPresent(block);
         if (recent != null)
         {
             Log.Debug("{}: Not scheduling suspect block {} for " + "rescanning, because we rescanned it recently."
                       , this, block);
             return;
         }
         if (suspectBlocks.Contains(block))
         {
             Log.Debug("{}: suspect block {} is already queued for " + "rescanning.", this, block
                       );
             return;
         }
         suspectBlocks.AddItem(block);
         recentSuspectBlocks.Put(block, true);
         Log.Debug("{}: Scheduling suspect block {} for rescanning.", this, block);
         Sharpen.Runtime.Notify(this);
     }
 }
예제 #4
0
            public bool Filter(ContextPartitionIdentifier contextPartitionIdentifier)
            {
                var id = (ContextPartitionIdentifierCategory) contextPartitionIdentifier;
                if (matchCategory == null && cpids.Contains(id.ContextPartitionId)) {
                    throw new EPException("Already exists context Id: " + id.ContextPartitionId);
                }

                cpids.Add(id.ContextPartitionId);
                categories.Add(id.Label);
                return matchCategory != null && matchCategory.Equals(id.Label);
            }
예제 #5
0
            public bool Filter(ContextPartitionIdentifier contextPartitionIdentifier)
            {
                var id = (ContextPartitionIdentifierHash) contextPartitionIdentifier;
                if (match == null && cpids.Contains(id.ContextPartitionId)) {
                    throw new EPException("Already exists context Id: " + id.ContextPartitionId);
                }

                cpids.Add(id.ContextPartitionId);
                Contexts.Add(id.Hash);
                return match.Contains(id.Hash);
            }
예제 #6
0
            public bool Filter(ContextPartitionIdentifier contextPartitionIdentifier)
            {
                var id = (ContextPartitionIdentifierCategory)contextPartitionIdentifier;

                if (_matchCategory == null && _cpids.Contains(id.ContextPartitionId.Value))
                {
                    throw new Exception("Already exists context id: " + id.ContextPartitionId);
                }
                _cpids.Add(id.ContextPartitionId.Value);
                _categories.Add(id.Label);
                return(_matchCategory != null && _matchCategory.Equals(id.Label));
            }
예제 #7
0
        /// <summary>given user name - get all the groups.</summary>
        /// <remarks>
        /// given user name - get all the groups.
        /// Needs to happen before creating the test users
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestGetServerSideGroups()
        {
            // get the user name
            SystemProcess  pp = Runtime.GetRuntime().Exec("whoami");
            BufferedReader br = new BufferedReader(new InputStreamReader(pp.GetInputStream())
                                                   );
            string userName = br.ReadLine().Trim();

            // If on windows domain, token format is DOMAIN\\user and we want to
            // extract only the user name
            if (Shell.Windows)
            {
                int sp = userName.LastIndexOf('\\');
                if (sp != -1)
                {
                    userName = Runtime.Substring(userName, sp + 1);
                }
                // user names are case insensitive on Windows. Make consistent
                userName = StringUtils.ToLowerCase(userName);
            }
            // get the groups
            pp = Runtime.GetRuntime().Exec(Shell.Windows ? Shell.Winutils + " groups -F" : "id -Gn"
                                           );
            br = new BufferedReader(new InputStreamReader(pp.GetInputStream()));
            string line = br.ReadLine();

            System.Console.Out.WriteLine(userName + ":" + line);
            ICollection <string> groups = new LinkedHashSet <string>();

            string[] tokens = line.Split(Shell.TokenSeparatorRegex);
            foreach (string s in tokens)
            {
                groups.AddItem(s);
            }
            UserGroupInformation login = UserGroupInformation.GetCurrentUser();
            string loginUserName       = login.GetShortUserName();

            if (Shell.Windows)
            {
                // user names are case insensitive on Windows. Make consistent
                loginUserName = StringUtils.ToLowerCase(loginUserName);
            }
            Assert.Equal(userName, loginUserName);
            string[] gi = login.GetGroupNames();
            Assert.Equal(groups.Count, gi.Length);
            for (int i = 0; i < gi.Length; i++)
            {
                Assert.True(groups.Contains(gi[i]));
            }
            UserGroupInformation fakeUser = UserGroupInformation.CreateRemoteUser("foo.bar");

            fakeUser.DoAs(new _PrivilegedExceptionAction_248(login, fakeUser));
        }
예제 #8
0
            public bool Filter(ContextPartitionIdentifier contextPartitionIdentifier)
            {
                var id = (ContextPartitionIdentifierHash)contextPartitionIdentifier;

                if (_match == null && _cpids.Contains(id.ContextPartitionId))
                {
                    throw new EPRuntimeException("Already exists context id: " + id.ContextPartitionId);
                }
                _cpids.Add(id.ContextPartitionId);
                _contexts.Add(id.Hash);
                return(_match.Contains(id.Hash));
            }
예제 #9
0
        public bool Filter(ContextPartitionIdentifier contextPartitionIdentifier) {
            var id = (ContextPartitionIdentifierInitiatedTerminated) contextPartitionIdentifier;
            if (_matchP00Value == null && _cpids.Contains(id.ContextPartitionId)) {
                throw new EPRuntimeException("Already exists context id: " + id.ContextPartitionId);
            }

            _cpids.Add(id.ContextPartitionId);
            _startTimes.Add(id.StartTime);
            var p00Value = (string) ((EventBean) id.Properties.Get("s0")).Get("p00");
            _p00PropertyValues.Add(p00Value);
            _lastValue = id;
            return _matchP00Value != null && _matchP00Value.Equals(p00Value);
        }
예제 #10
0
 public void addEnvironmentObject(EnvironmentObject eo)
 {
     envObjects.Add(eo);
     if (eo is Agent)
     {
         Agent a = (Agent)eo;
         if (!agents.Contains(a))
         {
             agents.Add(a);
             this.updateEnvironmentViewsAgentAdded(a);
         }
     }
 }
예제 #11
0
        /// <summary>Normalizes text decoration values.</summary>
        /// <param name="value">the text decoration value</param>
        /// <returns>a set of normalized decoration values</returns>
        private static ICollection <String> NormalizeTextDecoration(String value)
        {
            String[] parts = iText.IO.Util.StringUtil.Split(value, "\\s+");
            // LinkedHashSet to make order invariant of JVM
            ICollection <String> merged = new LinkedHashSet <String>();

            merged.AddAll(JavaUtil.ArraysAsList(parts));
            // if none and any other decoration are used together, none is displayed
            if (merged.Contains(CommonCssConstants.NONE))
            {
                merged.Clear();
            }
            return(merged);
        }
예제 #12
0
        protected string CreateT(LinkedHashSet <string> set, int seed)
        {
            int    stringLength = seed % 10 + 5;
            Random rand         = new Random(seed);

            byte[] bytes = new byte[stringLength];
            rand.NextBytes(bytes);
            string ret = Convert.ToBase64String(bytes);

            while (set.Contains(ret))
            {
                rand.NextBytes(bytes);
                ret = Convert.ToBase64String(bytes);
            }
            return(ret);
        }
예제 #13
0
        private PatternStreamSpecCompiled CompileInternal(
            StatementContext context,
            ICollection <string> eventTypeReferences,
            bool isInsertInto,
            ICollection <int> assignedTypeNumberStack,
            MatchEventSpec tags,
            IEnumerable <string> priorAllTags,
            bool isJoin,
            bool isContextDeclaration,
            bool isOnTrigger)
        {
            // validate
            if ((_suppressSameEventMatches || _discardPartialsOnMatch) &&
                (isJoin || isContextDeclaration || isOnTrigger))
            {
                throw new ExprValidationException(
                          "Discard-partials and suppress-matches is not supported in a joins, context declaration and on-action");
            }

            if (tags == null)
            {
                tags = new MatchEventSpec();
            }
            var subexpressionIdStack = new ArrayDeque <int>(assignedTypeNumberStack);
            var evaluatorContextStmt = new ExprEvaluatorContextStatement(context, false);
            var nodeStack            = new Stack <EvalFactoryNode>();

            // detemine ordered tags
            var filterFactoryNodes = EvalNodeUtil.RecursiveGetChildNodes(
                _evalFactoryNode, FilterForFilterFactoryNodes.INSTANCE);
            var allTagNamesOrdered = new LinkedHashSet <string>();

            if (priorAllTags != null)
            {
                allTagNamesOrdered.AddAll(priorAllTags);
            }
            foreach (var filterNode in filterFactoryNodes)
            {
                var factory = (EvalFilterFactoryNode)filterNode;
                int tagNumber;
                if (factory.EventAsName != null)
                {
                    if (!allTagNamesOrdered.Contains(factory.EventAsName))
                    {
                        allTagNamesOrdered.Add(factory.EventAsName);
                        tagNumber = allTagNamesOrdered.Count - 1;
                    }
                    else
                    {
                        tagNumber = FindTagNumber(factory.EventAsName, allTagNamesOrdered);
                    }
                    factory.EventAsTagNumber = tagNumber;
                }
            }

            RecursiveCompile(
                _evalFactoryNode, context, evaluatorContextStmt, eventTypeReferences, isInsertInto, tags,
                subexpressionIdStack, nodeStack, allTagNamesOrdered);

            var auditPattern            = AuditEnum.PATTERN.GetAudit(context.Annotations);
            var auditPatternInstance    = AuditEnum.PATTERNINSTANCES.GetAudit(context.Annotations);
            var compiledEvalFactoryNode = _evalFactoryNode;

            if (context.PatternNodeFactory.IsAuditSupported && (auditPattern != null || auditPatternInstance != null))
            {
                var instanceCount = new EvalAuditInstanceCount();
                compiledEvalFactoryNode = RecursiveAddAuditNode(
                    context.PatternNodeFactory, null, auditPattern != null, auditPatternInstance != null,
                    _evalFactoryNode, instanceCount);
            }

            return(new PatternStreamSpecCompiled(
                       compiledEvalFactoryNode, tags.TaggedEventTypes, tags.ArrayEventTypes, allTagNamesOrdered, ViewSpecs,
                       OptionalStreamName, Options, _suppressSameEventMatches, _discardPartialsOnMatch));
        }
예제 #14
0
     public void TestContainsObject()
     {
         Assert.IsTrue(hs.Contains(objArray[90]), "Returned false for valid object");
         Assert.IsTrue(!hs.Contains(new Object()), "Returned true for invalid Object");
 
         LinkedHashSet<Object> s = new LinkedHashSet<Object>();
         s.Add(null);
         Assert.IsTrue(s.Contains(null), "Cannot handle null");
     }
예제 #15
0
 /// <summary>
 /// Returns an indication whether the filter callback exists in this node.
 /// NOTE: the client to this method must use the read-write lock of this object
 /// to lock, if required by the client code.
 /// </summary>
 /// <param name="filterCallback">is the filter callback to check for</param>
 /// <returns>true if callback found, false if not</returns>
 public bool Contains(FilterHandle filterCallback)
 {
     return(_callbackSet.Contains(filterCallback));
 }
예제 #16
0
        public static void LinkedHashSetTest()
        {
            int[] setEmpty = { };
            int[] set1     = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int[] set2     = { 1, 2, 3, 4, 5, 6, 6, 8, 9 };
            int[] set3     = { 1, 2, 3, 4, 5, 6, 8, 9, 0 };

            LinkedHashSet <int> lhsEmpty = new LinkedHashSet <int>();
            LinkedHashSet <int> lhs1     = new LinkedHashSet <int>(set1);
            LinkedHashSet <int> lhs2     = new LinkedHashSet <int>(set2);
            LinkedHashSet <int> lhs3     = new LinkedHashSet <int>(set3);

            HashSet <int> hsEmpty = new HashSet <int>();
            HashSet <int> hs1     = new HashSet <int>(set1);
            HashSet <int> hs2     = new HashSet <int>(set2);
            HashSet <int> hs3     = new HashSet <int>(set3);

            #region Pseudo-LINQ-Extensions
            Assert.AreEqual(1, lhs1.First());
            Assert.AreEqual(9, lhs1.Last());
            Assert.AreEqual(0, lhs3.Last());
            Assert.Throws <InvalidOperationException>(() => lhsEmpty.First());
            Assert.Throws <InvalidOperationException>(() => lhsEmpty.Last());
            Assert.DoesNotThrow(() => lhsEmpty.FirstOrDefault());
            Assert.DoesNotThrow(() => lhsEmpty.LastOrDefault());
            Assert.AreEqual(default(int), lhsEmpty.FirstOrDefault());
            Assert.AreEqual(default(int), lhsEmpty.LastOrDefault());

            Assert.DoesNotThrow(() => lhsEmpty.Reverse());
            List <int> reversed = new List <int>(lhs3.Reverse());
            Assert.AreEqual(lhs3.Count, reversed.Count);
            Assert.AreEqual(0, reversed[0]);
            Assert.AreEqual(9, reversed[1]);
            Assert.AreEqual(8, reversed[2]);
            Assert.AreEqual(6, reversed[3]);
            Assert.AreEqual(5, reversed[4]);
            Assert.AreEqual(4, reversed[5]);
            Assert.AreEqual(3, reversed[6]);
            Assert.AreEqual(2, reversed[7]);
            Assert.AreEqual(1, reversed[8]);
            #endregion

            #region SetEquals
            Assert.IsTrue(lhsEmpty.SetEquals(lhsEmpty));
            Assert.IsTrue(lhs1.SetEquals(lhs1));
            Assert.IsTrue(lhs2.SetEquals(lhs2));
            Assert.IsTrue(lhs3.SetEquals(lhs3));

            Assert.IsTrue(lhsEmpty.SetEquals(hsEmpty));
            Assert.IsTrue(lhs1.SetEquals(hs1));
            Assert.IsTrue(lhs2.SetEquals(hs2));
            Assert.IsTrue(lhs3.SetEquals(hs3));

            Assert.IsTrue(lhsEmpty.SetEquals(setEmpty));
            Assert.IsTrue(lhs1.SetEquals(set1));
            Assert.IsTrue(lhs2.SetEquals(set2));
            Assert.IsTrue(lhs3.SetEquals(set3));

            Assert.IsTrue(lhsEmpty.SetEquals(GetEnumerator(setEmpty)));
            Assert.IsTrue(lhs1.SetEquals(GetEnumerator(set1)));
            Assert.IsTrue(lhs2.SetEquals(GetEnumerator(set2)));
            Assert.IsTrue(lhs3.SetEquals(GetEnumerator(set3)));

            Assert.IsFalse(lhsEmpty.SetEquals(lhs1));
            Assert.IsFalse(lhsEmpty.SetEquals(lhs2));
            Assert.IsFalse(lhsEmpty.SetEquals(lhs3));
            Assert.IsFalse(lhsEmpty.SetEquals(hs1));
            Assert.IsFalse(lhsEmpty.SetEquals(hs2));
            Assert.IsFalse(lhsEmpty.SetEquals(hs3));
            Assert.IsFalse(lhsEmpty.SetEquals(set1));
            Assert.IsFalse(lhsEmpty.SetEquals(set2));
            Assert.IsFalse(lhsEmpty.SetEquals(set3));
            Assert.IsFalse(lhsEmpty.SetEquals(GetEnumerator(set1)));
            Assert.IsFalse(lhsEmpty.SetEquals(GetEnumerator(set2)));
            Assert.IsFalse(lhsEmpty.SetEquals(GetEnumerator(set3)));

            Assert.IsFalse(lhs1.SetEquals(lhsEmpty));
            Assert.IsFalse(lhs1.SetEquals(lhs2));
            Assert.IsFalse(lhs1.SetEquals(lhs3));
            Assert.IsFalse(lhs1.SetEquals(hsEmpty));
            Assert.IsFalse(lhs1.SetEquals(hs2));
            Assert.IsFalse(lhs1.SetEquals(hs3));
            Assert.IsFalse(lhs1.SetEquals(setEmpty));
            Assert.IsFalse(lhs1.SetEquals(set2));
            Assert.IsFalse(lhs1.SetEquals(set3));
            Assert.IsFalse(lhs1.SetEquals(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs1.SetEquals(GetEnumerator(set2)));
            Assert.IsFalse(lhs1.SetEquals(GetEnumerator(set3)));

            Assert.IsFalse(lhs2.SetEquals(lhsEmpty));
            Assert.IsFalse(lhs2.SetEquals(lhs1));
            Assert.IsFalse(lhs2.SetEquals(lhs3));
            Assert.IsFalse(lhs2.SetEquals(hsEmpty));
            Assert.IsFalse(lhs2.SetEquals(hs1));
            Assert.IsFalse(lhs2.SetEquals(hs3));
            Assert.IsFalse(lhs2.SetEquals(setEmpty));
            Assert.IsFalse(lhs2.SetEquals(set1));
            Assert.IsFalse(lhs2.SetEquals(set3));
            Assert.IsFalse(lhs2.SetEquals(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs2.SetEquals(GetEnumerator(set1)));
            Assert.IsFalse(lhs2.SetEquals(GetEnumerator(set3)));

            Assert.IsFalse(lhs3.SetEquals(lhsEmpty));
            Assert.IsFalse(lhs3.SetEquals(lhs1));
            Assert.IsFalse(lhs3.SetEquals(lhs2));
            Assert.IsFalse(lhs3.SetEquals(hsEmpty));
            Assert.IsFalse(lhs3.SetEquals(hs1));
            Assert.IsFalse(lhs3.SetEquals(hs2));
            Assert.IsFalse(lhs3.SetEquals(setEmpty));
            Assert.IsFalse(lhs3.SetEquals(set1));
            Assert.IsFalse(lhs3.SetEquals(set2));
            Assert.IsFalse(lhs3.SetEquals(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs3.SetEquals(GetEnumerator(set1)));
            Assert.IsFalse(lhs3.SetEquals(GetEnumerator(set2)));
            #endregion

            #region Overlaps
            Assert.IsFalse(lhsEmpty.Overlaps(lhsEmpty));
            Assert.IsTrue(lhs1.Overlaps(lhs1));
            Assert.IsTrue(lhs2.Overlaps(lhs2));
            Assert.IsTrue(lhs3.Overlaps(lhs3));

            Assert.IsFalse(lhsEmpty.Overlaps(hsEmpty));
            Assert.IsTrue(lhs1.Overlaps(hs1));
            Assert.IsTrue(lhs2.Overlaps(hs2));
            Assert.IsTrue(lhs3.Overlaps(hs3));

            Assert.IsFalse(lhsEmpty.Overlaps(setEmpty));
            Assert.IsTrue(lhs1.Overlaps(set1));
            Assert.IsTrue(lhs2.Overlaps(set2));
            Assert.IsTrue(lhs3.Overlaps(set3));

            Assert.IsFalse(lhsEmpty.Overlaps(GetEnumerator(setEmpty)));
            Assert.IsTrue(lhs1.Overlaps(GetEnumerator(set1)));
            Assert.IsTrue(lhs2.Overlaps(GetEnumerator(set2)));
            Assert.IsTrue(lhs3.Overlaps(GetEnumerator(set3)));

            Assert.IsFalse(lhsEmpty.Overlaps(lhs1));
            Assert.IsFalse(lhsEmpty.Overlaps(lhs2));
            Assert.IsFalse(lhsEmpty.Overlaps(lhs3));
            Assert.IsFalse(lhsEmpty.Overlaps(hs1));
            Assert.IsFalse(lhsEmpty.Overlaps(hs2));
            Assert.IsFalse(lhsEmpty.Overlaps(hs3));
            Assert.IsFalse(lhsEmpty.Overlaps(set1));
            Assert.IsFalse(lhsEmpty.Overlaps(set2));
            Assert.IsFalse(lhsEmpty.Overlaps(set3));
            Assert.IsFalse(lhsEmpty.Overlaps(GetEnumerator(set1)));
            Assert.IsFalse(lhsEmpty.Overlaps(GetEnumerator(set2)));
            Assert.IsFalse(lhsEmpty.Overlaps(GetEnumerator(set3)));

            Assert.IsFalse(lhs1.Overlaps(lhsEmpty));
            Assert.IsTrue(lhs1.Overlaps(lhs2));
            Assert.IsTrue(lhs1.Overlaps(lhs3));
            Assert.IsFalse(lhs1.Overlaps(hsEmpty));
            Assert.IsTrue(lhs1.Overlaps(hs2));
            Assert.IsTrue(lhs1.Overlaps(hs3));
            Assert.IsFalse(lhs1.Overlaps(setEmpty));
            Assert.IsTrue(lhs1.Overlaps(set2));
            Assert.IsTrue(lhs1.Overlaps(set3));
            Assert.IsFalse(lhs1.Overlaps(GetEnumerator(setEmpty)));
            Assert.IsTrue(lhs1.Overlaps(GetEnumerator(set2)));
            Assert.IsTrue(lhs1.Overlaps(GetEnumerator(set3)));

            Assert.IsFalse(lhs2.Overlaps(lhsEmpty));
            Assert.IsTrue(lhs2.Overlaps(lhs1));
            Assert.IsTrue(lhs2.Overlaps(lhs3));
            Assert.IsFalse(lhs2.Overlaps(hsEmpty));
            Assert.IsTrue(lhs2.Overlaps(hs1));
            Assert.IsTrue(lhs2.Overlaps(hs3));
            Assert.IsFalse(lhs2.Overlaps(setEmpty));
            Assert.IsTrue(lhs2.Overlaps(set1));
            Assert.IsTrue(lhs2.Overlaps(set3));
            Assert.IsFalse(lhs2.Overlaps(GetEnumerator(setEmpty)));
            Assert.IsTrue(lhs2.Overlaps(GetEnumerator(set1)));
            Assert.IsTrue(lhs2.Overlaps(GetEnumerator(set3)));

            Assert.IsFalse(lhs3.Overlaps(lhsEmpty));
            Assert.IsTrue(lhs3.Overlaps(lhs1));
            Assert.IsTrue(lhs3.Overlaps(lhs2));
            Assert.IsFalse(lhs3.Overlaps(hsEmpty));
            Assert.IsTrue(lhs3.Overlaps(hs1));
            Assert.IsTrue(lhs3.Overlaps(hs2));
            Assert.IsFalse(lhs3.Overlaps(setEmpty));
            Assert.IsTrue(lhs3.Overlaps(set1));
            Assert.IsTrue(lhs3.Overlaps(set2));
            Assert.IsFalse(lhs3.Overlaps(GetEnumerator(setEmpty)));
            Assert.IsTrue(lhs3.Overlaps(GetEnumerator(set1)));
            Assert.IsTrue(lhs3.Overlaps(GetEnumerator(set2)));
            #endregion

            #region IsSubsetOf
            Assert.IsTrue(lhsEmpty.IsSubsetOf(lhsEmpty));
            Assert.IsTrue(lhs1.IsSubsetOf(lhs1));
            Assert.IsTrue(lhs2.IsSubsetOf(lhs2));
            Assert.IsTrue(lhs3.IsSubsetOf(lhs3));

            Assert.IsTrue(lhsEmpty.IsSubsetOf(hsEmpty));
            Assert.IsTrue(lhs1.IsSubsetOf(hs1));
            Assert.IsTrue(lhs2.IsSubsetOf(hs2));
            Assert.IsTrue(lhs3.IsSubsetOf(hs3));

            Assert.IsTrue(lhsEmpty.IsSubsetOf(setEmpty));
            Assert.IsTrue(lhs1.IsSubsetOf(set1));
            Assert.IsTrue(lhs2.IsSubsetOf(set2));
            Assert.IsTrue(lhs3.IsSubsetOf(set3));

            Assert.IsTrue(lhsEmpty.IsSubsetOf(GetEnumerator(setEmpty)));
            Assert.IsTrue(lhs1.IsSubsetOf(GetEnumerator(set1)));
            Assert.IsTrue(lhs2.IsSubsetOf(GetEnumerator(set2)));
            Assert.IsTrue(lhs3.IsSubsetOf(GetEnumerator(set3)));

            Assert.IsTrue(lhsEmpty.IsSubsetOf(lhs1));
            Assert.IsTrue(lhsEmpty.IsSubsetOf(lhs2));
            Assert.IsTrue(lhsEmpty.IsSubsetOf(lhs3));
            Assert.IsTrue(lhsEmpty.IsSubsetOf(hs1));
            Assert.IsTrue(lhsEmpty.IsSubsetOf(hs2));
            Assert.IsTrue(lhsEmpty.IsSubsetOf(hs3));
            Assert.IsTrue(lhsEmpty.IsSubsetOf(set1));
            Assert.IsTrue(lhsEmpty.IsSubsetOf(set2));
            Assert.IsTrue(lhsEmpty.IsSubsetOf(set3));
            Assert.IsTrue(lhsEmpty.IsSubsetOf(GetEnumerator(set1)));
            Assert.IsTrue(lhsEmpty.IsSubsetOf(GetEnumerator(set2)));
            Assert.IsTrue(lhsEmpty.IsSubsetOf(GetEnumerator(set3)));

            Assert.IsFalse(lhs1.IsSubsetOf(lhsEmpty));
            Assert.IsFalse(lhs1.IsSubsetOf(lhs2));
            Assert.IsFalse(lhs1.IsSubsetOf(lhs3));
            Assert.IsFalse(lhs1.IsSubsetOf(hsEmpty));
            Assert.IsFalse(lhs1.IsSubsetOf(hs2));
            Assert.IsFalse(lhs1.IsSubsetOf(hs3));
            Assert.IsFalse(lhs1.IsSubsetOf(setEmpty));
            Assert.IsFalse(lhs1.IsSubsetOf(set2));
            Assert.IsFalse(lhs1.IsSubsetOf(set3));
            Assert.IsFalse(lhs1.IsSubsetOf(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs1.IsSubsetOf(GetEnumerator(set2)));
            Assert.IsFalse(lhs1.IsSubsetOf(GetEnumerator(set3)));

            Assert.IsFalse(lhs2.IsSubsetOf(lhsEmpty));
            Assert.IsTrue(lhs2.IsSubsetOf(lhs1));
            Assert.IsTrue(lhs2.IsSubsetOf(lhs3));
            Assert.IsFalse(lhs2.IsSubsetOf(hsEmpty));
            Assert.IsTrue(lhs2.IsSubsetOf(hs1));
            Assert.IsTrue(lhs2.IsSubsetOf(hs3));
            Assert.IsFalse(lhs2.IsSubsetOf(setEmpty));
            Assert.IsTrue(lhs2.IsSubsetOf(set1));
            Assert.IsTrue(lhs2.IsSubsetOf(set3));
            Assert.IsFalse(lhs2.IsSubsetOf(GetEnumerator(setEmpty)));
            Assert.IsTrue(lhs2.IsSubsetOf(GetEnumerator(set1)));
            Assert.IsTrue(lhs2.IsSubsetOf(GetEnumerator(set3)));

            Assert.IsFalse(lhs3.IsSubsetOf(lhsEmpty));
            Assert.IsFalse(lhs3.IsSubsetOf(lhs1));
            Assert.IsFalse(lhs3.IsSubsetOf(lhs2));
            Assert.IsFalse(lhs3.IsSubsetOf(hsEmpty));
            Assert.IsFalse(lhs3.IsSubsetOf(hs1));
            Assert.IsFalse(lhs3.IsSubsetOf(hs2));
            Assert.IsFalse(lhs3.IsSubsetOf(setEmpty));
            Assert.IsFalse(lhs3.IsSubsetOf(set1));
            Assert.IsFalse(lhs3.IsSubsetOf(set2));
            Assert.IsFalse(lhs3.IsSubsetOf(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs3.IsSubsetOf(GetEnumerator(set1)));
            Assert.IsFalse(lhs3.IsSubsetOf(GetEnumerator(set2)));
            #endregion

            #region IsProperSubsetOf
            Assert.IsFalse(lhsEmpty.IsProperSubsetOf(lhsEmpty));
            Assert.IsFalse(lhs1.IsProperSubsetOf(lhs1));
            Assert.IsFalse(lhs2.IsProperSubsetOf(lhs2));
            Assert.IsFalse(lhs3.IsProperSubsetOf(lhs3));

            Assert.IsFalse(lhsEmpty.IsProperSubsetOf(hsEmpty));
            Assert.IsFalse(lhs1.IsProperSubsetOf(hs1));
            Assert.IsFalse(lhs2.IsProperSubsetOf(hs2));
            Assert.IsFalse(lhs3.IsProperSubsetOf(hs3));

            Assert.IsFalse(lhsEmpty.IsProperSubsetOf(setEmpty));
            Assert.IsFalse(lhs1.IsProperSubsetOf(set1));
            Assert.IsFalse(lhs2.IsProperSubsetOf(set2));
            Assert.IsFalse(lhs3.IsProperSubsetOf(set3));

            Assert.IsFalse(lhsEmpty.IsProperSubsetOf(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs1.IsProperSubsetOf(GetEnumerator(set1)));
            Assert.IsFalse(lhs2.IsProperSubsetOf(GetEnumerator(set2)));
            Assert.IsFalse(lhs3.IsProperSubsetOf(GetEnumerator(set3)));

            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(lhs1));
            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(lhs2));
            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(lhs3));
            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(hs1));
            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(hs2));
            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(hs3));
            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(set1));
            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(set2));
            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(set3));
            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(GetEnumerator(set1)));
            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(GetEnumerator(set2)));
            Assert.IsTrue(lhsEmpty.IsProperSubsetOf(GetEnumerator(set3)));

            Assert.IsFalse(lhs1.IsProperSubsetOf(lhsEmpty));
            Assert.IsFalse(lhs1.IsProperSubsetOf(lhs2));
            Assert.IsFalse(lhs1.IsProperSubsetOf(lhs3));
            Assert.IsFalse(lhs1.IsProperSubsetOf(hsEmpty));
            Assert.IsFalse(lhs1.IsProperSubsetOf(hs2));
            Assert.IsFalse(lhs1.IsProperSubsetOf(hs3));
            Assert.IsFalse(lhs1.IsProperSubsetOf(setEmpty));
            Assert.IsFalse(lhs1.IsProperSubsetOf(set2));
            Assert.IsFalse(lhs1.IsProperSubsetOf(set3));
            Assert.IsFalse(lhs1.IsProperSubsetOf(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs1.IsProperSubsetOf(GetEnumerator(set2)));
            Assert.IsFalse(lhs1.IsProperSubsetOf(GetEnumerator(set3)));

            Assert.IsFalse(lhs2.IsProperSubsetOf(lhsEmpty));
            Assert.IsTrue(lhs2.IsProperSubsetOf(lhs1));
            Assert.IsTrue(lhs2.IsProperSubsetOf(lhs3));
            Assert.IsFalse(lhs2.IsProperSubsetOf(hsEmpty));
            Assert.IsTrue(lhs2.IsProperSubsetOf(hs1));
            Assert.IsTrue(lhs2.IsProperSubsetOf(hs3));
            Assert.IsFalse(lhs2.IsProperSubsetOf(setEmpty));
            Assert.IsTrue(lhs2.IsProperSubsetOf(set1));
            Assert.IsTrue(lhs2.IsProperSubsetOf(set3));
            Assert.IsFalse(lhs2.IsProperSubsetOf(GetEnumerator(setEmpty)));
            Assert.IsTrue(lhs2.IsProperSubsetOf(GetEnumerator(set1)));
            Assert.IsTrue(lhs2.IsProperSubsetOf(GetEnumerator(set3)));

            Assert.IsFalse(lhs3.IsProperSubsetOf(lhsEmpty));
            Assert.IsFalse(lhs3.IsProperSubsetOf(lhs1));
            Assert.IsFalse(lhs3.IsProperSubsetOf(lhs2));
            Assert.IsFalse(lhs3.IsProperSubsetOf(hsEmpty));
            Assert.IsFalse(lhs3.IsProperSubsetOf(hs1));
            Assert.IsFalse(lhs3.IsProperSubsetOf(hs2));
            Assert.IsFalse(lhs3.IsProperSubsetOf(setEmpty));
            Assert.IsFalse(lhs3.IsProperSubsetOf(set1));
            Assert.IsFalse(lhs3.IsProperSubsetOf(set2));
            Assert.IsFalse(lhs3.IsProperSubsetOf(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs3.IsProperSubsetOf(GetEnumerator(set1)));
            Assert.IsFalse(lhs3.IsProperSubsetOf(GetEnumerator(set2)));
            #endregion

            #region IsSupersetOf
            Assert.IsTrue(lhsEmpty.IsSupersetOf(lhsEmpty));
            Assert.IsTrue(lhs1.IsSupersetOf(lhs1));
            Assert.IsTrue(lhs2.IsSupersetOf(lhs2));
            Assert.IsTrue(lhs3.IsSupersetOf(lhs3));

            Assert.IsTrue(lhsEmpty.IsSupersetOf(hsEmpty));
            Assert.IsTrue(lhs1.IsSupersetOf(hs1));
            Assert.IsTrue(lhs2.IsSupersetOf(hs2));
            Assert.IsTrue(lhs3.IsSupersetOf(hs3));

            Assert.IsTrue(lhsEmpty.IsSupersetOf(setEmpty));
            Assert.IsTrue(lhs1.IsSupersetOf(set1));
            Assert.IsTrue(lhs2.IsSupersetOf(set2));
            Assert.IsTrue(lhs3.IsSupersetOf(set3));

            Assert.IsTrue(lhsEmpty.IsSupersetOf(GetEnumerator(setEmpty)));
            Assert.IsTrue(lhs1.IsSupersetOf(GetEnumerator(set1)));
            Assert.IsTrue(lhs2.IsSupersetOf(GetEnumerator(set2)));
            Assert.IsTrue(lhs3.IsSupersetOf(GetEnumerator(set3)));

            Assert.IsFalse(lhsEmpty.IsSupersetOf(lhs1));
            Assert.IsFalse(lhsEmpty.IsSupersetOf(lhs2));
            Assert.IsFalse(lhsEmpty.IsSupersetOf(lhs3));
            Assert.IsFalse(lhsEmpty.IsSupersetOf(hs1));
            Assert.IsFalse(lhsEmpty.IsSupersetOf(hs2));
            Assert.IsFalse(lhsEmpty.IsSupersetOf(hs3));
            Assert.IsFalse(lhsEmpty.IsSupersetOf(set1));
            Assert.IsFalse(lhsEmpty.IsSupersetOf(set2));
            Assert.IsFalse(lhsEmpty.IsSupersetOf(set3));
            Assert.IsFalse(lhsEmpty.IsSupersetOf(GetEnumerator(set1)));
            Assert.IsFalse(lhsEmpty.IsSupersetOf(GetEnumerator(set2)));
            Assert.IsFalse(lhsEmpty.IsSupersetOf(GetEnumerator(set3)));

            Assert.IsTrue(lhs1.IsSupersetOf(lhsEmpty));
            Assert.IsTrue(lhs1.IsSupersetOf(lhs2));
            Assert.IsFalse(lhs1.IsSupersetOf(lhs3));
            Assert.IsTrue(lhs1.IsSupersetOf(hsEmpty));
            Assert.IsTrue(lhs1.IsSupersetOf(hs2));
            Assert.IsFalse(lhs1.IsSupersetOf(hs3));
            Assert.IsTrue(lhs1.IsSupersetOf(setEmpty));
            Assert.IsTrue(lhs1.IsSupersetOf(set2));
            Assert.IsFalse(lhs1.IsSupersetOf(set3));
            Assert.IsTrue(lhs1.IsSupersetOf(GetEnumerator(setEmpty)));
            Assert.IsTrue(lhs1.IsSupersetOf(GetEnumerator(set2)));
            Assert.IsFalse(lhs1.IsSupersetOf(GetEnumerator(set3)));

            Assert.IsTrue(lhs2.IsSupersetOf(lhsEmpty));
            Assert.IsFalse(lhs2.IsSupersetOf(lhs1));
            Assert.IsFalse(lhs2.IsSupersetOf(lhs3));
            Assert.IsTrue(lhs2.IsSupersetOf(hsEmpty));
            Assert.IsFalse(lhs2.IsSupersetOf(hs1));
            Assert.IsFalse(lhs2.IsSupersetOf(hs3));
            Assert.IsTrue(lhs2.IsSupersetOf(setEmpty));
            Assert.IsFalse(lhs2.IsSupersetOf(set1));
            Assert.IsFalse(lhs2.IsSupersetOf(set3));
            Assert.IsTrue(lhs2.IsSupersetOf(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs2.IsSupersetOf(GetEnumerator(set1)));
            Assert.IsFalse(lhs2.IsSupersetOf(GetEnumerator(set3)));

            Assert.IsTrue(lhs3.IsSupersetOf(lhsEmpty));
            Assert.IsFalse(lhs3.IsSupersetOf(lhs1));
            Assert.IsTrue(lhs3.IsSupersetOf(lhs2));
            Assert.IsTrue(lhs3.IsSupersetOf(hsEmpty));
            Assert.IsFalse(lhs3.IsSupersetOf(hs1));
            Assert.IsTrue(lhs3.IsSupersetOf(hs2));
            Assert.IsTrue(lhs3.IsSupersetOf(setEmpty));
            Assert.IsFalse(lhs3.IsSupersetOf(set1));
            Assert.IsTrue(lhs3.IsSupersetOf(set2));
            Assert.IsTrue(lhs3.IsSupersetOf(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs3.IsSupersetOf(GetEnumerator(set1)));
            Assert.IsTrue(lhs3.IsSupersetOf(GetEnumerator(set2)));
            #endregion

            #region IsProperSupersetOf
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(lhsEmpty));
            Assert.IsFalse(lhs1.IsProperSupersetOf(lhs1));
            Assert.IsFalse(lhs2.IsProperSupersetOf(lhs2));
            Assert.IsFalse(lhs3.IsProperSupersetOf(lhs3));

            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(hsEmpty));
            Assert.IsFalse(lhs1.IsProperSupersetOf(hs1));
            Assert.IsFalse(lhs2.IsProperSupersetOf(hs2));
            Assert.IsFalse(lhs3.IsProperSupersetOf(hs3));

            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(setEmpty));
            Assert.IsFalse(lhs1.IsProperSupersetOf(set1));
            Assert.IsFalse(lhs2.IsProperSupersetOf(set2));
            Assert.IsFalse(lhs3.IsProperSupersetOf(set3));

            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs1.IsProperSupersetOf(GetEnumerator(set1)));
            Assert.IsFalse(lhs2.IsProperSupersetOf(GetEnumerator(set2)));
            Assert.IsFalse(lhs3.IsProperSupersetOf(GetEnumerator(set3)));

            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(lhs1));
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(lhs2));
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(lhs3));
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(hs1));
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(hs2));
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(hs3));
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(set1));
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(set2));
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(set3));
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(GetEnumerator(set1)));
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(GetEnumerator(set2)));
            Assert.IsFalse(lhsEmpty.IsProperSupersetOf(GetEnumerator(set3)));

            Assert.IsTrue(lhs1.IsProperSupersetOf(lhsEmpty));
            Assert.IsTrue(lhs1.IsProperSupersetOf(lhs2));
            Assert.IsFalse(lhs1.IsProperSupersetOf(lhs3));
            Assert.IsTrue(lhs1.IsProperSupersetOf(hsEmpty));
            Assert.IsTrue(lhs1.IsProperSupersetOf(hs2));
            Assert.IsFalse(lhs1.IsProperSupersetOf(hs3));
            Assert.IsTrue(lhs1.IsProperSupersetOf(setEmpty));
            Assert.IsTrue(lhs1.IsProperSupersetOf(set2));
            Assert.IsFalse(lhs1.IsProperSupersetOf(set3));
            Assert.IsTrue(lhs1.IsProperSupersetOf(GetEnumerator(setEmpty)));
            Assert.IsTrue(lhs1.IsProperSupersetOf(GetEnumerator(set2)));
            Assert.IsFalse(lhs1.IsProperSupersetOf(GetEnumerator(set3)));

            Assert.IsTrue(lhs2.IsProperSupersetOf(lhsEmpty));
            Assert.IsFalse(lhs2.IsProperSupersetOf(lhs1));
            Assert.IsFalse(lhs2.IsProperSupersetOf(lhs3));
            Assert.IsTrue(lhs2.IsProperSupersetOf(hsEmpty));
            Assert.IsFalse(lhs2.IsProperSupersetOf(hs1));
            Assert.IsFalse(lhs2.IsProperSupersetOf(hs3));
            Assert.IsTrue(lhs2.IsProperSupersetOf(setEmpty));
            Assert.IsFalse(lhs2.IsProperSupersetOf(set1));
            Assert.IsFalse(lhs2.IsProperSupersetOf(set3));
            Assert.IsTrue(lhs2.IsProperSupersetOf(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs2.IsProperSupersetOf(GetEnumerator(set1)));
            Assert.IsFalse(lhs2.IsProperSupersetOf(GetEnumerator(set3)));

            Assert.IsTrue(lhs3.IsProperSupersetOf(lhsEmpty));
            Assert.IsFalse(lhs3.IsProperSupersetOf(lhs1));
            Assert.IsTrue(lhs3.IsProperSupersetOf(lhs2));
            Assert.IsTrue(lhs3.IsProperSupersetOf(hsEmpty));
            Assert.IsFalse(lhs3.IsProperSupersetOf(hs1));
            Assert.IsTrue(lhs3.IsProperSupersetOf(hs2));
            Assert.IsTrue(lhs3.IsProperSupersetOf(setEmpty));
            Assert.IsFalse(lhs3.IsProperSupersetOf(set1));
            Assert.IsTrue(lhs3.IsProperSupersetOf(set2));
            Assert.IsTrue(lhs3.IsProperSupersetOf(GetEnumerator(setEmpty)));
            Assert.IsFalse(lhs3.IsProperSupersetOf(GetEnumerator(set1)));
            Assert.IsTrue(lhs3.IsProperSupersetOf(GetEnumerator(set2)));
            #endregion

            #region Remove, Add and Contains
            Assert.IsTrue(lhs1.Remove(7));
            Assert.AreEqual(lhs1.Count, 8);
            Assert.IsTrue(lhs1.SetEquals(lhs2));
            Assert.IsFalse(lhs1.Remove(7));
            Assert.AreEqual(lhs1.Count, 8);

            Assert.IsTrue(lhs1.Add(0));
            Assert.AreEqual(lhs1.Count, 9);
            Assert.IsTrue(lhs1.SetEquals(lhs3));
            Assert.IsFalse(lhs1.Add(0));
            Assert.AreEqual(lhs1.Count, 9);

            Assert.IsTrue(lhs1.Contains(3));
            Assert.IsTrue(lhs1.Contains(0));

            Assert.IsFalse(lhs1.Contains(7));
            Assert.IsFalse(lhs3.Contains(7));

            lhs1.Clear();
            Assert.AreEqual(lhs1.Count, 0);
            Assert.IsTrue(lhs1.SetEquals(lhsEmpty));
            #endregion

            #region ExceptWith
            lhs1 = new LinkedHashSet <int>(set1);
            lhs2 = new LinkedHashSet <int>(set2);
            lhs3 = new LinkedHashSet <int>(set3);

            lhs1.ExceptWith(lhs2);
            Assert.AreEqual(lhs1.Count, 1);
            Assert.IsTrue(lhs1.Contains(7));

            lhs2.ExceptWith(lhs1);
            Assert.IsTrue(lhs2.SetEquals(set2));

            lhs1.ExceptWith(lhs3);
            Assert.AreEqual(lhs1.Count, 1);
            Assert.IsTrue(lhs1.Contains(7));

            lhs3.ExceptWith(lhs2);
            Assert.AreEqual(lhs3.Count, 1);
            Assert.IsTrue(lhs3.Contains(0));
            #endregion

            #region UnionWith
            lhs1 = new LinkedHashSet <int>(set1);
            lhs2 = new LinkedHashSet <int>(set2);
            lhs3 = new LinkedHashSet <int>(set3);

            lhs1.UnionWith(lhs2);
            Assert.IsTrue(lhs1.SetEquals(set1));

            lhs3.UnionWith(lhs2);
            Assert.IsTrue(lhs3.SetEquals(set3));

            lhs3.UnionWith(lhs1);
            Assert.IsTrue(lhs3.Contains(7));
            Assert.IsTrue(lhs3.Contains(0));
            Assert.AreEqual(lhs3.Count, 10);
            #endregion

            #region IntersectWith
            lhs1 = new LinkedHashSet <int>(set1);
            lhs2 = new LinkedHashSet <int>(set2);
            lhs3 = new LinkedHashSet <int>(set3);

            lhs1.IntersectWith(lhs2);
            Assert.IsTrue(lhs1.SetEquals(set2));

            lhs3.IntersectWith(lhs2);
            Assert.IsTrue(lhs3.SetEquals(set2));

            lhs1 = new LinkedHashSet <int>(set1);
            lhs2 = new LinkedHashSet <int>(set2);
            lhs3 = new LinkedHashSet <int>(set3);

            lhs3.IntersectWith(lhs1);
            Assert.IsFalse(lhs3.Contains(7));
            Assert.IsFalse(lhs3.Contains(0));
            Assert.AreEqual(lhs3.Count, 8);
            Assert.IsTrue(lhs3.SetEquals(set2));
            #endregion

            #region SymmetricExceptWith
            lhs1 = new LinkedHashSet <int>(set1);
            lhs2 = new LinkedHashSet <int>(set2);
            lhs3 = new LinkedHashSet <int>(set3);

            lhs1.SymmetricExceptWith(lhs3);
            Assert.AreEqual(lhs1.Count, 2);
            Assert.IsTrue(lhs1.Contains(0));
            Assert.IsTrue(lhs1.Contains(7));

            lhs1.SymmetricExceptWith(lhs2);
            Assert.AreEqual(lhs1.Count, 10);
            #endregion

            LinkedHashSet <int> lhs = new LinkedHashSet <int>();

            for (int i = 0; i < set1.Length; i++)
            {
                lhs.Add(set1[i]);
            }

            List <int> set1a = new List <int>();
            foreach (var i in lhs)
            {
                set1a.Add(i);
            }
            for (int i = 0; i < set1.Length; i++)
            {
                Assert.AreEqual(set1[i], set1a[i]);
            }

            lhs.Remove(7);
            lhs.Add(0);

            set1a.Clear();
            foreach (var i in lhs)
            {
                set1a.Add(i);
            }
            for (int i = 0; i < set3.Length; i++)
            {
                Assert.AreEqual(set3[i], set1a[i]);
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="trits"></param>
        /// <param name="bytes"></param>
        /// <exception cref="ArgumentException"></exception>
        public static void FromTritsToBytes(sbyte[] trits, byte[] bytes)
        {
            if (trits.Length != TritsLength)
            {
                throw new ArgumentException("trits array has invalid size");
            }

            if (bytes.Length != ByteLength)
            {
                throw new ArgumentException("bytes array has invalid size");
            }

            var baseHalf3 = new int[IntLength];

            var setUniqueNumbers = new LinkedHashSet <sbyte>();

            foreach (var x in trits)
            {
                setUniqueNumbers.Add(x);
            }

            if (setUniqueNumbers.Count == 1 && setUniqueNumbers.Contains(-1))
            {
                baseHalf3 = (int[])Half3.Clone();
                BigIntNot(baseHalf3);
                BigIntAdd(baseHalf3, 1);
            }
            else
            {
                var size = IntLength;
                for (var i = TritsLength - 1; i-- > 0;)
                {
                    {
                        // Multiply by radix
                        var sz    = size;
                        var carry = 0;

                        for (var j = 0; j < sz; j++)
                        {
                            // full_mul
                            var v = ToUnsignedLong(baseHalf3[j]) * 3 +
                                    ToUnsignedLong(carry);
                            carry        = (int)((v >> (sizeof(int) * 8)) & 0xFFFFFFFF);
                            baseHalf3[j] = (int)(v & 0xFFFFFFFF);
                        }

                        if (carry > 0)
                        {
                            baseHalf3[sz] = carry;
                            size         += 1;
                        }
                    }

                    var inValue = trits[i] + 1;
                    {
                        // Add
                        var sz = BigIntAdd(baseHalf3, inValue);
                        if (sz > size)
                        {
                            size = sz;
                        }
                    }
                }

                if (Sum(baseHalf3) != 0)
                {
                    if (BigIntCmp(Half3, baseHalf3) <= 0)
                    {
                        // base is >= HALF_3.
                        // just do base - HALF_3
                        baseHalf3 = BigIntSub(baseHalf3, Half3);
                    }
                    else
                    {
                        // we don't have a wrapping sub.
                        // so we need to be clever.
                        baseHalf3 = BigIntSub(Half3, baseHalf3);
                        BigIntNot(baseHalf3);
                        BigIntAdd(baseHalf3, 1);
                    }
                }
            }


            // output
            for (var i = 0; i < IntLength; i++)
            {
                bytes[i * 4 + 0] = (byte)((baseHalf3[IntLength - 1 - i] & 0xFF000000) >> 24);
                bytes[i * 4 + 1] = (byte)((baseHalf3[IntLength - 1 - i] & 0x00FF0000) >> 16);
                bytes[i * 4 + 2] = (byte)((baseHalf3[IntLength - 1 - i] & 0x0000FF00) >> 8);
                bytes[i * 4 + 3] = (byte)((baseHalf3[IntLength - 1 - i] & 0x000000FF) >> 0);
            }
        }
예제 #18
0
        public static PatternStreamSpecCompiled CompilePatternWTags(
            PatternStreamSpecRaw streamSpecRaw,
            ISet<string> eventTypeReferences,
            bool isInsertInto,
            MatchEventSpec tags,
            ISet<string> priorAllTags,
            bool isJoin,
            bool isContextDeclaration,
            bool isOnTrigger,
            int streamNum,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            // validate
            if ((streamSpecRaw.IsSuppressSameEventMatches || streamSpecRaw.IsDiscardPartialsOnMatch) &&
                (isJoin || isContextDeclaration || isOnTrigger)) {
                throw new ExprValidationException(
                    "Discard-partials and suppress-matches is not supported in a joins, context declaration and on-action");
            }

            if (tags == null) {
                tags = new MatchEventSpec();
            }

            var nodeStack = new Stack<EvalForgeNode>();

            // detemine ordered tags
            var allTagNamesOrdered = new LinkedHashSet<string>();
            var filterFactoryNodes = EvalNodeUtil.RecursiveGetChildNodes(
                streamSpecRaw.EvalForgeNode,
                FilterForFilterFactoryNodes.INSTANCE);
            if (priorAllTags != null) {
                allTagNamesOrdered.AddAll(priorAllTags);
            }

            foreach (var filterNode in filterFactoryNodes) {
                var forge = (EvalFilterForgeNode) filterNode;
                int tagNumber;
                if (forge.EventAsName != null) {
                    if (!allTagNamesOrdered.Contains(forge.EventAsName)) {
                        allTagNamesOrdered.Add(forge.EventAsName);
                        tagNumber = allTagNamesOrdered.Count - 1;
                    }
                    else {
                        tagNumber = FindTagNumber(forge.EventAsName, allTagNamesOrdered);
                    }

                    forge.EventAsTagNumber = tagNumber;
                }
            }

            // construct root : assigns factory node ids
            var top = streamSpecRaw.EvalForgeNode;
            var root = new EvalRootForgeNode(top, statementRawInfo.Annotations);
            RecursiveCompile(
                top,
                eventTypeReferences,
                isInsertInto,
                tags,
                nodeStack,
                allTagNamesOrdered,
                streamNum,
                statementRawInfo,
                services);

            var hook = (PatternCompileHook) ImportUtil.GetAnnotationHook(
                statementRawInfo.Annotations,
                HookType.INTERNAL_PATTERNCOMPILE,
                typeof(PatternCompileHook),
                services.ImportServiceCompileTime);
            if (hook != null) {
                hook.Pattern(root);
            }

            return new PatternStreamSpecCompiled(
                root,
                tags.TaggedEventTypes,
                tags.ArrayEventTypes,
                allTagNamesOrdered,
                streamSpecRaw.ViewSpecs,
                streamSpecRaw.OptionalStreamName,
                streamSpecRaw.Options,
                streamSpecRaw.IsSuppressSameEventMatches,
                streamSpecRaw.IsDiscardPartialsOnMatch);
        }
예제 #19
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="viewChain">views</param>
        /// <param name="matchRecognizeSpec">specification</param>
        /// <param name="agentInstanceContext">The agent instance context.</param>
        /// <param name="isUnbound">true for unbound stream</param>
        /// <param name="annotations">annotations</param>
        /// <exception cref="ExprValidationException">
        /// Variable ' + defineItem.Identifier + ' has already been defined
        /// or
        /// An aggregate function may not appear in a DEFINE clause
        /// or
        /// Failed to validate condition expression for variable ' + defineItem.Identifier + ':  + ex.Message
        /// or
        /// Aggregation functions in the measure-clause must only refer to properties of exactly one group variable returning multiple events
        /// or
        /// Aggregation functions in the measure-clause must refer to one or more properties of exactly one group variable returning multiple events
        /// or
        /// The measures clause requires that each expression utilizes the AS keyword to assign a column name
        /// </exception>
        /// <throws>ExprValidationException if validation fails</throws>
        public EventRowRegexNFAViewFactory(
            ViewFactoryChain viewChain,
            MatchRecognizeSpec matchRecognizeSpec,
            AgentInstanceContext agentInstanceContext,
            bool isUnbound,
            Attribute[] annotations,
            ConfigurationEngineDefaults.MatchRecognizeConfig matchRecognizeConfig)
        {
            var parentViewType = viewChain.EventType;

            _matchRecognizeSpec   = matchRecognizeSpec;
            _isUnbound            = isUnbound;
            _isIterateOnly        = HintEnum.ITERATE_ONLY.GetHint(annotations) != null;
            _matchRecognizeConfig = matchRecognizeConfig;

            var statementContext = agentInstanceContext.StatementContext;

            // Expand repeats and permutations
            _expandedPatternNode = RegexPatternExpandUtil.Expand(matchRecognizeSpec.Pattern);

            // Determine single-row and multiple-row variables
            _variablesSingle = new LinkedHashSet <string>();
            ISet <string> variablesMultiple = new LinkedHashSet <string>();

            EventRowRegexHelper.RecursiveInspectVariables(_expandedPatternNode, false, _variablesSingle, variablesMultiple);

            // each variable gets associated with a stream number (multiple-row variables as well to hold the current event for the expression).
            var streamNum = 0;

            _variableStreams = new LinkedHashMap <string, Pair <int, bool> >();
            foreach (var variableSingle in _variablesSingle)
            {
                _variableStreams.Put(variableSingle, new Pair <int, bool>(streamNum, false));
                streamNum++;
            }
            foreach (var variableMultiple in variablesMultiple)
            {
                _variableStreams.Put(variableMultiple, new Pair <int, bool>(streamNum, true));
                streamNum++;
            }

            // mapping of stream to variable
            _streamVariables = new SortedDictionary <int, string>();
            foreach (var entry in _variableStreams)
            {
                _streamVariables.Put(entry.Value.First, entry.Key);
            }

            // determine visibility rules
            var visibility = EventRowRegexHelper.DetermineVisibility(_expandedPatternNode);

            // assemble all single-row variables for expression validation
            var allStreamNames = new string[_variableStreams.Count];
            var allTypes       = new EventType[_variableStreams.Count];

            streamNum = 0;
            foreach (var variableSingle in _variablesSingle)
            {
                allStreamNames[streamNum] = variableSingle;
                allTypes[streamNum]       = parentViewType;
                streamNum++;
            }
            foreach (var variableMultiple in variablesMultiple)
            {
                allStreamNames[streamNum] = variableMultiple;
                allTypes[streamNum]       = parentViewType;
                streamNum++;
            }

            // determine type service for use with DEFINE
            // validate each DEFINE clause expression
            ISet <string>             definedVariables = new HashSet <string>();
            IList <ExprAggregateNode> aggregateNodes   = new List <ExprAggregateNode>();
            var exprEvaluatorContext = new ExprEvaluatorContextStatement(statementContext, false);

            _isExprRequiresMultimatchState = new bool[_variableStreams.Count];

            for (var defineIndex = 0; defineIndex < matchRecognizeSpec.Defines.Count; defineIndex++)
            {
                var defineItem = matchRecognizeSpec.Defines[defineIndex];
                if (definedVariables.Contains(defineItem.Identifier))
                {
                    throw new ExprValidationException("Variable '" + defineItem.Identifier + "' has already been defined");
                }
                definedVariables.Add(defineItem.Identifier);

                // stream-type visibilities handled here
                var typeServiceDefines = EventRowRegexNFAViewFactoryHelper.BuildDefineStreamTypeServiceDefine(statementContext, _variableStreams, defineItem, visibility, parentViewType);

                var exprNodeResult    = HandlePreviousFunctions(defineItem.Expression);
                var validationContext = new ExprValidationContext(
                    typeServiceDefines,
                    statementContext.EngineImportService,
                    statementContext.StatementExtensionServicesContext, null,
                    statementContext.SchedulingService,
                    statementContext.VariableService,
                    statementContext.TableService, exprEvaluatorContext,
                    statementContext.EventAdapterService,
                    statementContext.StatementName,
                    statementContext.StatementId,
                    statementContext.Annotations,
                    statementContext.ContextDescriptor,
                    statementContext.ScriptingService,
                    true, false, true, false, null, false);

                ExprNode validated;
                try {
                    // validate
                    validated = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.MATCHRECOGDEFINE, exprNodeResult, validationContext);

                    // check aggregates
                    defineItem.Expression = validated;
                    ExprAggregateNodeUtil.GetAggregatesBottomUp(validated, aggregateNodes);
                    if (!aggregateNodes.IsEmpty())
                    {
                        throw new ExprValidationException("An aggregate function may not appear in a DEFINE clause");
                    }
                }
                catch (ExprValidationException ex) {
                    throw new ExprValidationException("Failed to validate condition expression for variable '" + defineItem.Identifier + "': " + ex.Message, ex);
                }

                // determine access to event properties from multi-matches
                var visitor = new ExprNodeStreamRequiredVisitor();
                validated.Accept(visitor);
                var streamsRequired = visitor.StreamsRequired;
                foreach (var streamRequired in streamsRequired)
                {
                    if (streamRequired >= _variableStreams.Count)
                    {
                        var streamNumIdent = _variableStreams.Get(defineItem.Identifier).First;
                        _isExprRequiresMultimatchState[streamNumIdent] = true;
                        break;
                    }
                }
            }
            _isDefineAsksMultimatches  = CollectionUtil.IsAnySet(_isExprRequiresMultimatchState);
            _defineMultimatchEventBean = _isDefineAsksMultimatches ? EventRowRegexNFAViewFactoryHelper.GetDefineMultimatchBean(statementContext, _variableStreams, parentViewType) : null;

            // assign "prev" node indexes
            // Since an expression such as "prior(2, price), prior(8, price)" translates into {2, 8} the relative index is {0, 1}.
            // Map the expression-supplied index to a relative index
            var countPrev = 0;

            foreach (var entry in _callbacksPerIndex)
            {
                foreach (var callback in entry.Value)
                {
                    callback.AssignedIndex = countPrev;
                }
                countPrev++;
            }

            // determine type service for use with MEASURE
            IDictionary <string, object> measureTypeDef = new LinkedHashMap <string, object>();

            foreach (var variableSingle in _variablesSingle)
            {
                measureTypeDef.Put(variableSingle, parentViewType);
            }
            foreach (var variableMultiple in variablesMultiple)
            {
                measureTypeDef.Put(variableMultiple, new EventType[] { parentViewType });
            }
            var outputEventTypeName = statementContext.StatementId + "_rowrecog";

            _compositeEventType = (ObjectArrayEventType)statementContext.EventAdapterService.CreateAnonymousObjectArrayType(outputEventTypeName, measureTypeDef);
            StreamTypeService typeServiceMeasure = new StreamTypeServiceImpl(_compositeEventType, "MATCH_RECOGNIZE", true, statementContext.EngineURI);

            // find MEASURE clause aggregations
            var measureReferencesMultivar = false;
            IList <ExprAggregateNode> measureAggregateExprNodes = new List <ExprAggregateNode>();

            foreach (var measureItem in matchRecognizeSpec.Measures)
            {
                ExprAggregateNodeUtil.GetAggregatesBottomUp(measureItem.Expr, measureAggregateExprNodes);
            }
            if (!measureAggregateExprNodes.IsEmpty())
            {
                var isIStreamOnly = new bool[allStreamNames.Length];
                CompatExtensions.Fill(isIStreamOnly, true);
                var typeServiceAggregateMeasure  = new StreamTypeServiceImpl(allTypes, allStreamNames, isIStreamOnly, statementContext.EngineURI, false);
                var measureExprAggNodesPerStream = new Dictionary <int, IList <ExprAggregateNode> >();

                foreach (var aggregateNode in measureAggregateExprNodes)
                {
                    // validate absence of group-by
                    aggregateNode.ValidatePositionals();
                    if (aggregateNode.OptionalLocalGroupBy != null)
                    {
                        throw new ExprValidationException("Match-recognize does not allow aggregation functions to specify a group-by");
                    }

                    // validate node and params
                    var count   = 0;
                    var visitor = new ExprNodeIdentifierVisitor(true);

                    var validationContext = new ExprValidationContext(
                        typeServiceAggregateMeasure,
                        statementContext.EngineImportService,
                        statementContext.StatementExtensionServicesContext, null,
                        statementContext.SchedulingService,
                        statementContext.VariableService,
                        statementContext.TableService,
                        exprEvaluatorContext,
                        statementContext.EventAdapterService,
                        statementContext.StatementName,
                        statementContext.StatementId,
                        statementContext.Annotations,
                        statementContext.ContextDescriptor,
                        statementContext.ScriptingService,
                        false, false, true, false, null, false);
                    for (int ii = 0; ii < aggregateNode.ChildNodes.Count; ii++)
                    {
                        var child     = aggregateNode.ChildNodes[ii];
                        var validated = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.MATCHRECOGMEASURE, child, validationContext);
                        validated.Accept(visitor);
                        aggregateNode.SetChildNode(count++, new ExprNodeValidated(validated));
                    }
                    validationContext = new ExprValidationContext(
                        typeServiceMeasure,
                        statementContext.EngineImportService,
                        statementContext.StatementExtensionServicesContext, null,
                        statementContext.SchedulingService,
                        statementContext.VariableService,
                        statementContext.TableService,
                        exprEvaluatorContext,
                        statementContext.EventAdapterService,
                        statementContext.StatementName,
                        statementContext.StatementId,
                        statementContext.Annotations,
                        statementContext.ContextDescriptor,
                        statementContext.ScriptingService,
                        false, false, true, false, null, false);
                    aggregateNode.Validate(validationContext);

                    // verify properties used within the aggregation
                    var aggregatedStreams = new HashSet <int>();
                    foreach (var pair in visitor.ExprProperties)
                    {
                        aggregatedStreams.Add(pair.First);
                    }

                    int?multipleVarStream = null;
                    foreach (int streamNumAggregated in aggregatedStreams)
                    {
                        var variable = _streamVariables.Get(streamNumAggregated);
                        if (variablesMultiple.Contains(variable))
                        {
                            measureReferencesMultivar = true;
                            if (multipleVarStream == null)
                            {
                                multipleVarStream = streamNumAggregated;
                                continue;
                            }
                            throw new ExprValidationException("Aggregation functions in the measure-clause must only refer to properties of exactly one group variable returning multiple events");
                        }
                    }

                    if (multipleVarStream == null)
                    {
                        throw new ExprValidationException("Aggregation functions in the measure-clause must refer to one or more properties of exactly one group variable returning multiple events");
                    }

                    var aggNodesForStream = measureExprAggNodesPerStream.Get(multipleVarStream.Value);
                    if (aggNodesForStream == null)
                    {
                        aggNodesForStream = new List <ExprAggregateNode>();
                        measureExprAggNodesPerStream.Put(multipleVarStream.Value, aggNodesForStream);
                    }
                    aggNodesForStream.Add(aggregateNode);
                }

                var factoryDesc = AggregationServiceFactoryFactory.GetServiceMatchRecognize(_streamVariables.Count, measureExprAggNodesPerStream, typeServiceAggregateMeasure.EventTypes);
                _aggregationService     = factoryDesc.AggregationServiceFactory.MakeService(agentInstanceContext);
                _aggregationExpressions = factoryDesc.Expressions;
            }
            else
            {
                _aggregationService     = null;
                _aggregationExpressions = Collections.GetEmptyList <AggregationServiceAggExpressionDesc>();
            }

            // validate each MEASURE clause expression
            IDictionary <string, object> rowTypeDef = new LinkedHashMap <string, object>();
            var streamRefVisitor = new ExprNodeStreamUseCollectVisitor();

            foreach (var measureItem in matchRecognizeSpec.Measures)
            {
                if (measureItem.Name == null)
                {
                    throw new ExprValidationException("The measures clause requires that each expression utilizes the AS keyword to assign a column name");
                }
                var validated = ValidateMeasureClause(measureItem.Expr, typeServiceMeasure, variablesMultiple, _variablesSingle, statementContext);
                measureItem.Expr = validated;
                rowTypeDef.Put(measureItem.Name, validated.ExprEvaluator.ReturnType);
                validated.Accept(streamRefVisitor);
            }

            // Determine if any of the multi-var streams are referenced in the measures (non-aggregated only)
            foreach (var @ref in streamRefVisitor.Referenced)
            {
                var rootPropName = @ref.RootPropertyNameIfAny;
                if (rootPropName != null)
                {
                    if (variablesMultiple.Contains(rootPropName))
                    {
                        measureReferencesMultivar = true;
                        break;
                    }
                }

                var streamRequired = @ref.StreamReferencedIfAny;
                if (streamRequired != null)
                {
                    var streamVariable = _streamVariables.Get(streamRequired.Value);
                    if (streamVariable != null)
                    {
                        var def = _variableStreams.Get(streamVariable);
                        if (def != null && def.Second)
                        {
                            measureReferencesMultivar = true;
                            break;
                        }
                    }
                }
            }
            _isCollectMultimatches = measureReferencesMultivar || _isDefineAsksMultimatches;

            // create rowevent type
            var rowEventTypeName = statementContext.StatementId + "_rowrecogrow";

            _rowEventType = statementContext.EventAdapterService.CreateAnonymousMapType(rowEventTypeName, rowTypeDef, true);

            // validate partition-by expressions, if any
            if (!matchRecognizeSpec.PartitionByExpressions.IsEmpty())
            {
                var typeServicePartition = new StreamTypeServiceImpl(parentViewType, "MATCH_RECOGNIZE_PARTITION", true, statementContext.EngineURI);
                var validated            = new List <ExprNode>();
                var validationContext    = new ExprValidationContext(
                    typeServicePartition,
                    statementContext.EngineImportService,
                    statementContext.StatementExtensionServicesContext, null,
                    statementContext.SchedulingService, statementContext.VariableService, statementContext.TableService,
                    exprEvaluatorContext, statementContext.EventAdapterService, statementContext.StatementName,
                    statementContext.StatementId, statementContext.Annotations, statementContext.ContextDescriptor,
                    statementContext.ScriptingService,
                    false, false, true, false, null, false);
                foreach (var partitionExpr in matchRecognizeSpec.PartitionByExpressions)
                {
                    validated.Add(ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.MATCHRECOGPARTITION, partitionExpr, validationContext));
                }
                matchRecognizeSpec.PartitionByExpressions = validated;
            }

            // validate interval if present
            if (matchRecognizeSpec.Interval != null)
            {
                var validationContext =
                    new ExprValidationContext(
                        new StreamTypeServiceImpl(statementContext.EngineURI, false),
                        statementContext.EngineImportService,
                        statementContext.StatementExtensionServicesContext, null,
                        statementContext.SchedulingService,
                        statementContext.VariableService, statementContext.TableService, exprEvaluatorContext,
                        statementContext.EventAdapterService, statementContext.StatementName, statementContext.StatementId,
                        statementContext.Annotations, statementContext.ContextDescriptor, statementContext.ScriptingService,
                        false, false, true, false, null, false);
                matchRecognizeSpec.Interval.Validate(validationContext);
            }
        }
예제 #20
0
        public static RowRecogPlan ValidateAndPlan(
            IContainer container,
            EventType parentEventType,
            bool unbound,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var statementRawInfo = @base.StatementRawInfo;
            var matchRecognizeSpec = @base.StatementSpec.Raw.MatchRecognizeSpec;
            var annotations = statementRawInfo.Annotations;
            var iterateOnly = HintEnum.ITERATE_ONLY.GetHint(annotations) != null;
            var additionalForgeables = new List<StmtClassForgeableFactory>();

            // Expanded pattern already there
            RowRecogExprNode expandedPatternNode = matchRecognizeSpec.Pattern;

            // Determine single-row and multiple-row variables
            var variablesSingle = new LinkedHashSet<string>();
            var variablesMultiple = new LinkedHashSet<string>();
            RowRecogHelper.RecursiveInspectVariables(expandedPatternNode, false, variablesSingle, variablesMultiple);

            // each variable gets associated with a stream number (multiple-row variables as well to hold the current event for the expression).
            var streamNum = 0;
            var variableStreams = new LinkedHashMap<string, Pair<int, bool>>();
            foreach (var variableSingle in variablesSingle) {
                variableStreams.Put(variableSingle, new Pair<int, bool>(streamNum, false));
                streamNum++;
            }

            foreach (var variableMultiple in variablesMultiple) {
                variableStreams.Put(variableMultiple, new Pair<int, bool>(streamNum, true));
                streamNum++;
            }

            // mapping of stream to variable
            var streamVariables = new OrderedListDictionary<int, string>();
            foreach (var entry in variableStreams) {
                streamVariables.Put(entry.Value.First, entry.Key);
            }

            // determine visibility rules
            var visibility = RowRecogHelper.DetermineVisibility(expandedPatternNode);

            // assemble all single-row variables for expression validation
            var allStreamNames = new string[variableStreams.Count];
            var allTypes = new EventType[variableStreams.Count];

            streamNum = 0;
            foreach (var variableSingle in variablesSingle) {
                allStreamNames[streamNum] = variableSingle;
                allTypes[streamNum] = parentEventType;
                streamNum++;
            }

            foreach (var variableMultiple in variablesMultiple) {
                allStreamNames[streamNum] = variableMultiple;
                allTypes[streamNum] = parentEventType;
                streamNum++;
            }

            // determine type service for use with DEFINE
            // validate each DEFINE clause expression
            ISet<string> definedVariables = new HashSet<string>();
            IList<ExprAggregateNode> aggregateNodes = new List<ExprAggregateNode>();
            var isExprRequiresMultimatchState = new bool[variableStreams.Count];
            var previousNodes = new OrderedListDictionary<int, IList<ExprPreviousMatchRecognizeNode>>();

            for (var defineIndex = 0; defineIndex < matchRecognizeSpec.Defines.Count; defineIndex++) {
                MatchRecognizeDefineItem defineItem = matchRecognizeSpec.Defines[defineIndex];
                if (definedVariables.Contains(defineItem.Identifier)) {
                    throw new ExprValidationException(
                        "Variable '" + defineItem.Identifier + "' has already been defined");
                }

                definedVariables.Add(defineItem.Identifier);

                // stream-type visibilities handled here
                var typeServiceDefines = BuildDefineStreamTypeServiceDefine(
                    defineIndex,
                    variableStreams,
                    defineItem,
                    visibility,
                    parentEventType,
                    statementRawInfo,
                    services);

                var exprNodeResult = HandlePreviousFunctions(defineItem.Expression, previousNodes);
                var validationContext = new ExprValidationContextBuilder(typeServiceDefines, statementRawInfo, services)
                    .WithAllowBindingConsumption(true)
                    .WithDisablePropertyExpressionEventCollCache(true)
                    .Build();

                ExprNode validated;
                try {
                    // validate
                    validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                        ExprNodeOrigin.MATCHRECOGDEFINE,
                        exprNodeResult,
                        validationContext);

                    // check aggregates
                    defineItem.Expression = validated;
                    ExprAggregateNodeUtil.GetAggregatesBottomUp(validated, aggregateNodes);
                    if (!aggregateNodes.IsEmpty()) {
                        throw new ExprValidationException("An aggregate function may not appear in a DEFINE clause");
                    }
                }
                catch (ExprValidationException ex) {
                    throw new ExprValidationException(
                        "Failed to validate condition expression for variable '" +
                        defineItem.Identifier +
                        "': " +
                        ex.Message,
                        ex);
                }

                // determine access to event properties from multi-matches
                var visitor = new ExprNodeStreamRequiredVisitor();
                validated.Accept(visitor);
                var streamsRequired = visitor.StreamsRequired;
                foreach (var streamRequired in streamsRequired) {
                    if (streamRequired >= variableStreams.Count) {
                        var streamNumIdent = variableStreams.Get(defineItem.Identifier).First;
                        isExprRequiresMultimatchState[streamNumIdent] = true;
                        break;
                    }
                }
            }

            var defineAsksMultimatches = CollectionUtil.IsAnySet(isExprRequiresMultimatchState);

            // determine type service for use with MEASURE
            IDictionary<string, object> measureTypeDef = new LinkedHashMap<string, object>();
            foreach (var variableSingle in variablesSingle) {
                measureTypeDef.Put(variableSingle, parentEventType);
            }

            foreach (var variableMultiple in variablesMultiple) {
                measureTypeDef.Put(variableMultiple, new[] {parentEventType});
            }

            var compositeTypeName = services.EventTypeNameGeneratorStatement.AnonymousRowrecogCompositeName;
            var compositeTypeMetadata = new EventTypeMetadata(
                compositeTypeName,
                @base.ModuleName,
                EventTypeTypeClass.MATCHRECOGDERIVED,
                EventTypeApplicationType.OBJECTARR,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var compositeEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                compositeTypeMetadata,
                measureTypeDef,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(compositeEventType);
            StreamTypeService compositeTypeServiceMeasure =
                new StreamTypeServiceImpl(compositeEventType, "MATCH_RECOGNIZE", true);

            // find MEASURE clause aggregations
            var measureReferencesMultivar = false;
            IList<ExprAggregateNode> measureAggregateExprNodes = new List<ExprAggregateNode>();
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                ExprAggregateNodeUtil.GetAggregatesBottomUp(measureItem.Expr, measureAggregateExprNodes);
            }

            AggregationServiceForgeDesc[] aggregationServices = null;
            if (!measureAggregateExprNodes.IsEmpty()) {
                aggregationServices = PlanAggregations(
                    measureAggregateExprNodes,
                    compositeTypeServiceMeasure,
                    allStreamNames,
                    allTypes,
                    streamVariables,
                    variablesMultiple,
                    @base,
                    services);
                foreach (AggregationServiceForgeDesc svc in aggregationServices) {
                    if (svc != null) {
                        additionalForgeables.AddAll(svc.AdditionalForgeables);
                    }
                }
            }

            // validate each MEASURE clause expression
            IDictionary<string, object> rowTypeDef = new LinkedHashMap<string, object>();
            var streamRefVisitor = new ExprNodeStreamUseCollectVisitor();
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                if (measureItem.Name == null) {
                    throw new ExprValidationException(
                        "The measures clause requires that each expression utilizes the AS keyword to assign a column name");
                }

                var validated = ValidateMeasureClause(
                    measureItem.Expr,
                    compositeTypeServiceMeasure,
                    variablesMultiple,
                    variablesSingle,
                    statementRawInfo,
                    services);
                measureItem.Expr = validated;
                rowTypeDef.Put(measureItem.Name, validated.Forge.EvaluationType);
                validated.Accept(streamRefVisitor);
            }

            // Determine if any of the multi-var streams are referenced in the measures (non-aggregated only)
            foreach (var @ref in streamRefVisitor.Referenced) {
                var rootPropName = @ref.RootPropertyNameIfAny;
                if (rootPropName != null) {
                    if (variablesMultiple.Contains(rootPropName)) {
                        measureReferencesMultivar = true;
                        break;
                    }
                }

                var streamRequired = @ref.StreamReferencedIfAny;
                if (streamRequired != null) {
                    var streamVariable = streamVariables.Get(streamRequired.Value);
                    if (streamVariable != null) {
                        var def = variableStreams.Get(streamVariable);
                        if (def != null && def.Second) {
                            measureReferencesMultivar = true;
                            break;
                        }
                    }
                }
            }

            var collectMultimatches = measureReferencesMultivar || defineAsksMultimatches;

            // create rowevent type
            var rowTypeName = services.EventTypeNameGeneratorStatement.AnonymousRowrecogRowName;
            var rowTypeMetadata = new EventTypeMetadata(
                rowTypeName,
                @base.ModuleName,
                EventTypeTypeClass.MATCHRECOGDERIVED,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var rowEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                rowTypeMetadata,
                rowTypeDef,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(rowEventType);

            // validate partition-by expressions, if any
            ExprNode[] partitionBy;
            MultiKeyClassRef partitionMultiKey;
            if (!matchRecognizeSpec.PartitionByExpressions.IsEmpty()) {
                StreamTypeService typeServicePartition = new StreamTypeServiceImpl(
                    parentEventType,
                    "MATCH_RECOGNIZE_PARTITION",
                    true);
                IList<ExprNode> validated = new List<ExprNode>();
                var validationContext =
                    new ExprValidationContextBuilder(typeServicePartition, statementRawInfo, services)
                        .WithAllowBindingConsumption(true)
                        .Build();
                foreach (var partitionExpr in matchRecognizeSpec.PartitionByExpressions) {
                    validated.Add(
                        ExprNodeUtilityValidate.GetValidatedSubtree(
                            ExprNodeOrigin.MATCHRECOGPARTITION,
                            partitionExpr,
                            validationContext));
                }

                matchRecognizeSpec.PartitionByExpressions = validated;
                partitionBy = ExprNodeUtilityQuery.ToArray(validated);
                MultiKeyPlan multiKeyPlan = MultiKeyPlanner.PlanMultiKey(partitionBy, false, @base.StatementRawInfo, services.SerdeResolver);
                partitionMultiKey = multiKeyPlan.ClassRef;
                additionalForgeables.AddAll(multiKeyPlan.MultiKeyForgeables);
            }
            else {
                partitionBy = null;
                partitionMultiKey = null;
            }

            // validate interval if present
            if (matchRecognizeSpec.Interval != null) {
                var validationContext =
                    new ExprValidationContextBuilder(new StreamTypeServiceImpl(false), statementRawInfo, services)
                        .WithAllowBindingConsumption(true)
                        .Build();
                var validated = (ExprTimePeriod) ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.MATCHRECOGINTERVAL,
                    matchRecognizeSpec.Interval.TimePeriodExpr,
                    validationContext);
                matchRecognizeSpec.Interval.TimePeriodExpr = validated;
            }

            // compile variable definition expressions
            IDictionary<string, ExprNode> variableDefinitions = new Dictionary<string, ExprNode>();
            foreach (var defineItem in matchRecognizeSpec.Defines) {
                variableDefinitions.Put(defineItem.Identifier, defineItem.Expression);
            }

            // create evaluators
            var columnNames = new string[matchRecognizeSpec.Measures.Count];
            var columnForges = new ExprNode[matchRecognizeSpec.Measures.Count];
            var count = 0;
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                columnNames[count] = measureItem.Name;
                columnForges[count] = measureItem.Expr;
                count++;
            }

            // build states
            var strand = RowRecogHelper.BuildStartStates(
                expandedPatternNode,
                variableDefinitions,
                variableStreams,
                isExprRequiresMultimatchState);
            var startStates = strand.StartStates.ToArray();
            RowRecogNFAStateForge[] allStates = strand.AllStates.ToArray();

            if (Log.IsInfoEnabled) {
                Log.Info("NFA tree:\n" + RowRecogNFAViewUtil.Print(startStates));
            }

            // determine names of multimatching variables
            string[] multimatchVariablesArray;
            int[] multimatchStreamNumToVariable;
            int[] multimatchVariableToStreamNum;
            if (variablesSingle.Count == variableStreams.Count) {
                multimatchVariablesArray = new string[0];
                multimatchStreamNumToVariable = new int[0];
                multimatchVariableToStreamNum = new int[0];
            }
            else {
                multimatchVariablesArray = new string[variableStreams.Count - variablesSingle.Count];
                multimatchVariableToStreamNum = new int[multimatchVariablesArray.Length];
                multimatchStreamNumToVariable = new int[variableStreams.Count];
                CompatExtensions.Fill(multimatchStreamNumToVariable, -1);
                count = 0;
                foreach (var entry in variableStreams) {
                    if (entry.Value.Second) {
                        var index = count;
                        multimatchVariablesArray[index] = entry.Key;
                        multimatchVariableToStreamNum[index] = entry.Value.First;
                        multimatchStreamNumToVariable[entry.Value.First] = index;
                        count++;
                    }
                }
            }

            var numEventsEventsPerStreamDefine =
                defineAsksMultimatches ? variableStreams.Count + 1 : variableStreams.Count;

            // determine interval-or-terminated
            var orTerminated = matchRecognizeSpec.Interval != null && matchRecognizeSpec.Interval.IsOrTerminated;
            TimePeriodComputeForge intervalCompute = null;
            if (matchRecognizeSpec.Interval != null) {
                intervalCompute = matchRecognizeSpec.Interval.TimePeriodExpr.TimePeriodComputeForge;
            }

            EventType multimatchEventType = null;
            if (defineAsksMultimatches) {
                multimatchEventType = GetDefineMultimatchEventType(variableStreams, parentEventType, @base, services);
            }

            // determine previous-access indexes and assign "prev" node indexes
            // Since an expression such as "prior(2, price), prior(8, price)" translates into {2, 8} the relative index is {0, 1}.
            // Map the expression-supplied index to a relative index
            int[] previousRandomAccessIndexes = null;
            if (!previousNodes.IsEmpty()) {
                previousRandomAccessIndexes = new int[previousNodes.Count];
                var countPrev = 0;
                foreach (var entry in previousNodes) {
                    previousRandomAccessIndexes[countPrev] = entry.Key;
                    foreach (var callback in entry.Value) {
                        callback.AssignedIndex = countPrev;
                    }

                    countPrev++;
                }
            }

            RowRecogDescForge forge = new RowRecogDescForge(
                parentEventType,
                rowEventType,
                compositeEventType,
                multimatchEventType,
                multimatchStreamNumToVariable,
                multimatchVariableToStreamNum,
                partitionBy,
                partitionMultiKey,
                variableStreams,
                matchRecognizeSpec.Interval != null,
                iterateOnly,
                unbound,
                orTerminated,
                collectMultimatches,
                defineAsksMultimatches,
                numEventsEventsPerStreamDefine,
                multimatchVariablesArray,
                startStates,
                allStates,
                matchRecognizeSpec.IsAllMatches,
                matchRecognizeSpec.Skip.Skip,
                columnForges,
                columnNames,
                intervalCompute,
                previousRandomAccessIndexes,
                aggregationServices);
            
            return new RowRecogPlan(forge, additionalForgeables);
        }
예제 #21
0
        private static List <IAtomContainer> MakeCut(IBond cut, IAtomContainer mol, Dictionary <IAtom, int> idx, int[][] adjlist)
        {
            var beg = cut.Begin;
            var end = cut.End;

            var bvisit = new LinkedHashSet <IAtom>();
            var evisit = new LinkedHashSet <IAtom>();
            var queue  = new ArrayDeque <IAtom>();

            bvisit.Add(beg);
            evisit.Add(end);

            queue.Add(beg);
            bvisit.Add(end); // stop visits
            while (queue.Any())
            {
                var atom = queue.Poll();
                bvisit.Add(atom);
                foreach (var w in adjlist[idx[atom]])
                {
                    var nbr = mol.Atoms[w];
                    if (!bvisit.Contains(nbr))
                    {
                        queue.Add(nbr);
                    }
                }
            }
            bvisit.Remove(end);

            queue.Add(end);
            evisit.Add(beg); // stop visits
            while (queue.Any())
            {
                var atom = queue.Poll();
                evisit.Add(atom);
                foreach (var w in adjlist[idx[atom]])
                {
                    var nbr = mol.Atoms[w];
                    if (!evisit.Contains(nbr))
                    {
                        queue.Add(nbr);
                    }
                }
            }
            evisit.Remove(beg);

            var bldr  = mol.Builder;
            var bfrag = bldr.NewAtomContainer();
            var efrag = bldr.NewAtomContainer();

            int diff = bvisit.Count - evisit.Count;

            if (diff < -10)
            {
                evisit.Clear();
            }
            else if (diff > 10)
            {
                bvisit.Clear();
            }

            if (bvisit.Any())
            {
                bfrag.Atoms.Add(bldr.NewPseudoAtom());
                foreach (var atom in bvisit)
                {
                    bfrag.Atoms.Add(atom);
                }
                bfrag.AddBond(bfrag.Atoms[0], bfrag.Atoms[1], cut.Order);
                bfrag.Bonds[0].SetProperty(PropertyName_CutBond, cut);
            }

            if (evisit.Any())
            {
                efrag.Atoms.Add(bldr.NewPseudoAtom());
                foreach (var atom in evisit)
                {
                    efrag.Atoms.Add(atom);
                }
                efrag.AddBond(efrag.Atoms[0], efrag.Atoms[1], cut.Order);
                efrag.Bonds[0].SetProperty(PropertyName_CutBond, cut);
            }

            foreach (var bond in mol.Bonds)
            {
                var a1 = bond.Begin;
                var a2 = bond.End;
                if (bvisit.Contains(a1) && bvisit.Contains(a2))
                {
                    bfrag.Bonds.Add(bond);
                }
                else if (evisit.Contains(a1) && evisit.Contains(a2))
                {
                    efrag.Bonds.Add(bond);
                }
            }

            var res = new List <IAtomContainer>();

            if (!bfrag.IsEmpty())
            {
                res.Add(bfrag);
            }
            if (!efrag.IsEmpty())
            {
                res.Add(efrag);
            }
            return(res);
        }
예제 #22
0
        public VariantPropertyDesc ResolveProperty(
            string propertyName,
            EventType[] variants)
        {
            var existsInAll = true;
            Type commonType = null;
            var mustCoerce = false;
            for (var i = 0; i < variants.Length; i++) {
                var type = variants[i].GetPropertyType(propertyName).GetBoxedType();
                if (type == null) {
                    existsInAll = false;
                    continue;
                }

                if (commonType == null) {
                    commonType = type;
                    continue;
                }

                // compare types
                if (type == commonType) {
                    continue;
                }

                // coercion
                if (type.IsNumeric()) {
                    if (type.CanCoerce(commonType)) {
                        mustCoerce = true;
                        continue;
                    }

                    if (commonType.CanCoerce(type)) {
                        mustCoerce = true;
                        commonType = type;
                    }
                }
                else if (commonType == typeof(object)) {
                    continue;
                }
                else if (!type.IsBuiltinDataType()) {
                    // common interface or base class
                    ISet<Type> supersForType = new LinkedHashSet<Type>();
                    TypeHelper.GetBase(type, supersForType);
                    supersForType.Remove(typeof(object));

                    if (supersForType.Contains(commonType)) {
                        continue; // type implements or : common type
                    }

                    if (TypeHelper.IsSubclassOrImplementsInterface(commonType, type)) {
                        commonType = type; // common type implements type
                        continue;
                    }

                    // find common interface or type both implement
                    ISet<Type> supersForCommonType = new LinkedHashSet<Type>();
                    TypeHelper.GetBase(commonType, supersForCommonType);
                    supersForCommonType.Remove(typeof(object));

                    // Take common classes first, ignoring interfaces
                    var found = false;
                    foreach (var superClassType in supersForType) {
                        if (!superClassType.IsInterface && supersForCommonType.Contains(superClassType)) {
                            commonType = superClassType;
                            found = true;
                            break;
                        }
                    }

                    if (found) {
                        continue;
                    }

                    // Take common interfaces
                    foreach (var superClassType in supersForType) {
                        if (superClassType.IsInterface && supersForCommonType.Contains(superClassType)) {
                            break;
                        }
                    }
                }

                commonType = typeof(object);
            }

            if (!existsInAll) {
                return null;
            }

            if (commonType == null) {
                return null;
            }

            // property numbers should start at zero since the serve as array index
            var propertyGetterCache = variantEventType.VariantPropertyGetterCache;
            propertyGetterCache.AddGetters(propertyName);

            EventPropertyGetterSPI getter;
            if (mustCoerce) {
                var caster = SimpleTypeCasterFactory.GetCaster(null, commonType);
                getter = new VariantEventPropertyGetterAnyWCast(variantEventType, propertyName, caster);
            }
            else {
                getter = new VariantEventPropertyGetterAny(variantEventType, propertyName);
            }

            return new VariantPropertyDesc(commonType, getter, true);
        }
예제 #23
0
 /// <summary>
 /// Check whether an abbreviation is enabled.
 /// </summary>
 /// <param name="label">is enabled</param>
 /// <returns>the label is enabled</returns>
 public bool IsEnabled(string label)
 {
     return(labels.Contains(label) && !disabled.Contains(label));
 }