Esempio n. 1
0
        public static int Compare(SubtermMatcher m1, SubtermMatcher m2)
        {
            if (m1 == m2)
            {
                return(0);
            }

            if (m1.IsMatchOnlyNewKinds != m2.IsMatchOnlyNewKinds)
            {
                return(!m1.IsMatchOnlyNewKinds ? -1 : 1);
            }

            if (m1.pattern.Length != m2.pattern.Length)
            {
                return(m1.pattern.Length < m2.pattern.Length ? -1 : 1);
            }

            int cmp;

            for (int i = 0; i < m1.pattern.Length; ++i)
            {
                cmp = Term.Compare(m1.pattern[i], m2.pattern[i]);
                if (cmp != 0)
                {
                    return(cmp);
                }
            }

            return(0);
        }
Esempio n. 2
0
        public SubtermMatcher Clone(TermIndex index)
        {
            var srcIndex = pattern[0].Owner;
            var clone    = new SubtermMatcher();

            clone.IsMatchOnlyNewKinds = IsMatchOnlyNewKinds;
            clone.Trigger             = Trigger == null ? null : index.MkClone(Trigger);
            clone.IsSatisfiable       = IsSatisfiable;
            clone.IsTriggerable       = IsTriggerable;

            Map <Term, Set <int> > levelMatches, clonedLevelMatches;

            clone.pattern        = new Term[pattern.Length];
            clone.matchingUnions = new AppFreeCanUnn[pattern.Length];
            for (int i = 0; i < pattern.Length; ++i)
            {
                clone.pattern[i] = index.MkClone(pattern[i]);
                if (matchingUnions[i] != null)
                {
                    clone.matchingUnions[i] = new AppFreeCanUnn(index.MkClone(matchingUnions[i].MkTypeTerm(srcIndex)));
                }

                if (matcher.TryFindValue(i, out levelMatches))
                {
                    clonedLevelMatches = new Map <Term, Set <int> >(Term.Compare);
                    foreach (var kv in levelMatches)
                    {
                        clonedLevelMatches.Add(index.MkClone(kv.Key), kv.Value);
                    }

                    clone.matcher.Add(i, clonedLevelMatches);
                }
            }

            return(clone);
        }