Пример #1
0
        public MutableLookup(IEqualityComparer <TKey> comparer)
        {
            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }

            groupings = new Dictionary <TKey, MutableLookupGrouping>(comparer);
            if (!typeof(TKey).IsValueType)
            {
                nullGrouping = new MutableLookupGrouping(default(TKey));
            }
        }
Пример #2
0
        /// <summary>
        /// Adds <paramref name="element"/> under the specified <paramref name="key"/>. <paramref name="key"/> does not need to exist.
        /// </summary>
        /// <param name="key">The key to add <paramref name="element"/> under.</param>
        /// <param name="element">The element to add.</param>
        public void Add(TKey key, TElement element)
        {
            MutableLookupGrouping grouping;

            if (key == null)
            {
                grouping = nullGrouping;
            }
            else if (!this.groupings.TryGetValue(key, out grouping))
            {
                grouping = new MutableLookupGrouping(key);
                this.groupings.Add(key, grouping);
            }

            grouping.Add(element);
        }
Пример #3
0
        public void Add(TKey key, IEnumerable <TElement> elements)
        {
            if (elements == null)
            {
                throw new ArgumentNullException("elements");
            }

            MutableLookupGrouping grouping;

            if (key == null)
            {
                grouping = nullGrouping;
            }
            else if (!this.groupings.TryGetValue(key, out grouping))
            {
                grouping = new MutableLookupGrouping(key);
                this.groupings.Add(key, grouping);
            }

            grouping.AddRange(elements);
        }
Пример #4
0
        public MutableLookup(ILookup <TKey, TElement> lookup)
        {
            if (lookup == null)
            {
                throw new ArgumentNullException("lookup");
            }

            groupings = new Dictionary <TKey, MutableLookupGrouping>(lookup.Count);

            if (!typeof(TKey).IsValueType)
            {
                nullGrouping = new MutableLookupGrouping(default(TKey), lookup[default(TKey)]);
            }

            foreach (var grouping in lookup)
            {
                if (grouping.Key == null)
                {
                    continue;
                }

                groupings.Add(grouping.Key, new MutableLookupGrouping(grouping.Key, grouping));
            }
        }