/// <inheritdoc/>
        public void Enqueue(HexKeyValuePair <int, TValue> item)
        {
            var index = item.Key >> _shift;

            if (index <= _baseIndex)
            {
                _queue.Enqueue(item);
            }
            else if (_lists == null && _queue.Count < PoolSize)
            {
                _baseIndex = index;
                _queue.Enqueue(item);
            }
            else
            {
                if (_lists == null)
                {
#if UseSortedDictionary
                    _lists = new SortedDictionary <ushort, HotPriorityQueueList <PathPriority, TValue> >();
#else
                    _lists = new SortedList <int, HotPriorityQueueList <int, TValue> >();
#endif
                }
                HotPriorityQueueList <int, TValue> list;
                if (!_lists.TryGetValue(index, out list))
                {
                    list = new HotPriorityQueueList <int, TValue>();
                    _lists.Add(index, list);
                }
                list.Add(item);
            }
        }
            /// <inheritdoc/>
            public bool TryDequeue(out HexKeyValuePair <TKey, TValue> result)
            {
                if (_items.Count == 0)
                {
                    result = default(HexKeyValuePair <TKey, TValue>);
                    return(false);
                }

                result = _items[0];

                // Remove the first item if neighbour will only be 0 or 1 items left after doing so.
                if (_items.Count <= 2)
                {
                    _items.RemoveAt(0);
                }
                else
                {
                    // Remove the first item and move the last item to the front.
                    _items[0] = _items[_items.Count - 1];
                    _items.RemoveAt(_items.Count - 1);

                    MinHeapifyDown(0);
                }
                return(true);
            }
Exemple #3
0
 /// <inheritdoc/>
 public void Enqueue(HexKeyValuePair <TPriority, TValue> item)
 {
     if (!_dictionary.TryGetValue(item.Key, out var queue))
     {
         queue = new Queue <TValue>();
         _dictionary.Add(item.Key, queue);
     }
     queue.Enqueue(item.Value);    // Only not-null values enqueued; so assumptions below valid.
 }
            /// <inheritdoc/>
            public bool TryPeek(out HexKeyValuePair <TKey, TValue> result)
            {
                if (_items.Count == 0)
                {
                    result = default(HexKeyValuePair <TKey, TValue>);
                    return(false);
                }

                result = _items[0];
                return(true);
            }
Exemple #5
0
        /// <inheritdoc/>
        public void Enqueue(HexKeyValuePair <TPriority, TValue> item)
        {
            Queue <TValue> queue;

            if (!_list.TryGetValue(item.Key, out queue))
            {
                queue = new Queue <TValue>();
                _list.Add(item.Key, queue);
            }
            queue.Enqueue(item.Value);
        }
Exemple #6
0
 /// <inheritdoc/>
 public bool TryPeek(out HexKeyValuePair <TPriority, TValue> result)
 {
     if (_dictionary.Count > 0)
     {
         var list = _dictionary.First();
         var v    = list.Value.Peek();
         result = HexKeyValuePair.New(list.Key, v);
         return(true);
     }
     result = default(HexKeyValuePair <TPriority, TValue>);
     return(false);
 }
Exemple #7
0
 /// <inheritdoc/>
 public bool TryPeek(out HexKeyValuePair <TPriority, TValue> result)
 {
     if (_list.Any())
     {
         var pair = _list.First();
         var v    = pair.Value.Peek();
         result = new HexKeyValuePair <TPriority, TValue>(pair.Key, v);
         return(true);
     }
     result = default(HexKeyValuePair <TPriority, TValue>);
     return(false);
 }
            /// <inheritdoc/>
            public void Enqueue(HexKeyValuePair <TKey, TValue> item)
            {
                _items.Add(item);
                var child  = Count - 1;
                var parent = (child - 1) / 2;

                while (child > 0 && _items[parent] > _items[child])
                {
                    var heap = _items[parent];  _items[parent] = _items[child];  _items[child] = heap;
                    child  = parent;
                    parent = (child - 1) / 2;
                }
            }
 /// <inheritdoc/>
 public bool TryPeek(out HexKeyValuePair <int, TValue> result)
 {
     if (_queue.TryPeek(out result))
     {
         return(true);
     }
     else if (_lists.Count > 0)
     {
         return((_queue = GetNextQueue()).TryPeek(out result));
     }
     else
     {
         return(false);
     }
 }
