public virtual void CheckConsistency() { ReadOnlyIndexCollectionList InternalList = InternalIndexCollectionList; ReadOnlyIndexCollectionReadOnlyList PublicList = IndexCollectionList; for (int i = 0; i < InternalList.Count; i++) { IReadOnlyIndexCollection InternalItem = InternalList[i]; Debug.Assert(PublicList.Contains(InternalItem)); Debug.Assert(PublicList.IndexOf(InternalItem) >= 0); IReadOnlyIndexCollection PublicItem = PublicList[i]; Debug.Assert(InternalList.Contains(PublicItem)); Debug.Assert(InternalList.IndexOf(PublicItem) >= 0); if (i == 0) { Debug.Assert(!((ICollection <IReadOnlyIndexCollection>)InternalList).IsReadOnly); InternalList.Remove(InternalItem); InternalList.Insert(0, InternalItem); IEnumerable <IReadOnlyIndexCollection> AsEnumerable = InternalList; foreach (IReadOnlyIndexCollection Item in AsEnumerable) { Debug.Assert(Item == InternalItem); break; } } } }
/// <summary> /// Checks if a index collection is contained is a list of index collection. /// . Properties must be different. /// . They must not share an index. /// </summary> /// <param name="collection">The collection to check.</param> /// <param name="collectionList">The list of collections already accumulated.</param> public static bool IsCollectionSeparate(IReadOnlyIndexCollection collection, ReadOnlyIndexCollectionReadOnlyList collectionList) { bool Result = true; foreach (IReadOnlyBrowsingChildIndex Index0 in collection.NodeIndexList) { foreach (IReadOnlyIndexCollection Item in collectionList) { if (Item.PropertyName == collection.PropertyName) { Result = false; } foreach (IReadOnlyBrowsingChildIndex Index1 in Item.NodeIndexList) { if (Index0.Equals(Index1)) { Result = false; } } } } return(Result); }
private protected virtual ReadOnlyInnerReadOnlyDictionary <string> BuildInnerTable(ReadOnlyBrowseContext browseContext) { IReadOnlyNodeState State = browseContext.State; Debug.Assert(State.InnerTable == null); ReadOnlyIndexCollectionReadOnlyList IndexCollectionList = browseContext.IndexCollectionList; ReadOnlyInnerDictionary <string> InnerTable = CreateInnerTable(); foreach (IReadOnlyIndexCollection NodeIndexCollection in IndexCollectionList) { string PropertyName = NodeIndexCollection.PropertyName; Debug.Assert(!InnerTable.ContainsKey(PropertyName)); IReadOnlyInner Inner = BuildInner(State, NodeIndexCollection); InnerTable.Add(PropertyName, Inner); } if (InnerTable.Count > 0) { DebugObjects.AddReference(InnerTable); } return(InnerTable.ToReadOnly()); }
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 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); } } }