Esempio n. 1
0
        public void AddOccurNodes(Edge eSource, Edge eDest)
        {
            if (eDest.st == null)
            {
                eDest.st  = eSource.st;
                eDest.len = eSource.len;
            }
            else
            {
                OccurNode on = eDest.st;
                while (on.next != null)
                {
                    on = on.next;
                }

                on.next      = new OccurNode();
                on.next.next = eSource.st.next;
                //on.next.previous = on.next;
                on.next.value = eSource.st.value;
                eDest.len    += eSource.len;
            }
        }
Esempio n. 2
0
        public void VisitNode4Imp(int tabs, int pnvalue, List<int> pnIndexes)
        {
            //int occurCounter = 0;
            MakeEdgeVectorHashtable1();
            Console.WriteLine("MakeEdgeVectorHashtable1() finished: " + DateTime.Now.ToString());

            Stack<EdgeStruct> s = new Stack<EdgeStruct>();
            //int[] rootOccurIndexes = new int[2] { -1, -1 };

            OccurNode[] rootOccurSt = new OccurNode[1] { null };
            int[] rootOccurLength = new int[1] { -1 };

            List<Edge> edgeCol = Edge.FindAll1(stn);
            edgeCol.Sort(EdgeComparer);
            foreach (Edge e in edgeCol)
            {
                EdgeStruct es = new EdgeStruct();
                es.e = e;
                es.tabs = 0;
                es.pnValue = 0;
                //es.pnOccurIndexes = rootOccurIndexes;
                es.pnOccurStart = rootOccurSt;
                es.pnOccurLength = rootOccurLength;
                s.Push(es);
            }
            edgeCol.Clear();
            edgeCol = null;
            //int leafCounter = 0;

            while (s.Count != 0)
            {
                EdgeStruct es = s.Pop();
                if (es.e.value != -1)  // node has already been marked
                {
                    es.e.st = es.occurStart[0];
                    es.e.len = es.occurLength[0];
                    //calculatePeriodCounter++;
                    if (IsCalculatePeriod(es.e))
                    {
                        CalculatePeriodImp(es.e);
                        //CalculatePeriod2(es.e);
                    }

                    if (es.pnOccurStart[0] == null)
                    {
                        es.pnOccurStart[0] = es.occurStart[0];
                        es.pnOccurLength[0] = es.occurLength[0];
                    }
                    else
                    {
                        occur.Sort(es.pnOccurStart, es.pnOccurLength[0], es.occurStart, es.occurLength[0]);
                        es.pnOccurLength[0] += es.occurLength[0];
                    }
                }
                else        // node has not been marked yet
                {
                    int myval = 0;
                    if (es.e.last_char_index == (N - 1))        // if it leads to a leaf
                    {
                        myval = N - ((es.e.last_char_index - es.e.first_char_index) + 1 + es.pnValue);

                        occur.Add(myval, es.pnOccurStart, es.pnOccurLength);
                    }
                    else
                    {
                        myval = ((es.e.last_char_index - es.e.first_char_index) + 1 + es.pnValue);
                        es.e.value = myval;

                        //es.occurIndexes = new int[2]{-1,-1};
                        s.Push(es);
                        stn = es.e.end_node;
                        List<Edge> eCol = Edge.FindAll1(stn);
                        eCol.Sort(EdgeComparer);
                        foreach (Edge e in eCol)
                        {
                            EdgeStruct es1 = new EdgeStruct();
                            es1.e = e;
                            es1.tabs = es.tabs + 1;
                            es1.pnValue = es.e.value;
                            es1.pnOccurStart = es.occurStart;
                            es1.pnOccurLength = es.occurLength;
                            //es1.pnOccurIndexes = es.occurIndexes;
                            s.Push(es1);
                        }
                        eCol.Clear();
                        eCol = null;
                    }
                }
            }
        }
