public void TestQueueOperations()
        {
            var chatsToRetrieve = new SimplePriorityQueue <ChatQueueItem, HigherVersionWinsComparerChat>(new LowerVersionWinsChatComparer());

            var dummyContext = new TeamsDataContext((TeamsParticipant)"00000000-0000-beef-0000-000000000000", new ProcessedTenant(new Tenant(), DateTime.UtcNow));

            var chatLowVersion = new HigherVersionWinsComparerChat(new Chat()
            {
                version = 5, id = "1"
            });
            var chatMediumVersion = new HigherVersionWinsComparerChat(new Chat()
            {
                version = 50, id = "2"
            });
            var chatHighVersion = new HigherVersionWinsComparerChat(new Chat()
            {
                version = 500, id = "3"
            });

            chatsToRetrieve.Enqueue(new ChatQueueItem(dummyContext, chatLowVersion), chatLowVersion);
            chatsToRetrieve.Enqueue(new ChatQueueItem(dummyContext, chatMediumVersion), chatMediumVersion);
            chatsToRetrieve.Enqueue(new ChatQueueItem(dummyContext, chatHighVersion), chatHighVersion);

            var isRemoved = chatsToRetrieve.TryRemove(new ChatQueueItem(dummyContext, chatMediumVersion));

            Assert.IsTrue(isRemoved);
            isRemoved = chatsToRetrieve.TryRemove(new ChatQueueItem(dummyContext, chatMediumVersion));
            Assert.IsFalse(isRemoved);
        }
Example #2
0
 /// <summary>
 /// When the precondition for a chunk to be in this stage fails,
 /// if the chunk is in this stage, send it back.
 /// </summary>
 /// <param name="chunkId"></param>
 private void OnPreconditionFailure(Vector3Int chunkId)
 {
     if (queue.TryRemove(chunkId))
     {
         GoingBackwardsThisUpdate.Add(chunkId);
     }
 }
Example #3
0
        /* Might add these at some point -- these are the ones that would allow partial rescans by resetting values starting at the changed cell(s).
         * 1) Search outward from the given changed cell(s) as long as you can keep jumping to a cell with HIGHER total cost. This set of cells represents
         *      all the cells which might have been influenced by the changed cell(s).
         * 2) Note where this search stopped:  Each of the cells adjacent to this set (but not part of it) will be the frontier for the rescan.
         * 3) Reset the value of each cell in this set to Unexplored.
         * 3) Rescan the map from the frontier.
         * (If any of the changed cells could be sources, that needs to be handled too.)
         * public void Rescan(Point changedCell){ }
         * public void Rescan(IEnumerable<Point> changedCells){ }*/

        private void RescanInternal()          // Differs from ScanInternal in how it uses the frontier
        {
            while (frontier.Count > 0)
            {
                Point current = frontier.Dequeue();
                foreach (Dir8 dir in EightDirections.Enumerate(true, false, false))
                {
                    Point neighbor = current.PointInDir(dir);
                    if (!neighbor.ExistsOnMap())
                    {
                        continue;
                    }
                    if (this[neighbor] == Blocked)
                    {
                        continue;
                    }
                    int neighborCost = GetCellCost(neighbor);
                    if (neighborCost < 0)
                    {
                        if (this[neighbor] == Unexplored)
                        {
                            frontier.TryRemove(neighbor);                             // (Not sure this can happen on a rescan if done correctly)
                            this[neighbor] = Blocked;
                        }
                    }
                    else
                    {
                        int totalCost = this[current] + neighborCost;
                        if (this[neighbor] > totalCost)
                        {
                            // Remove them before changing sort values, so the sort doesn't break:
                            if (this[neighbor] != Unexplored)
                            {
                                frontier.TryRemove(neighbor);
                            }
                            this[neighbor] = totalCost;
                            frontier.Enqueue(neighbor, totalCost);
                        }
                    }
                }
            }
        }
        private void RemoveOldestTask(HttpRequestPriority priority)
        {
            lock (_queueSyncLock)
            {
                _perPriorityQueue[priority].TryDequeue(out var oldestTask);

                _tasksQueue.TryRemove(oldestTask);

                if (oldestTask == null)
                {
                    return;
                }

                _taskIdToTaskMap.TryRemove(oldestTask.Id, out var _);

                _priorityToTasksCountMap.AddOrUpdate(oldestTask.Priority, 0, (key, value) => value - 1);
            }
        }
Example #5
0
 public bool Remove(Unit entityController)
 {
     return(unitsTurnQueue.TryRemove(entityController));
 }