Exemplo n.º 1
0
 /// <summary>
 /// Creates an Dictionary with the given capacity
 /// </summary>
 public Dictionary(int capacity)
 {
     if (IsKeyIdentityType())
     {
         dict = new DictionaryImplOpenIdentityHashMap <TKey, TValue>(capacity);
     }
     else
     {
         dict = new DictionaryImplHashMap <TKey, TValue>(capacity);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Default ctor
        /// </summary>
        public Dictionary(IEqualityComparer <TKey> comparer)
        {
            Comparer = comparer;

            if (comparer == null || comparer is EqualityComparer <TKey> .DefaultComparer)
            {
                dict = new DictionaryImplHashMap <TKey, TValue>();
            }
            else
            {
                // have to use the key-wrapping dictionary.
                dict = new DictionaryImplHashMapWithComparerWrapper <TKey, TValue>(comparer);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Default ctor
        /// </summary>
        public Dictionary(Dictionary <TKey, TValue> source)
        {
            if (source.dict is DictionaryImplHashMap <TKey, TValue> )
            {
                dict = new DictionaryImplHashMap <TKey, TValue>((DictionaryImplHashMap <TKey, TValue>)source.dict);
                return;
            }
            if (source.dict is DictionaryImplHashMapWithComparerWrapper <TKey, TValue> )
            {
                dict = new DictionaryImplHashMapWithComparerWrapper <TKey, TValue>((DictionaryImplHashMapWithComparerWrapper <TKey, TValue>)source.dict);
                return;
            }
            if (source.dict is DictionaryImplOpenIdentityHashMap <TKey, TValue> )
            {
                dict = new DictionaryImplOpenIdentityHashMap <TKey, TValue>((DictionaryImplOpenIdentityHashMap <TKey, TValue>)source.dict);
                return;
            }

            // can this even happen?
            if (source.Comparer == null || source.Comparer is EqualityComparer <TKey> .DefaultComparer)
            {
                if (IsKeyIdentityType())
                {
                    dict = new DictionaryImplOpenIdentityHashMap <TKey, TValue>();
                }
                else
                {
                    dict = new DictionaryImplHashMap <TKey, TValue>();
                }
            }
            else
            {
                dict = new DictionaryImplHashMapWithComparerWrapper <TKey, TValue>(source.Comparer);
            }

            foreach (var elem in source)
            {
                dict.Add(elem);
            }
        }