Esempio n. 3
0
        public void CalculatePeriodImp(Edge e)
        {
            if (e.value > Program.maxStrLen || e.value < Program.minStrLen)
            {
                return;
            }

            OccurNode current = e.st;

            /* *********** Extracting data for complexity improvement experiments **************
             * Date: 10th Sep 2008, 5:54 AM
             */
            //if (e.value < 35)
            //{
            for (int i = 0; i < e.len; i++)
            {
                ovl.Add(current.value);
                current = current.next;
            }

            current = e.st;
            Program.CalculatePeriod(ovl.ToArray(), e.value);
            ovl.Clear();
            return;

            //}
            /************ End extracting data for complexity improvement experiments ************/

            //     code to find the last value of occur_vector - 2nd nov 2007
            OccurNode last = e.st;

            for (int k = 1; k < e.len; k++)
            {
                last = last.next;
            }
            int lastOccurValue = last.value;
            // end code to find the last value of occur_vector - 2nd nov 2007
            int preDiffValue = -5; // introduced to check the repetitive stPos periods like 0,3,6,9

            calculatePeriodCounter++;


            for (int i = 1; i < e.len; i++)
            {
                outerLoopCounterBeforeCheck++;
                //int diffValue = occur[i + 1] - occur[i];
                int diffValue = current.next.value - current.value;

                /******* Modifying temporarily to check periodicity of 3
                 * if (diffValue < 5 || diffValue < e.value || diffValue == 1 || diffValue > (0.33 * T.Length) || current.value > (0.5 * T.Length))
                 * //*********** End Modifying to check 3 *********/
                /* replacing with line below for packet data
                 * if (diffValue < 5 || diffValue < e.value  || diffValue > (0.33 * T.Length) || current.value > (0.5 * T.Length) || diffValue == preDiffValue)
                 */
                if (diffValue < 2 || diffValue < e.value || diffValue > 20 || diffValue == preDiffValue)
                {
                    diffCounter++;
                    current = current.next;
                    continue;
                }
                Period p = new Period();
                p.periodValue = diffValue;
                p.stPos       = current.value;
                p.endPos      = lastOccurValue; // introduced to find periodicity in segments - 2nd nov 2007
                p.fci         = p.stPos;
                p.length      = e.value;
                preDiffValue  = diffValue;

                ///*****commenting temporarily - 5th nov 2007 *********
                if (PeriodCollection.Exist(p))
                {
                    periodColExistCounter++;
                    current = current.next;
                    continue;
                }
                //****** end commenting ********/

                outerLoopCounterAfterCheck++;

                /*********** not required after new code aug 27
                 * int modRes = p.stPos % p.periodValue;
                 */
                p.foundPosCount = 0;

                /******** NEW CODE Aug 27 ************/
                int    A, C = 0;
                double B = 0, sumPerVal = 0;

                int preSubCurValue = -5;
                //int preStPos = p.stPos;
                int currStPos = p.stPos;
                /***** END NEW CODE Aug 27 *********/

                OccurNode subCurrent = current;
                for (int j = i; j <= e.len; j++)
                {
                    innerLoopCounter++;


                    ///******** NEW CODE Aug 27 ***********
                    //A = subCurrent.value - p.stPos;
                    A = subCurrent.value - currStPos;
                    B = Math.Round((double)A / p.periodValue);
                    C = A - (p.periodValue * (int)B);
                    if (C >= (-1 * tolWin) && C <= tolWin)
                    {
                        //if (Math.Round((double)((preSubCurValue - p.stPos) / p.periodValue)) != B)
                        if (Math.Round((double)((preSubCurValue - currStPos) / p.periodValue)) != B) // if it is a valid periodic occurence
                        {
                            preSubCurValue = subCurrent.value;
                            //preStPos = currStPos;           // new lines
                            currStPos = subCurrent.value;     // new lines
                            p.foundPosCount++;
                            sumPerVal += (p.periodValue + C); // new lines
                        }
                    }
                    //***** END NEW CODE Aug 27 *********/

                    /**************** commenting the original one
                     * if (modRes == subCurrent.value % p.periodValue)
                     * p.foundPosCount++;
                     ********** end comment ***/

                    ///***** introducing dmax and mu concept - Nov 4 2007
                    if (j != i && j < e.len &&                                                            // if its atleast the 2nd occurence or at maximum 2nd last occurence
                        (subCurrent.next.value - subCurrent.value) >= (dmax /* * p.periodValue*/) &&      // if difference between this and previous occurence is greater than dmax times period value
                        (currStPos - p.stPos) >= (minLengthOfSegment * (T.Length - 1) /*p.periodValue*/)) // if the length of to be segment is greater than minLengthOfSegment times period value
                    //(subCurrent.value - p.stPos) >= (minLengthOfSegment * p.periodValue)) // if the length of to be segment is greater than minLengthOfSegment times period value
                    {
                        /*if (currStPos == subCurrent.value)  // if this occurence was match
                         * {
                         *  p.endPos = subCurrent.value;
                         * }
                         * else
                         * {
                         *  p.endPos = currStPos;           // set to the last matched position
                         * }
                         */

                        p.endPos = currStPos;           // set to the last matched position

                        break;
                    }
                    //****** end dmax and mu code - Nov 4 2007 **********/


                    subCurrent = subCurrent.next;
                }

                double y = 0;

                /*** commented and replaced with the lines below to avoid > 1 conf using avgPeriodValue instead of periodValue
                 * if (((T.Length - 1 - p.stPos) % p.periodValue) >= e.value) y = 1; else y = 0;
                 * double th1 = p.foundPosCount / Math.Floor(((double)(T.Length - 1 - p.stPos) / p.periodValue) + y);
                 */

                ///*** used p.avgPeriodValue instead of p.periodValue in threshold (conf) calculation to avoid th > 1
                /// also added periodicity for segments code by replacing T.length - 1 with lastOccurValue + p.length
                p.avgPeriodValue = (sumPerVal - p.periodValue) / (p.foundPosCount - 1);

                /************ changed lastOccurValue with p.endPos in the following lines ***********
                 * if (((lastOccurValue + p.length - p.stPos) % ((int)Math.Round(p.avgPeriodValue))) >= e.value) y = 1; else y = 0;
                 * double th1 = p.foundPosCount / Math.Floor(((double)(lastOccurValue + p.length - p.stPos) / p.avgPeriodValue) + y);
                 *********end changed lastOccurValue with p.endPos in the above lines *****************/
                if (((p.endPos + p.length - p.stPos) % ((int)Math.Round(p.avgPeriodValue))) >= e.value)
                {
                    y = 1;
                }
                else
                {
                    y = 0;
                }
                double th1 = p.foundPosCount / Math.Floor(((double)(p.endPos + p.length - p.stPos) / p.avgPeriodValue) + y);
                //*/
                p.threshold = th1;

                if (p.threshold >= this.minThreshold) //&& (!IsPeriodExist(p)))
                {
                    AddPeriodCounter++;
                    //p.avgPeriodValue = (sumPerVal-p.periodValue) / (p.foundPosCount-1); // moving this to upper lines
                    PeriodCollection.Add(p.periodValue, p);
                    //break;

                    //periods.Add(p);
                }
                current = current.next;
            }
        }
