예제 #1
0
        public IndexNodeMutation(int depth, IndexNode node, IIndexNodeFactory indexNodeFactory)
            : this(depth, indexNodeFactory)
        {
            this.original      = node;
            this.IntraNodeText = node.IntraNodeText;

            this.HasMatches    = node.HasMatches;
            this.HasChildNodes = node.HasChildNodes;
        }
예제 #2
0
        public IndexNode CreateNode(IndexNode parent)
        {
            if (parent is null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            var nextDepth = parent.Depth + 1;

            return(new IndexNode(this, nextDepth, this.GetIndexSupportLevelForDepth(nextDepth)));
        }
예제 #3
0
        private bool TryRemove(IndexNode node, int itemId, int nodeDepth, [NotNullWhen(true)] out IndexNodeMutation?mutatedNode)
        {
            mutatedNode = null;

            if (node.HasChildNodes)
            {
                // Work through the child nodes and recursively determine whether removals are needed from
                // them. If they are, then this instance will also become mutated.
                foreach (var child in node.ChildNodes)
                {
                    if (this.TryRemove(child.Value, itemId, nodeDepth + 1, out var mutatedChild))
                    {
                        if (mutatedNode == null)
                        {
                            mutatedNode = new IndexNodeMutation(nodeDepth, node, this.indexNodeFactory);
                            mutatedNode.EnsureMutatedChildNodesCreated();
                        }

                        mutatedNode.MutatedChildNodes !.Add(child.Key, mutatedChild);
                    }
                }
            }

            if (node.HasMatches)
            {
                // Removing an item from the nodes current matches will return the same dictionary
                // if the item didn't exist - this removes the need for an extra Exists check
                var mutatedMatches = node.Matches.Remove(itemId);
                if (mutatedMatches != node.Matches)
                {
                    if (mutatedNode == null)
                    {
                        mutatedNode = new IndexNodeMutation(nodeDepth, node, this.indexNodeFactory);
                    }

                    mutatedNode.EnsureMutatedMatchesCreated();
                    mutatedNode.MutatedMatches !.Remove(itemId);
                }
            }

            return(mutatedNode != null);
        }
예제 #4
0
 public IndexMutation(IndexNode root, IIndexNodeFactory indexNodeFactory)
 {
     this.root = new IndexNodeMutation(0, root, indexNodeFactory);
 }