Пример #1
0
        public FastDictionary(IDictionary <char[], TValue> dictionary, CharComparer comparer) :
            this(dictionary != null? dictionary.Count: 0, comparer)
        {
            if (dictionary == null)
            {
                throw new ArgumentNullException("Dictionary");
            }

            foreach (KeyValuePair <char[], TValue> pair in dictionary)
            {
                Add(pair.Key, pair.Value);
            }
        }
Пример #2
0
        public virtual void OnDeserialization(Object sender)
        {
            if (m_siInfo == null)
            {
                // It might be necessary to call OnDeserialization from a container if the container object also implements
                // OnDeserialization. However, remoting will call OnDeserialization again.
                // We can return immediately if this function is called twice.
                // Note we set m_siInfo to null at the end of this method.
                return;
            }

            int realVersion = m_siInfo.GetInt32(VersionName);
            int hashsize    = m_siInfo.GetInt32(HashSizeName);

            comparer = (CharComparer)m_siInfo.GetValue(ComparerName, typeof(CharComparer));

            if (hashsize != 0)
            {
                buckets = new int[hashsize];
                for (int i = 0; i < buckets.Length; i++)
                {
                    buckets[i] = -1;
                }
                entries  = new Entry[hashsize];
                freeList = -1;

                KeyValuePair <char[], TValue>[] array = (KeyValuePair <char[], TValue>[])
                                                        m_siInfo.GetValue(KeyValuePairsName, typeof(KeyValuePair <char[], TValue>[]));

                if (array == null)
                {
                    throw new SerializationException("Serialization_MissingKeyValuePairs");
                }

                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i].Key == null)
                    {
                        throw new SerializationException("Serialization_NullKey");
                    }
                    Insert(array[i].Key, array[i].Value, true);
                }
            }
            else
            {
                buckets = null;
            }

            version  = realVersion;
            m_siInfo = null;
        }
Пример #3
0
 public FastDictionary(int capacity, CharComparer comparer)
 {
     if (capacity < 0)
     {
         throw new ArgumentOutOfRangeException("Capacity");
     }
     if (capacity > 0)
     {
         Initialize(capacity);
     }
     if (comparer == null)
     {
         comparer = new CharComparer();
     }
     this.comparer = comparer;
 }
Пример #4
0
 public FastDictionary(CharComparer comparer) : this(0, comparer)
 {
 }