Esempio n. 4
0
        public void VisitNode4Imp(int tabs, int pnvalue, List <int> pnIndexes)
        {
            //int occurCounter = 0;
            MakeEdgeVectorHashtable1();
            Console.WriteLine("MakeEdgeVectorHashtable1() finished: " + DateTime.Now.ToString());

            Stack <EdgeStruct> s = new Stack <EdgeStruct>();

            //int[] rootOccurIndexes = new int[2] { -1, -1 };

            OccurNode[] rootOccurSt = new OccurNode[1] {
                null
            };
            int[] rootOccurLength = new int[1] {
                -1
            };

            List <Edge> edgeCol = Edge.FindAll1(stn);

            edgeCol.Sort(EdgeComparer);
            foreach (Edge e in edgeCol)
            {
                EdgeStruct es = new EdgeStruct();
                es.e       = e;
                es.tabs    = 0;
                es.pnValue = 0;
                //es.pnOccurIndexes = rootOccurIndexes;
                es.pnOccurStart  = rootOccurSt;
                es.pnOccurLength = rootOccurLength;
                s.Push(es);
            }
            edgeCol.Clear();
            edgeCol = null;
            //int leafCounter = 0;

            while (s.Count != 0)
            {
                EdgeStruct es = s.Pop();
                if (es.e.value != -1)  // node has already been marked
                {
                    es.e.st  = es.occurStart[0];
                    es.e.len = es.occurLength[0];
                    //calculatePeriodCounter++;
                    if (IsCalculatePeriod(es.e))
                    {
                        CalculatePeriodImp(es.e);
                        //CalculatePeriod2(es.e);
                    }

                    if (es.pnOccurStart[0] == null)
                    {
                        es.pnOccurStart[0]  = es.occurStart[0];
                        es.pnOccurLength[0] = es.occurLength[0];
                    }
                    else
                    {
                        occur.Sort(es.pnOccurStart, es.pnOccurLength[0], es.occurStart, es.occurLength[0]);
                        es.pnOccurLength[0] += es.occurLength[0];
                    }
                }
                else        // node has not been marked yet
                {
                    int myval = 0;
                    if (es.e.last_char_index == (N - 1))        // if it leads to a leaf
                    {
                        myval = N - ((es.e.last_char_index - es.e.first_char_index) + 1 + es.pnValue);

                        occur.Add(myval, es.pnOccurStart, es.pnOccurLength);
                    }
                    else
                    {
                        myval      = ((es.e.last_char_index - es.e.first_char_index) + 1 + es.pnValue);
                        es.e.value = myval;


                        //es.occurIndexes = new int[2]{-1,-1};
                        s.Push(es);
                        stn = es.e.end_node;
                        List <Edge> eCol = Edge.FindAll1(stn);
                        eCol.Sort(EdgeComparer);
                        foreach (Edge e in eCol)
                        {
                            EdgeStruct es1 = new EdgeStruct();
                            es1.e             = e;
                            es1.tabs          = es.tabs + 1;
                            es1.pnValue       = es.e.value;
                            es1.pnOccurStart  = es.occurStart;
                            es1.pnOccurLength = es.occurLength;
                            //es1.pnOccurIndexes = es.occurIndexes;
                            s.Push(es1);
                        }
                        eCol.Clear();
                        eCol = null;
                    }
                }
            }
        }