Ejemplo n.º 1
0
 private void AddBlockTargetLinesToDict(Dictionary <int, int> dict, PatternBlock block)
 {
     foreach (int lineNum in block.targetLines.Keys)
     {
         if (!dict.ContainsKey(lineNum))
         {
             dict.Add(lineNum, lineNum);
         }
     }
 }
Ejemplo n.º 2
0
        private PatternBlock DetectBlock(int startNum, int startLineToSearch, int maxBlockLen, int maxDiffInBlock, int maxMisses, Dictionary <int, int> processedLinesDict, ILogWindowSearch logWindow)
        {
            int targetLine = FindSimilarLine(startNum, startLineToSearch, processedLinesDict, logWindow);

            if (targetLine == -1)
            {
                return(null);
            }

            PatternBlock block = new PatternBlock();

            block.startLine = startNum;
            int srcLine = block.startLine;

            block.targetStart = targetLine;
            int srcMisses = 0;

            block.srcLines.Add(srcLine, srcLine);
            int         len = 0;
            QualityInfo qi  = new QualityInfo();

            qi.Quality = block.weigth;
            block.qualityInfoList[targetLine] = qi;

            while (!logWindow.ShouldCancel)
            {
                srcLine++;
                len++;
                if (maxBlockLen > 0 && len > maxBlockLen)
                {
                    break;
                }
                int nextTargetLine = FindSimilarLine(srcLine, targetLine + 1, processedLinesDict, logWindow);
                if (nextTargetLine > -1 && nextTargetLine - targetLine - 1 <= maxDiffInBlock)
                {
                    block.weigth += maxDiffInBlock - (nextTargetLine - targetLine - 1) + 1;
                    block.endLine = srcLine;
                    block.srcLines.Add(srcLine, srcLine);
                    if (nextTargetLine - targetLine > 1)
                    {
                        int tempWeight = block.weigth;
                        for (int tl = targetLine + 1; tl < nextTargetLine; ++tl)
                        {
                            qi         = new QualityInfo();
                            qi.Quality = --tempWeight;
                            block.qualityInfoList[tl] = qi;
                        }
                    }
                    targetLine = nextTargetLine;
                    qi         = new QualityInfo();
                    qi.Quality = block.weigth;
                    block.qualityInfoList[targetLine] = qi;
                }
                else
                {
                    srcMisses++;
                    block.weigth--;
                    targetLine++;
                    qi         = new QualityInfo();
                    qi.Quality = block.weigth;
                    block.qualityInfoList[targetLine] = qi;
                    if (srcMisses > maxMisses)
                    {
                        break;
                    }
                }
            }
            block.targetEnd = targetLine;
            qi         = new QualityInfo();
            qi.Quality = block.weigth;
            block.qualityInfoList[targetLine] = qi;
            for (int k = block.targetStart; k <= block.targetEnd; ++k)
            {
                block.targetLines.Add(k, k);
            }
            return(block);
        }