예제 #1
0
        /// <summary>
        /// Enqueue the item with the given priority, without calling lock(_queue)
        /// </summary>
        private void EnqueueNoLock(TItem item, TPriority priority)
        {
            SimpleNode node = new SimpleNode(item);

            if (_queue.Count == _queue.MaxSize)
            {
                _queue.Resize(_queue.MaxSize * 2 + 1);
            }
            _queue.Enqueue(node, priority);
            AddToNodeCache(node);
        }
예제 #2
0
        /// <summary>
        /// Enqueue the item with the given priority, without calling lock(_queue) or AddToNodeCache(node)
        /// </summary>
        /// <param name="item"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        private SimpleNode EnqueueNoLockOrCache(TItem item, TPriority priority)
        {
            SimpleNode node = new SimpleNode(item);

            if (_queue.Count == _queue.MaxSize)
            {
                _queue.Resize(_queue.MaxSize * 2 + 1);
            }
            _queue.Enqueue(node, priority);
            return(node);
        }
 /// <summary>
 /// Enqueue a node to the priority queue.  Lower values are placed in front. Ties are broken by first-in-first-out.
 /// This queue automatically resizes itself, so there's no concern of the queue becoming 'full'.
 /// Duplicates are allowed.
 /// O(log n)
 /// </summary>
 public void Enqueue(TItem item, TPriority priority)
 {
     lock (_queue)
     {
         SimpleNode node = new SimpleNode(item);
         if (_queue.Count == _queue.MaxSize)
         {
             _queue.Resize(_queue.MaxSize * 2 + 1);
         }
         _queue.Enqueue(node, priority);
     }
 }