/// <summary>
 /// Find the entry in the dictionary whose key is the
 /// weak predecessor of the specified key.
 /// </summary>
 /// <param name="key">The key</param>
 /// <param name="res">The predecessor, if any</param>
 /// <returns>True if key has a weak predecessor</returns>
 public bool TryWeakPredecessor(K key, out SCG.KeyValuePair <K, V> res) => sorteddict.TryWeakPredecessor(key, out res);
Beispiel #2
0
 public bool Remove(SCG.KeyValuePair <TKey, TValue> item)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="c"></param>
 /// <param name="lowEntry"></param>
 /// <param name="lowIsValid"></param>
 /// <param name="highEntry"></param>
 /// <param name="highIsValid"></param>
 /// <returns></returns>
 public bool Cut(IComparable <K> c, out SCG.KeyValuePair <K, V> lowEntry, out bool lowIsValid, out SCG.KeyValuePair <K, V> highEntry, out bool highIsValid)
 {
     return(sorteddict.Cut(c, out lowEntry, out lowIsValid, out highEntry, out highIsValid));;
 }
Beispiel #4
0
 /// <summary>
 /// Find the entry in the dictionary whose key is the
 /// weak successor of the specified key.
 /// </summary>
 /// <param name="key">The key</param>
 /// <param name="res">The weak successor, if any</param>
 /// <returns>True if the key has a weak successor</returns>
 public bool TryWeakSuccessor(K key, out SCG.KeyValuePair <K, V> res)
 {
     return(sortedpairs.TryWeakSuccessor(new SCG.KeyValuePair <K, V>(key, default), out res));
 }
Beispiel #5
0
 public void Add(SCG.KeyValuePair <TKey, TValue> item)
 {
     throw new NotImplementedException();
 }
Beispiel #6
0
 public override K Map(SCG.KeyValuePair <K, V> pair)
 {
     return(pair.Key);
 }
Beispiel #7
0
 public bool Equals(SCG.KeyValuePair <K, V> other)
 {
     return(cutter.Equals(other.Key));
 }
Beispiel #8
0
 public int CompareTo(SCG.KeyValuePair <K, V> other)
 {
     return(cutter.CompareTo(other.Key));
 }
Beispiel #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cutter"></param>
 /// <param name="lowEntry"></param>
 /// <param name="lowIsValid"></param>
 /// <param name="highEntry"></param>
 /// <param name="highIsValid"></param>
 /// <returns></returns>
 public bool Cut(IComparable <K> cutter, out SCG.KeyValuePair <K, V> lowEntry, out bool lowIsValid, out SCG.KeyValuePair <K, V> highEntry, out bool highIsValid)
 {
     return(sortedpairs.Cut(new KeyValuePairComparable(cutter), out lowEntry, out lowIsValid, out highEntry, out highIsValid));
 }
Beispiel #10
0
        /// <summary>
        /// Remove all items *not* in a supplied collection from this bag,
        /// counting multiplicities.
        /// </summary>
        /// <param name="items">The items to retain</param>
        public virtual void RetainAll(SCG.IEnumerable <T> items)
        {
            UpdateCheck();

            HashBag <T> res = new HashBag <T>(itemequalityComparer);

            foreach (T item in items)
            {
                SCG.KeyValuePair <T, int> p = new SCG.KeyValuePair <T, int>(item, default);
                if (dict.Find(ref p))
                {
                    SCG.KeyValuePair <T, int> q = p;
                    if (res.dict.Find(ref q))
                    {
                        if (q.Value < p.Value)
                        {
                            q = new SCG.KeyValuePair <T, int>(q.Key, q.Value + 1);
                            res.dict.Update(q);
                            res.size++;
                        }
                    }
                    else
                    {
                        q = new SCG.KeyValuePair <T, int>(q.Key, 1);
                        res.dict.Add(q);
                        res.size++;
                    }
                }
            }

            if (size == res.size)
            {
                return;
            }

            CircularQueue <T> wasRemoved = null;

            if ((ActiveEvents & EventType.Removed) != 0)
            {
                wasRemoved = new CircularQueue <T>();
                foreach (SCG.KeyValuePair <T, int> p in dict)
                {
                    int removed = p.Value - res.ContainsCount(p.Key);
                    if (removed > 0)
                    {
#warning We could send bag events here easily using a CircularQueue of (should?)
                        for (int i = 0; i < removed; i++)
                        {
                            wasRemoved.Enqueue(p.Key);
                        }
                    }
                }
            }
            dict = res.dict;
            size = res.size;

            if ((ActiveEvents & EventType.Removed) != 0)
            {
                RaiseForRemoveAll(wasRemoved);
            }
            else if ((ActiveEvents & EventType.Changed) != 0)
            {
                RaiseCollectionChanged();
            }
        }