Esempio n. 1
0
        private static void GenerateTreap(IInverseIntTreap <int> treap, int seed)
        {
            Random random = new Random(seed);

            for (int i = 0; i < 1000; i++)
            {
                treap.Insert(i, i + 1);
            }

            for (int i = 0; i < 1000; i++)
            {
                int source = random.Next() % treap.Count;
                int dest   = random.Next() % treap.Count;
                treap.Move(source, dest);
            }
        }
Esempio n. 2
0
        private void MoveSuffix(char sym, int boundIdx, int idx, HashedSet <int> newBoundarySuffix)
        {
            int curLcp = lcp[idx];

            int rightBound  = BinarySearch.BinarySearch.Instance.BinarySearchLast(idx, Math.Min(arrayLength - 1, 1 + idx + charCollector.GetInt(stringBuilder[boundIdx])), new LcpFirstStrategy(this, curLcp, idx)) + 1;
            int newPosition = BinarySearch.BinarySearch.Instance.BinarySearchFirst(idx + 1, Math.Min(rightBound + 1, arrayLength), new SymbolFirstStrategy(this, curLcp, sym)) - 1;

            if (idx > 0)
            {
                int lc = lcp.Aggregate(idx - 1, idx);
                lcp[idx - 1] = lc;
            }

            int newLcp;
            int newLcpPrev;

            if (lcp[newPosition] >= curLcp)
            {
                newLcp     = curLcp;
                newLcpPrev = curLcp;
                if (stringBuilder[array[newPosition + 1] + curLcp] == sym)
                {
                    newBoundarySuffix.Add(boundIdx);
                    newLcp++;
                }
            }
            else
            {
                newLcp     = lcp[newPosition];
                newLcpPrev = curLcp;
                if (stringBuilder[array[newPosition] + curLcp] == sym)
                {
                    newLcpPrev++;
                }
            }

            lcp.Move(idx, newPosition);
            array.Move(idx, newPosition);
            lcp[newPosition]     = newLcp;
            lcp[newPosition - 1] = newLcpPrev;
        }