Exemple #1
0
 internal MapEnumerator(ImmutableItemMap <U> map, int firstIndex, int afterLastIndex)
 {
     _map            = map;
     _firstIndex     = firstIndex;
     _currentIndex   = firstIndex - 1;
     _afterLastIndex = afterLastIndex;
 }
Exemple #2
0
 public void WriteBinary(BinaryWriter w)
 {
     ConvertToImmutable();
     if (this._immutableMap == null)
     {
         this._immutableMap = new ImmutableItemMap <T>(this._provider);
     }
     this._immutableMap.WriteBinary(w);
 }
Exemple #3
0
        public void ConvertToImmutable()
        {
            if (this._mutableMap != null)
            {
                // Convert or merge the maps
                this._immutableMap = this._mutableMap.ConvertToImmutable(this._immutableMap);

                // Clear the mutable map
                this._mutableMap = null;
            }
        }
Exemple #4
0
 public void ReadBinary(BinaryReader r)
 {
     this._mutableMap   = null;
     this._immutableMap = new ImmutableItemMap <T>(this._provider);
     this._immutableMap.ReadBinary(r);
 }
Exemple #5
0
 public void Clear()
 {
     this._immutableMap = null;
     this._mutableMap   = null;
 }
        public ImmutableItemMap <T> ConvertToImmutable(ImmutableItemMap <T> previousLinks = null)
        {
            // If no links were added, return the previous map
            if (_groupIndices.Count == 0)
            {
                return(previousLinks);
            }

            // Sort the new links by the group index
            PartialArray <int> .SortKeysAndItems(_groupIndices, _memberIndices);

            // Build a new immutable map
            ImmutableItemMap <T> newMap = new ImmutableItemMap <T>(_provider);

            // Track how many of the sorted mutable links we've added so far
            int nextIndex = 0;

            // Track the group we're adding links for and what we've linked it to (to filter duplicates)
            int           currentGroup = -1;
            HashSet <int> linksAlreadyAddedForGroup = null;

            // If there was an immutable set, build from it first
            if (previousLinks != null)
            {
                for (int groupIndex = 0; groupIndex < previousLinks._firstMemberIndexForGroup.Count; ++groupIndex)
                {
                    linksAlreadyAddedForGroup = new HashSet <int>();

                    // Add all links in the old set from this group (if any)
                    MapEnumerator <T> oldLinks = previousLinks.LinksFrom(groupIndex);
                    while (oldLinks.MoveNext())
                    {
                        if (linksAlreadyAddedForGroup.Add(oldLinks.CurrentIndex))
                        {
                            newMap.AddLink(groupIndex, oldLinks.CurrentIndex);
                        }
                    }

                    // Add all links in the new set from this group (if any)
                    while (nextIndex < _groupIndices.Count && _groupIndices[nextIndex] == groupIndex)
                    {
                        if (linksAlreadyAddedForGroup.Add(_memberIndices[nextIndex]))
                        {
                            newMap.AddLink(_groupIndices[nextIndex], _memberIndices[nextIndex]);
                        }
                        nextIndex++;
                    }
                }
            }

            // Add remaining links in the new set, if any are left
            currentGroup = -1;
            while (nextIndex < _groupIndices.Count)
            {
                // If we're adding links for a different group, reset the 'already added' set
                if (_groupIndices[nextIndex] != currentGroup)
                {
                    currentGroup = _groupIndices[nextIndex];
                    linksAlreadyAddedForGroup = new HashSet <int>();
                }

                if (linksAlreadyAddedForGroup.Add(_memberIndices[nextIndex]))
                {
                    newMap.AddLink(_groupIndices[nextIndex], _memberIndices[nextIndex]);
                }
                nextIndex++;
            }

            return(newMap);
        }