private protected virtual ReadOnlyNodeStateDictionary BuildChildrenStateTable(ReadOnlyBrowseContext browseContext) { IReadOnlyNodeState State = browseContext.State; ReadOnlyInnerReadOnlyDictionary <string> InnerTable = State.InnerTable; ReadOnlyIndexCollectionReadOnlyList IndexCollectionList = browseContext.IndexCollectionList; ReadOnlyNodeStateDictionary ChildStateTable = CreateChildStateTable(); foreach (IReadOnlyIndexCollection <IReadOnlyBrowsingChildIndex> NodeIndexCollection in IndexCollectionList) { // List of indexes for this property (one for placeholder and optional node, several for lists and block lists) IReadOnlyList <IReadOnlyBrowsingChildIndex> NodeIndexList = NodeIndexCollection.NodeIndexList; string PropertyName = NodeIndexCollection.PropertyName; Debug.Assert(InnerTable.ContainsKey(PropertyName)); IReadOnlyInner <IReadOnlyBrowsingChildIndex> Inner = (IReadOnlyInner <IReadOnlyBrowsingChildIndex>)InnerTable[PropertyName]; for (int i = 0; i < NodeIndexList.Count; i++) { IReadOnlyBrowsingChildIndex ChildIndex = NodeIndexList[i]; // If the inner is that of a block list, and the index is for the first node in the block, add block-specific states if (Inner is IReadOnlyBlockListInner <IReadOnlyBrowsingBlockNodeIndex> AsBlockListInner && ChildIndex is IReadOnlyBrowsingNewBlockNodeIndex AsNewBlockIndex) { IReadOnlyBlockState BlockState = AsBlockListInner.InitNewBlock(AsNewBlockIndex); ((IReadOnlyBlockState <IReadOnlyInner <IReadOnlyBrowsingChildIndex> >)BlockState).InitBlockState(); Stats.BlockCount++; IReadOnlyBrowsingPatternIndex PatternIndex = BlockState.PatternIndex; IReadOnlyPatternState PatternState = BlockState.PatternState; AddState(PatternIndex, PatternState); Stats.PlaceholderNodeCount++; IReadOnlyBrowsingSourceIndex SourceIndex = BlockState.SourceIndex; IReadOnlySourceState SourceState = BlockState.SourceState; AddState(SourceIndex, SourceState); Stats.PlaceholderNodeCount++; ChildIndex = AsNewBlockIndex.ToExistingBlockIndex(); } IReadOnlyNodeState ChildState = BuildChildState(Inner, ChildIndex); ChildStateTable.Add(NodeIndexList[i], ChildState); } } return(ChildStateTable); }
private protected virtual void BuildStateTable(IReadOnlyInner <IReadOnlyBrowsingChildIndex> parentInner, ReadOnlyBrowseContext parentBrowseContext, IReadOnlyIndex nodeIndex, IReadOnlyNodeState state) { Debug.Assert((parentBrowseContext == null) || (parentBrowseContext != null && parentInner != null)); Debug.Assert(Contains(nodeIndex)); Debug.Assert(IndexToState(nodeIndex) == state); // Browse the uninitialized state for children ReadOnlyBrowseContext BrowseContext = CreateBrowseContext(parentBrowseContext, state); BrowseStateChildren(BrowseContext, parentInner); // Build inners for each child ReadOnlyInnerReadOnlyDictionary <string> InnerTable = BuildInnerTable(BrowseContext); // Initialize the state InitState(BrowseContext, parentInner, nodeIndex, InnerTable); // Build uninitialized states for each child ReadOnlyNodeStateDictionary ChildrenStateTable = BuildChildrenStateTable(BrowseContext); // Continue to build the table for each of them BuildChildrenStates(BrowseContext, ChildrenStateTable); }
/// <inheritdoc/> public ReadOnlyNodeStateReadOnlyDictionary(ReadOnlyNodeStateDictionary dictionary) : base(dictionary) { }
private protected virtual void BuildChildrenStates(ReadOnlyBrowseContext browseContext, ReadOnlyNodeStateDictionary childrenStateTable) { IReadOnlyNodeState State = browseContext.State; ReadOnlyInnerReadOnlyDictionary <string> InnerTable = State.InnerTable; ReadOnlyIndexCollectionReadOnlyList IndexCollectionList = browseContext.IndexCollectionList; // Build states for children in the order they have been reported when browsing the parent state foreach (IReadOnlyIndexCollection <IReadOnlyBrowsingChildIndex> NodeIndexCollection in IndexCollectionList) { IReadOnlyList <IReadOnlyBrowsingChildIndex> NodeIndexList = NodeIndexCollection.NodeIndexList; string PropertyName = NodeIndexCollection.PropertyName; IReadOnlyInner <IReadOnlyBrowsingChildIndex> Inner = (IReadOnlyInner <IReadOnlyBrowsingChildIndex>)InnerTable[PropertyName]; for (int i = 0; i < NodeIndexList.Count; i++) { IReadOnlyBrowsingChildIndex ChildNodeIndex = NodeIndexList[i]; IReadOnlyNodeState ChildState = childrenStateTable[ChildNodeIndex]; BuildStateTable(Inner, browseContext, ChildState.ParentIndex, ChildState); } } }