private void Regroup(TSource modifiedItem)
        {
            var currentGroup = this.ItemToGroupIndex[modifiedItem];

            TKey newKey = this.KeySelector(modifiedItem);

            if (EqualityComparer <TKey> .Default.Equals(currentGroup.Key, newKey))
            {
                return;
            }

            GroupedReadOnlyContinuousCollection <TKey, TSource> newGroupForModifiedItem = GetCollectionForKey(newKey);

            while (currentGroup.InternalCollection.Remove(modifiedItem))
            {
                newGroupForModifiedItem.InternalCollection.Add(modifiedItem);
            }

            if (currentGroup.Count == 0)
            {
                this.Output.Remove(currentGroup);
            }

            this.ItemToGroupIndex[modifiedItem] = newGroupForModifiedItem;
        }
        private GroupedReadOnlyContinuousCollection <TKey, TSource> GetCollectionForKey(TKey key)
        {
            GroupedReadOnlyContinuousCollection <TKey, TSource> group =
                this.Output.FirstOrDefault(item => EqualityComparer <TKey> .Default.Equals(item.Key, key));

            if (group == null)
            {
                group = new GroupedReadOnlyContinuousCollection <TKey, TSource>(key);
                this.Output.Add(group);
            }
            return(group);
        }