Ejemplo n.º 1
0
        /// <summary>
        /// Array optimized
        /// source.ToDictionary(keySelector, valueSelector)
        /// </summary>
        public static CompactDictionary <TKey, TValue, TComparer> ToComapctDictionary <TSource, TKey, TValue, TComparer>(this TSource[] source, Func <TSource, TKey> keySelector, Func <TSource, TValue> valueSelector)
            where TComparer : struct, IEqualityComparer <TKey>
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (keySelector == null)
            {
                throw new ArgumentNullException(nameof(keySelector));
            }
            if (valueSelector == null)
            {
                throw new ArgumentNullException(nameof(valueSelector));
            }

            var d = new CompactDictionary <TKey, TValue, TComparer>(source.Length);

            foreach (var x in source)
            {
                d.AddOrUpdate(keySelector(x), valueSelector(x));
            }

            return(d);
        }
Ejemplo n.º 2
0
        public void MarginalCapacity()
        {
            var d = new CompactDictionary <string, int>(items.Length / 2);

            foreach (var n in items)
            {
                d.AddOrUpdate(n.Key, n.Value);
            }

            foreach (var n in notExsist)
            {
                Assert.Null(Get(d, n));
            }
            foreach (var n in items)
            {
                Assert.Equal(n.Value, Get(d, n.Key));
            }
        }