Ejemplo n.º 1
0
        /// <summary>
        /// 从指定的主键中移除指定的值。
        /// </summary>
        /// <param name="key">指定的主键。</param>
        /// <param name="value">指定的值。</param>
        /// <returns>是否移除成功。</returns>
        public bool Remove(TKey key, TValue value)
        {
            LinkedListRange <TValue> range = default(LinkedListRange <TValue>);

            if (m_Dictionary.TryGetValue(key, out range))
            {
                for (LinkedListNode <TValue> current = range.First; current != null && current != range.Terminal; current = current.Next)
                {
                    if (current.Value.Equals(value))
                    {
                        if (current == range.First)
                        {
                            LinkedListNode <TValue> next = current.Next;
                            if (next == range.Terminal)
                            {
                                m_LinkedList.Remove(next);
                                m_Dictionary.Remove(key);
                            }
                            else
                            {
                                m_Dictionary[key] = new LinkedListRange <TValue>(next, range.Terminal);
                            }
                        }

                        m_LinkedList.Remove(current);
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取多值字典中指定主键的范围。
 /// </summary>
 /// <param name="key">指定的主键。</param>
 /// <returns>指定主键的范围。</returns>
 public LinkedListRange <TValue> this[TKey key]
 {
     get
     {
         LinkedListRange <TValue> range = default(LinkedListRange <TValue>);
         m_Dictionary.TryGetValue(key, out range);
         return(range);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 检查多值字典中是否包含指定值。
        /// </summary>
        /// <param name="key">要检查的主键。</param>
        /// <param name="value">要检查的值。</param>
        /// <returns>多值字典中是否包含指定值。</returns>
        public bool Contains(TKey key, TValue value)
        {
            LinkedListRange <TValue> range = default(LinkedListRange <TValue>);

            if (m_Dictionary.TryGetValue(key, out range))
            {
                return(range.Contains(value));
            }

            return(false);
        }
Ejemplo n.º 4
0
            internal Enumerator(LinkedListRange <T> range)
            {
                if (!range.IsValid)
                {
                    throw new GameException("Range is invalid.");
                }

                m_GameLinkedListRange = range;
                m_Current             = m_GameLinkedListRange.First;
                Current = default(T);
            }
Ejemplo n.º 5
0
        /// <summary>
        /// 向指定的主键增加指定的值。
        /// </summary>
        /// <param name="key">指定的主键。</param>
        /// <param name="value">指定的值。</param>
        public void Add(TKey key, TValue value)
        {
            LinkedListRange <TValue> range = default(LinkedListRange <TValue>);

            if (m_Dictionary.TryGetValue(key, out range))
            {
                m_LinkedList.AddBefore(range.Terminal, value);
            }
            else
            {
                LinkedListNode <TValue> first    = m_LinkedList.AddLast(value);
                LinkedListNode <TValue> terminal = m_LinkedList.AddLast(default(TValue));
                m_Dictionary.Add(key, new LinkedListRange <TValue>(first, terminal));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 从指定的主键中移除所有的值。
        /// </summary>
        /// <param name="key">指定的主键。</param>
        /// <returns>是否移除成功。</returns>
        public bool RemoveAll(TKey key)
        {
            LinkedListRange <TValue> range = default(LinkedListRange <TValue>);

            if (m_Dictionary.TryGetValue(key, out range))
            {
                m_Dictionary.Remove(key);

                LinkedListNode <TValue> current = range.First;
                while (current != null)
                {
                    LinkedListNode <TValue> next = current != range.Terminal ? current.Next : null;
                    m_LinkedList.Remove(current);
                    current = next;
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 尝试获取多值字典中指定主键的范围。
 /// </summary>
 /// <param name="key">指定的主键。</param>
 /// <param name="range">指定主键的范围。</param>
 /// <returns>是否获取成功。</returns>
 public bool TryGetValue(TKey key, out LinkedListRange <TValue> range)
 {
     return(m_Dictionary.TryGetValue(key, out range));
 }