Beispiel #1
0
        public void TestPriorityQueue()
        {
            IComparer <int> comparer_value = new ComparerNatural <int>();

            Assert.AreEqual(1, comparer_value.Compare(5, -1));
            IComparer <int> comparer_index = new ComparerArrayIndex <int>(new ComparerNatural <int>(), new int[] { 5, -1 });

            Assert.AreEqual(1, comparer_index.Compare(0, 1));

            int[] values = new int[] { 0, 1, 1, 2, -5, 6, 7, 7, 19, -20 };
            PriorityQueueC5 <int> queue = new PriorityQueueC5 <int>(new ComparerArrayIndex <int>(new ComparerNatural <int>(), values));

            queue.Enqueue(0);
            queue.Enqueue(4);
            queue.Enqueue(8);
            Assert.AreEqual(8, queue.DequeueLast());
            Assert.AreEqual(0, queue.DequeueLast());
            Assert.AreEqual(4, queue.DequeueLast());
            queue.Enqueue(4);
            queue.Enqueue(4);
            queue.Enqueue(8);
            queue.Enqueue(4);
            queue.Enqueue(9);
            Assert.AreEqual(8, queue.DequeueLast());
            Assert.AreEqual(4, queue.DequeueLast());
            Assert.AreEqual(4, queue.DequeueLast());
            Assert.AreEqual(4, queue.DequeueLast());
            Assert.AreEqual(9, queue.DequeueLast());
        }
        public IMaxTree <ElementType> BuildMaxTree(ElementType[] element_array, IComparer <ElementType> element_value_comparer, ITopologyElement topology, int real_element_count, IProgressReporter reporter)
        {
            this.d_element_array        = element_array;
            this.element_value_comparer = element_value_comparer;
            this.element_index_comparer = new ComparerArrayIndex <ElementType>(element_value_comparer, element_array);

            this.d_topology = topology;
            this.d_reporter = reporter;

            this.d_done = 0;
            this.d_elements_to_queued    = new bool[d_element_array.Length];
            this.d_neigbor_element_array = new int[d_topology.MaximumConnectivity];
            this.d_fringe          = new PriorityQueueC5 <int>(element_index_comparer);
            this.d_component_stack = new Stack <Tuple <ElementType, IList <int>, IList <MaxTreeNode <ElementType> > > >();



            d_fringe.Enqueue(0);
            d_elements_to_queued[0] = true;
            // Build tree
            while (d_fringe.Count != 0)
            {
                Process(d_fringe.PeekLast());
            }
            Tuple <ElementType, IList <int>, IList <MaxTreeNode <ElementType> > > component = d_component_stack.Pop();
            MaxTreeNode <ElementType> bottom_level_node = new MaxTreeNode <ElementType>(component.Item1, component.Item2, component.Item3, element_value_comparer);

            return(new MaxTree <ElementType>(bottom_level_node, d_element_array.Length, real_element_count, element_value_comparer));
        }
 private void AddNeigborsToFringe(int element_index)
 {
     d_topology.ElementNeighboursRBA(element_index, d_neigbor_element_array);
     foreach (int neigbor_element_index in d_neigbor_element_array)
     {
         if (neigbor_element_index != -1)
         {
             if (!d_elements_to_queued[neigbor_element_index])
             {
                 //Console.WriteLine("Enqueue" + neigbor_element_index);
                 d_fringe.Enqueue(neigbor_element_index);
                 d_elements_to_queued[neigbor_element_index] = true;
                 if (this.element_index_comparer.Compare(element_index, neigbor_element_index) == -1)// HOOK
                 {
                     return;
                 }
             }
         }
     }
 }