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; }
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))); }
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); }
public IndexMutation(IndexNode root, IIndexNodeFactory indexNodeFactory) { this.root = new IndexNodeMutation(0, root, indexNodeFactory); }