Exemple #1
0
        public void ContainsKeyTest()
        {
            var heap = new MinHeap <int, int>();

            heap.Add(42, -1);
            Assert.IsTrue(heap.ContainsKey(42));
            Assert.IsFalse(heap.ContainsKey(-1));
        }
        public void ContainsKeyTest()
        {
            var heap = new MinHeap <string, int, Dictionary <string, int> >();

            heap.Add("item1", 3);
            heap.Add("item2", 4);
            heap.Add("item3", 8);

            Assert.IsTrue(heap.ContainsKey("item2"));
            Assert.IsFalse(heap.ContainsKey("item4"));
            Assert.Throws <ArgumentNullException>(() => heap.ContainsKey(null));
        }
        public void KeyRemovedAfterExtractMin()
        {
            var heap = new MinHeap <string, int, Dictionary <string, int> >();

            heap.Add("item1", 3);
            heap.ExtractMin();

            Assert.IsFalse(heap.ContainsKey("item1"));
        }
Exemple #4
0
        private void UpdateNeighbors(
            int currentWptIndex,
            RouteSeachRegion regionPara,
            RouteFindingData findRouteData,
            MinHeap <int, double> unvisited,
            double currentDis)
        {
            foreach (var edgeIndex in wptList.EdgesFrom(currentWptIndex))
            {
                var wptData     = findRouteData.WaypointData;
                var edge        = wptList.GetEdge(edgeIndex);
                int index       = edge.ToNodeIndex;
                var countryCode = wptList[index].CountryCode;

                if (WptWithinRange(findRouteData, index, regionPara) &&
                    avoidedCountry.Contains(countryCode) == false)
                {
                    double newDis = currentDis + GetEdgeDistance(edge);

                    if (wptData[index].CurrentDistance == double.PositiveInfinity)
                    {
                        // The node was never touched.
                        unvisited.Add(index, newDis);
                        wptData[index] = new RouteFindingData.WaypointStatus(
                            edge,
                            newDis,
                            InRange.Yes);
                    }
                    else if (unvisited.ContainsKey(index) && newDis < unvisited[index])
                    {
                        unvisited.ChangeValue(index, newDis);
                        wptData[index] = new RouteFindingData.WaypointStatus(
                            edge,
                            newDis,
                            InRange.Yes);
                    }
                }
            }
        }