Пример #1
0
        /// <summary>
        /// Insert a edge at given parent.
        /// </summary>
        /// <param name="parentEdge">Parent edge.</param>
        /// <param name="startIndex">Start index of edge</param>
        /// <param name="endIndex">End index of edge</param>
        /// <returns>New edge created</returns>
        public override IEdge Insert(IEdge parentEdge, int startIndex, int endIndex)
        {
            // This is a leaf node with both start and end indices pointing to
            // terminating symbol. Don't insert this.
            if (startIndex >= Sequence.Count)
            {
                return(null);
            }

            if (PersisntThreshold > Count)
            {
                return(base.Insert(parentEdge, startIndex, endIndex));
            }

            PersistentMultiWaySuffixEdge edge = new PersistentMultiWaySuffixEdge(
                startIndex,
                endIndex,
                MaximumChildrenCount);

            edge.Key = EdgeStore.Write(edge);

            // Parent edge of type PersistentMultiWaySuffixEdge
            PersistentMultiWaySuffixEdge pmwParentEdge = parentEdge as PersistentMultiWaySuffixEdge;

            if (pmwParentEdge != null)
            {
                pmwParentEdge.AddChild(edge.Key);
                Count++;
                return(edge);
            }

            // Parent edge of type MultiWaySuffixEdge
            MultiWaySuffixEdge mwParentEdge = parentEdge as MultiWaySuffixEdge;

            if (mwParentEdge != null)
            {
                if (mwParentEdge.GetChildren() == null)
                {
                    mwParentEdge.AddChild(edge);
                    Count++;
                    return(edge);
                }

                if (mwParentEdge.GetChildren().Length < MaximumChildrenCount)
                {
                    mwParentEdge.AddChild(edge);
                    Count++;
                    return(edge);
                }

                // No more children edge can be added.
                throw new InvalidOperationException(string.Format(
                                                        CultureInfo.CurrentCulture,
                                                        "Cannot add more than {0} child nodes to edge.",
                                                        MaximumChildrenCount));
            }

            return(edge);
        }
Пример #2
0
        public override IEdge Split(IEdge edge, int splitAt)
        {
            // This is a leaf node with both start and end indices pointing to
            // terminating symbol. Don't insert this.
            if (splitAt == Sequence.Count)
            {
                return(edge);
            }

            PersistentMultiWaySuffixEdge pmwCurrentEdge = edge as PersistentMultiWaySuffixEdge;

            if (pmwCurrentEdge == null)
            {
                return(base.Split(edge, splitAt));
            }

            // Create the new edge
            PersistentMultiWaySuffixEdge newEdge =
                new PersistentMultiWaySuffixEdge(splitAt + 1, pmwCurrentEdge.EndIndex, MaximumChildrenCount);

            // Copy the children of old edge to new edge
            newEdge.ReplaceChildren(pmwCurrentEdge.GetChildren());

            // Write the edge to storage
            newEdge.Key = EdgeStore.Write(newEdge);

            // Update the old edge
            pmwCurrentEdge.EndIndex = splitAt;

            // Set new edge as child edge to old edge
            pmwCurrentEdge.ClearChildren();
            pmwCurrentEdge.AddChild(newEdge.Key);
            Count++;

            // Update the edge in storage
            EdgeStore.Write(pmwCurrentEdge);

            return(pmwCurrentEdge);
        }