Esempio n. 1
0
        /// <summary>
        /// 从指定的主键中移除指定的值。
        /// </summary>
        /// <param name="key">指定的主键。</param>
        /// <param name="value">指定的值。</param>
        /// <returns>是否移除成功。</returns>
        public bool Remove(TKey key, TValue value)
        {
            CFLinkedListRange <TValue> range = default(CFLinkedListRange <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 CFLinkedListRange <TValue>(next, range.Terminal);
                            }
                        }

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

            return(false);
        }
Esempio n. 2
0
 /// <summary>
 /// 获取多值字典中指定主键的范围。
 /// </summary>
 /// <param name="key">指定的主键。</param>
 /// <returns>指定主键的范围。</returns>
 public CFLinkedListRange <TValue> this[TKey key]
 {
     get
     {
         CFLinkedListRange <TValue> range = default(CFLinkedListRange <TValue>);
         m_Dictionary.TryGetValue(key, out range);
         return(range);
     }
 }
Esempio n. 3
0
            internal Enumerator(CFLinkedListRange <T> range)
            {
                if (!range.IsValid)
                {
                    throw new Exception("Range is invalid.");
                }

                m_GameFrameworkLinkedListRange = range;
                m_Current      = m_GameFrameworkLinkedListRange.m_First;
                m_CurrentValue = default(T);
            }
Esempio n. 4
0
        /// <summary>
        /// 检查多值字典中是否包含指定值。
        /// </summary>
        /// <param name="key">要检查的主键。</param>
        /// <param name="value">要检查的值。</param>
        /// <returns>多值字典中是否包含指定值。</returns>
        public bool Contains(TKey key, TValue value)
        {
            CFLinkedListRange <TValue> range = default(CFLinkedListRange <TValue>);

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

            return(false);
        }
Esempio n. 5
0
        /// <summary>
        /// 向指定的主键增加指定的值。
        /// </summary>
        /// <param name="key">指定的主键。</param>
        /// <param name="value">指定的值。</param>
        public void Add(TKey key, TValue value)
        {
            CFLinkedListRange <TValue> range = default(CFLinkedListRange <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 CFLinkedListRange <TValue>(first, terminal));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 从指定的主键中移除所有的值。
        /// </summary>
        /// <param name="key">指定的主键。</param>
        /// <returns>是否移除成功。</returns>
        public bool RemoveAll(TKey key)
        {
            CFLinkedListRange <TValue> range = default(CFLinkedListRange <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);
        }
Esempio n. 7
0
 /// <summary>
 /// 尝试获取多值字典中指定主键的范围。
 /// </summary>
 /// <param name="key">指定的主键。</param>
 /// <param name="range">指定主键的范围。</param>
 /// <returns>是否获取成功。</returns>
 public bool TryGetValue(TKey key, out CFLinkedListRange <TValue> range)
 {
     return(m_Dictionary.TryGetValue(key, out range));
 }