Пример #1
0
        private long BWMatching(BWt first, BWt second, List <char> list)
        {
            long top    = 0;
            long bottom = second.processedArray.Count() - 1;

            while (top <= bottom)
            {
                if (list.Count != 0)
                {
                    char symbol = list[list.Count - 1];
                    int  symNum = SymbolNumber(symbol);
                    list.RemoveAt(list.Count - 1);
                    Tuple <int, long, int> firstOcc = FindLett(top, bottom, second, symNum);
                    if (firstOcc.Item1 == -5)
                    {
                        return(0);
                    }
                    top = first.startINdex[firstOcc.Item1] + firstOcc.Item2 - 1;
                    long countAfterBott = AfterBott(bottom, second, symNum);
                    bottom = first.startINdex[firstOcc.Item1] + first.count[firstOcc.Item1] - countAfterBott - 1;
                }
                else
                {
                    return(bottom - top + 1);
                }
            }
            return(-4);
        }
        public string Solve(string bwt)
        {
            string        sortedbwt = Sort(bwt);
            BWt           first     = new BWt(sortedbwt);
            BWt           second    = new BWt(bwt);
            StringBuilder strResult = new StringBuilder(bwt);
            string        result;
            int           len = bwt.Length - 1;

            strResult[(int)len] = '$';
            len--;
            Tuple <int, long, int> curr = second.processedArray[0];

            while (len >= 0)
            {
                curr = find(second.processedArray[curr.Item3], first, second);
                if (len < bwt.Length && len > -1)
                {
                    strResult[(int)len] = returnLet(curr.Item1);
                }

                len--;
            }
            result = strResult.ToString();
            return(result);
        }
Пример #3
0
 private long AfterBott(long bottom, BWt second, int symNum)
 {
     for (int i = (int)bottom + 1; i < second.text.Length; i++)
     {
         if (second.processedArray[i].Item1 == symNum)
         {
             return(second.count[symNum] - second.processedArray[i].Item2 + 1);
         }
     }
     return(0);
 }
Пример #4
0
 private Tuple <int, long, int> FindLett(long top, long bottom, BWt second, int symNum)
 {
     for (int i = (int)top; i <= (int)bottom; i++)
     {
         if (second.processedArray[i].Item1 == symNum)
         {
             return(second.processedArray[i]);
         }
     }
     return(new Tuple <int, long, int>(-5, -5, -5));
 }
Пример #5
0
        public long[] Solve(string text, long n, String[] patterns)
        {
            string      sortedbwt = Sort(text);
            BWt         first     = new BWt(sortedbwt);
            BWt         second    = new BWt(text);
            List <long> result    = new List <long>();

            for (int i = 0; i < patterns.Length; i++)
            {
                result.Add(BWMatching(first, second, patterns[i].ToList()));
            }
            return(result.ToArray());
        }
        private Tuple <int, long, int> find(Tuple <int, long, int> curr, BWt first, BWt second)
        {
            long count  = curr.Item2 - 1;
            long indexF = curr.Item1;

            if (indexF > -1 && indexF < first.startINdex.Length)
            {
                indexF = first.startINdex[indexF] + count;
            }
            if (indexF > -1 && indexF < first.processedArray.Count)
            {
                return(first.processedArray[(int)indexF]);
            }
            return(new Tuple <int, long, int>(-3, -3, -4));
        }