예제 #1
0
        public override void Emit(SourceBuilder sourceCode)
        {
            sourceCode.AppendFrontFormat("if({0} != null)\n", NamesOfEntities.FoundMatchesForFilteringVariable());
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            // emit check whether hash is contained in found matches hash map
            sourceCode.AppendFrontFormat("if(!{0}.ContainsKey({1}))\n",
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            // if not, just insert it
            sourceCode.AppendFrontFormat("{0}[{1}] = match;\n",
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());

            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
            sourceCode.AppendFront("else\n");
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            // otherwise loop till end of collision list of the hash set, insert there
            sourceCode.AppendFrontFormat("{0} {1} = {2}[{3}];\n",
                                         RulePatternClassName + "." + NamesOfEntities.MatchClassName(PatternName),
                                         NamesOfEntities.DuplicateMatchCandidateVariable(),
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());
            sourceCode.AppendFrontFormat("while({0}.nextWithSameHash != null) {0} = {0}.nextWithSameHash;\n",
                                         NamesOfEntities.DuplicateMatchCandidateVariable());

            sourceCode.AppendFrontFormat("{0}.nextWithSameHash = match;\n",
                                         NamesOfEntities.DuplicateMatchCandidateVariable());

            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");

            if (ParallelizedAction)
            {
                sourceCode.AppendFrontFormat("match.{0} = {0};\n",
                                             NamesOfEntities.DuplicateMatchHashVariable());
            }

            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
예제 #2
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFront("// Check whether a duplicate match to be purged was found or will be found\n");
            }

            // emit hash variable declaration
            sourceCode.AppendFrontFormat("int {0} = 0;\n", NamesOfEntities.DuplicateMatchHashVariable());

            // only do the rest if more than one match is requested
            sourceCode.AppendFront("if(maxMatches!=1) {\n");
            sourceCode.Indent();

            // emit found matches hash map initialization as needed
            sourceCode.AppendFrontFormat("if({0}==null) {0} = new Dictionary<int, {1}>();\n",
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         RulePatternClassName + "." + NamesOfEntities.MatchClassName(PatternName));

            // emit hash variable initialization with result of hash computation
            sourceCode.AppendFrontFormat("{0} = unchecked(",
                                         NamesOfEntities.DuplicateMatchHashVariable());
            EmitHashComputation(sourceCode, NeededElements.Length - 1);
            sourceCode.Append(");\n");

            // emit check whether hash is contained in found matches hash map
            sourceCode.AppendFrontFormat("if({0}.ContainsKey({1}))\n",
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            // emit check whether one of the matches in the hash map with same hash is equal to the locally matched elements
            sourceCode.AppendFrontFormat("{0} {1} = {2}[{3}];\n",
                                         RulePatternClassName + "." + NamesOfEntities.MatchClassName(PatternName),
                                         NamesOfEntities.DuplicateMatchCandidateVariable(),
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());
            sourceCode.AppendFront("do {\n");
            sourceCode.Indent();

            // emit check for same elements
            sourceCode.AppendFront("if(");
            for (int i = 0; i < NeededElements.Length; ++i)
            {
                if (i != 0)
                {
                    sourceCode.Append(" && ");
                }
                sourceCode.AppendFormat("{0}._{1} == {2}",
                                        NamesOfEntities.DuplicateMatchCandidateVariable() + MatchObjectPaths[i],
                                        NamesOfEntities.MatchName(NeededElementsUnprefixedName[i], NeededElementsIsNode[i] ? BuildMatchObjectType.Node : BuildMatchObjectType.Edge),
                                        NamesOfEntities.CandidateVariable(NeededElements[i]));
            }
            sourceCode.Append(")\n");

            // emit check failed code, i.e. the current local match is equivalent to one of the already found ones, a duplicate
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");

            // close "emit check whether one of the matches in the hash map with same hash is equal to the locally matched elements"
            // switching to next match with the same hash, if available
            sourceCode.Unindent();
            sourceCode.AppendFront("} ");
            sourceCode.AppendFormat("while(({0} = {0}.nextWithSameHash) != null);\n",
                                    NamesOfEntities.DuplicateMatchCandidateVariable());

            // close "emit check whether hash is contained in found matches hash map"
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");

            // close "only do the rest if more than one match is requested"
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }