예제 #1
0
        /// <summary>To understand the principles of this algorithm see the paper by Michael Arnold and Enno Ohlebusch given in the remarks of the class description (<see cref="LongestCommonGeneralizedRepeatL"/>).</summary>
        /// <param name="i">The i.</param>
        private void list_update(int i)
        {
            var sa_i    = _suffixArray[i];
            var textlcp = _LCPS[i];

            int wordIdx   = _wordIndices[i];
            var text_item = _items[wordIdx][_last_index[wordIdx]];

            _last_index[wordIdx] = (_last_index[wordIdx] + 1) % list_sizes[wordIdx];

            _pqls[wordIdx].Add(textlcp);
            int former_textlcp = _pqls[wordIdx].MinimumValue;

            _pqls[wordIdx].Remove();
            textlcp = _pqls[wordIdx].MinimumValue;

            if (_x_repeats[wordIdx] > 1 && _lastLcp[textlcp].IntervalSize >= 0)
            {
                _lastLcp[textlcp].IntervalSize++;
            }

            if (_lastLcp[former_textlcp] != text_item || text_item.IntervalBegin != text_item)
            {
                // decrease interval size
                if (_x_repeats[wordIdx] != 0 && _lastLcp[textlcp].IntervalSize >= 0)
                {
                    _lastLcp[former_textlcp].IntervalSize--;
                }

                // if text_item is the end of an interval
                if (text_item == _lastLcp[former_textlcp])
                {
                    create_interval(text_item.Next, text_item.IntervalBegin, text_item.Lcp, text_item.IntervalSize, text_item.Clean);

                    if (_lastLcp[text_item.Lcp] == text_item)
                    {
                        _lastLcp[text_item.Lcp] = text_item.Next;
                    }
                }

                // if text_item is the beginning of an interval
                else if (text_item == _lastLcp[former_textlcp].IntervalBegin)
                {
                    create_interval(text_item.IntervalEnd, text_item.Previous, text_item.IntervalEnd.Lcp, text_item.IntervalEnd.IntervalSize, text_item.IntervalEnd.Clean);
                }

                // reset interval pointers
                text_item.IntervalEnd   = text_item;
                text_item.IntervalBegin = text_item;
            }

            if (_x_repeats[wordIdx] == 1)
            {
                text_item.IntervalSize = 1;
            }
            else
            {
                text_item.IntervalSize = 0;
            }

            if (_ddlList.Last != text_item)
            {
                // remove nodeToRemove from the list, and add it to the end
                _ddlList.Remove(text_item);
                _ddlList.AddLast(text_item);
                // update lcp value
                text_item.Previous.Lcp = _LCP[i];
            }
            if (_x_repeats[wordIdx] > 0)
            {
                text_item.Clean = true;
            }

            text_item.Idx = i;
        }
예제 #2
0
        private void InitializeIntermediates()
        {
            // initialize items
            list_sizes = new int[_numberOfWords];
            for (int i = 0; i < list_sizes.Length; ++i)
            {
                list_sizes[i] = (_x_repeats[i] > 0) ? _x_repeats[i] : 1;
            }

            _preResults = new List <PreResult>();
            _ddlList    = new LinkedObjectList();
            _items      = new DDLElement[_numberOfWords][];
            for (int i = 0; i < _items.Length; ++i)
            {
                int list_size_i = list_sizes[i];
                _items[i] = new DDLElement[list_size_i];
                for (int j = 0; j < list_size_i; ++j)
                {
                    DDLElement ele;
                    _items[i][j] = ele = new DDLElement()
                    {
                        Text = i
                    };
                    ele.IntervalSize = 0;
                    _ddlList.AddLast(ele);
                }
                if (_x_repeats[i] > 0)
                {
                    _items[i][0].IntervalSize = 1;
                }
            }

            // initialize intermediates
            _last_index = new int[_numberOfWords];
            _pqls       = new MinimumOnSlidingWindow[_numberOfWords];
            for (int i = 0; i < _numberOfWords; ++i)
            {
                _pqls[i].Initialize(_x_repeats[i], 0);
                //_pqls[i].add_value(0);
            }

            _lastLcp = new DDLElement[_maximumLcp + 1];

            var        begin = _ddlList.Last.Previous; // front.prev->prev;
            DDLElement end   = _ddlList.First;         // originally back.next

            begin.IntervalEnd = end;
            end.IntervalBegin = begin;
            if (_x_repeats[_ddlList.Last.Text] > 1)
            {
                end.IntervalSize = _numberOfWords;
            }
            else
            {
                end.IntervalSize = _numberOfWords - 1;
            }
            for (int i = 0; i < _numberOfWords - 1; ++i)
            {
                if (_x_repeats[i] == 0)
                {
                    end.IntervalSize = -1;
                    end.Clean        = false;
                }
            }
            _lastLcp[0] = end;
        }