Exemple #10
0
 /// <inheritdoc/>
 public bool TryDequeue(out HexKeyValuePair <TPriority, TValue> result)
 {
     if (_dictionary.Count > 0)
     {
         var list = _dictionary.First();
         var v    = list.Value.Dequeue();
         result = HexKeyValuePair.New(list.Key, v);
         if (list.Value.Count == 0)
         {
             _dictionary.Remove(list.Key);
         }
         return(true);
     }
     result = default(HexKeyValuePair <TPriority, TValue>);
     return(false);
 }
Exemple #11
0
 /// <inheritdoc/>
 public bool TryDequeue(out HexKeyValuePair <TPriority, TValue> result)
 {
     if (_list.Any())
     {
         var pair = _list.First();
         var v    = pair.Value.Dequeue();
         result = new HexKeyValuePair <TPriority, TValue>(pair.Key, v);
         if (pair.Value.Count == 0)
         {
             _list.Remove(pair.Key);
         }
         return(true);
     }
     result = default(HexKeyValuePair <TPriority, TValue>);
     return(false);
 }
        /// <inheritdoc/>
        public bool TryDequeue(out HexKeyValuePair <int, TValue> result)
        {
            if (_queue.TryDequeue(out result))
            {
                return(true);
            }
            else
            {
                var list = _lists.First();
                _baseIndex = list.Key;
                _queue     = list.Value.PriorityQueue;
                _lists.Remove(list.Key);

                return(_queue.TryDequeue(out result));
            }
        }
        /// <inheritdoc/>
        public void Enqueue(HexKeyValuePair <int, TValue> item)
        {
            var index = item.Key >> _preferenceWidth;

            if (index <= _baseIndex)
            {
                _queue.Enqueue(item);
            }
            else if (_lists.Count == 0 && _queue.Count < PoolSize)
            {
                _baseIndex = index;
                _queue.Enqueue(item);
            }
            else
            {
                HotPriorityQueueList <int, TValue> list;
                if (!_lists.TryGetValue(index, out list))
                {
                    list = new HotPriorityQueueList <int, TValue>();
                    _lists.Add(index, list);
                }
                list.Add(item);
            }
        }
 /// <inheritdoc/>
 public bool Equals(HexKeyValuePair <TKey, TValue> other)
 {
     return(this == other);
 }
Exemple #15
0
 /// <inheritdoc/>
 public void Enqueue(TKey key, TValue value)
 {
     Enqueue(HexKeyValuePair.New(key, value));
 }
 /// <inheritdoc/>
 public int CompareTo(HexKeyValuePair <TKey, TValue> other)
 {
     return(this.Key.CompareTo(other.Key));
 }
Exemple #17
0
 IEnumerable <HexKeyValuePair <TPriority, TValue> > Enumerable()
 {
     return(from list in _dictionary
            from item in list.Value
            select HexKeyValuePair.New(list.Key, item));
 }
Exemple #18
0
 /// <inheritdoc/>
 public void Enqueue(TPriority priority, TValue value)
 {
     Enqueue(HexKeyValuePair.New(priority, value));
 }
 /// <inheritdoc/>
 public bool Remove(HexKeyValuePair <TKey, TValue> item)
 {
     throw new InvalidOperationException("Remove");
 }
 /// <inheritdoc/>
 public void Add(HexKeyValuePair <TKey, TValue> item)
 {
     _list.Add(item);
 }
 /// <inheritdoc/>
 public bool Contains(HexKeyValuePair <TKey, TValue> item)
 {
     return(_list.Contains(item));
 }