Ejemplo n.º 1
0
            public bool Find(ref K item)
            {
                SCG.KeyValuePair <K, V> p = new SCG.KeyValuePair <K, V>(item, default);
                bool retval = sortedpairs.Find(ref p);

                item = p.Key;
                return(retval);
            }
Ejemplo n.º 2
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));
 }
Ejemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="lowKey"></param>
 /// <param name="highKey"></param>
 public void RemoveRangeFromTo(K lowKey, K highKey)
 {
     sortedpairs.RemoveRangeFromTo(new SCG.KeyValuePair <K, V>(lowKey, default), new SCG.KeyValuePair <K, V>(highKey, default));
 }
Ejemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="highKey"></param>
 public void RemoveRangeTo(K highKey)
 {
     sortedpairs.RemoveRangeTo(new SCG.KeyValuePair <K, V>(highKey, default));
 }
Ejemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="top"></param>
 /// <returns></returns>
 public IDirectedEnumerable <SCG.KeyValuePair <K, V> > RangeTo(K top)
 {
     return(sortedpairs.RangeTo(new SCG.KeyValuePair <K, V>(top, default)));
 }
Ejemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="bot"></param>
 /// <returns></returns>
 public IDirectedEnumerable <SCG.KeyValuePair <K, V> > RangeFrom(K bot)
 {
     return(sortedpairs.RangeFrom(new SCG.KeyValuePair <K, V>(bot, default)));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Get the entry in the dictionary whose key is the
 /// weak successor of the specified key.
 /// </summary>
 /// <exception cref="NoSuchItemException"></exception>
 /// <param name="key">The key</param>
 /// <returns>The entry</returns>
 public SCG.KeyValuePair <K, V> WeakSuccessor(K key)
 {
     return(sortedpairs.WeakSuccessor(new SCG.KeyValuePair <K, V>(key, default)));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Get the entry in the dictionary whose key is the
 /// predecessor of the specified key.
 /// </summary>
 /// <exception cref="NoSuchItemException"></exception>
 /// <param name="key">The key</param>
 /// <returns>The entry</returns>
 public SCG.KeyValuePair <K, V> Predecessor(K key)
 {
     return(sortedpairs.Predecessor(new SCG.KeyValuePair <K, V>(key, default)));
 }
Ejemplo n.º 9
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();
            }
        }