Beispiel #1
0
        static void time_dynamic_pq(int MAXID, int MAXCOUNT, int mod, int rounds, LocalProfiler profiler)
        {
            profiler.Start("dynam_all");

            profiler.Start("dynam_initialize");
            DynamicPriorityQueue <TestDynamicNode> PQ_Dynamic   = new DynamicPriorityQueue <TestDynamicNode>();
            MemoryPool <TestDynamicNode>           Dynamic_Pool = new MemoryPool <TestDynamicNode>();
            SparseObjectList <TestDynamicNode>     IDMap        = new SparseObjectList <TestDynamicNode>(MAXID, MAXCOUNT);

            profiler.StopAndAccumulate("dynam_initialize");

            for (int ri = 0; ri < rounds; ++ri)
            {
                profiler.Start("dynam_push");

                int count = 0;
                int id    = 0;
                while (count < MAXCOUNT)
                {
                    id = (id + mod) % MAXID;
                    TestDynamicNode node = new TestDynamicNode(); //Dynamic_Pool.Allocate();
                    //node.Initialize(id);
                    node.id = id;
                    PQ_Dynamic.Enqueue(node, count);
                    IDMap[id] = node;
                    count++;
                }

                profiler.StopAndAccumulate("dynam_push");
                profiler.Start("dynam_update");

                Random r = new Random(31337);
                id = 0; count = 0;
                while (count++ < MAXCOUNT)
                {
                    id = (id + mod) % MAXID;
                    float new_p = count + ((r.Next() % 1000) - 1000);
                    PQ_Dynamic.Update(IDMap[id], new_p);
                }

                profiler.StopAndAccumulate("dynam_update");
                profiler.Start("dynam_pop");

                while (PQ_Dynamic.Count > 0)
                {
                    TestDynamicNode node = PQ_Dynamic.Dequeue();
                    //if (rounds > 1)
                    //    Dynamic_Pool.Return(node);
                }

                profiler.StopAndAccumulate("dynam_pop");
            }

            //Dynamic_Pool.FreeAll();

            profiler.StopAndAccumulate("dynam_all");
        }
Beispiel #2
0
        public static void test_pq_debuggable()
        {
            int MAXID = 10;

            IndexPriorityQueue QIndex = new IndexPriorityQueue(MAXID);
            DynamicPriorityQueue <TestDynamicNode> QDynamic = new DynamicPriorityQueue <TestDynamicNode>();

            TestDynamicNode[] dyn_nodes = new TestDynamicNode[MAXID];

            bool verbose = false;

            //int n = 1;
            for (int i = 0; i < MAXID; ++i)
            {
                //n = (n + 17) % 17;
                int   id       = i;
                float priority = 1.0f - (float)i / 10.0f;
                QIndex.Enqueue(id, priority);
                if (verbose)
                {
                    System.Console.WriteLine("i = {0}", i);
                }
                QIndex.DebugPrint();
                if (verbose)
                {
                    System.Console.WriteLine("---", i);
                }
                dyn_nodes[i] = new TestDynamicNode()
                {
                    id = id
                };
                QDynamic.Enqueue(dyn_nodes[i], priority);
                QDynamic.DebugPrint();
            }

            System.Console.WriteLine("Dequeing...");


            for (int i = 0; i < MAXID; ++i)
            {
                float newp = (float)((i + MAXID / 2) % MAXID) / 10.0f;
                QIndex.Update(i, newp);
                QDynamic.Update(dyn_nodes[i], newp);
                //System.Console.WriteLine("UPDATE {0} {1}", QIndex.First, QDynamic.First.id);
                //QIndex.DebugPrint();
                //System.Console.WriteLine("---", i);
                //QDynamic.DebugPrint();
                Util.gDevAssert(QIndex.First == QDynamic.First.id);
            }


            for (int i = 0; i < MAXID; ++i)
            {
                int id   = QIndex.Dequeue();
                var node = QDynamic.Dequeue();
                Util.gDevAssert(id == node.id);
                if (verbose)
                {
                    System.Console.WriteLine("DEQUEUE {0} {1}", id, node.id);
                }

                if (verbose)
                {
                    QIndex.DebugPrint();
                }
                if (verbose)
                {
                    System.Console.WriteLine("---", i);
                }
                if (verbose)
                {
                    QDynamic.DebugPrint();
                }
            }
        }
Beispiel #3
0
        public static void test_pq()
        {
            System.Console.WriteLine("testing priority queues...");

            int MAXID    = 1000000;
            int MAXCOUNT = 100;
            int mod      = 31337;

            for (int kk = 0; kk < 3; ++kk)
            {
                if (kk == 1)
                {
                    MAXCOUNT = MAXID / 10;
                }
                else if (kk == 2)
                {
                    MAXCOUNT = MAXID;
                }

                IndexPriorityQueue PQ_Index = new IndexPriorityQueue(MAXID);
                DynamicPriorityQueue <TestDynamicNode> PQ_Dynamic   = new DynamicPriorityQueue <TestDynamicNode>();
                MemoryPool <TestDynamicNode>           Dynamic_Pool = new MemoryPool <TestDynamicNode>();
                Dictionary <int, TestDynamicNode>      DynamicNodes = new Dictionary <int, TestDynamicNode>();

                System.Console.WriteLine("inserting {0} of {1}", MAXCOUNT, MAXID);

                int count = 0;
                int id    = 0;
                while (count < MAXCOUNT)
                {
                    id = (id + mod) % MAXID;

                    PQ_Index.Enqueue(id, count);
                    TestDynamicNode node = Dynamic_Pool.Allocate();
                    node.Initialize(id);
                    PQ_Dynamic.Enqueue(node, count);
                    DynamicNodes[id] = node;
                    count++;
                }
                Util.gDevAssert(PQ_Index.IsValidQueue());
                Util.gDevAssert(PQ_Dynamic.IsValidQueue());
                Util.gDevAssert(PQ_Index.Count == PQ_Dynamic.Count);
                Util.gDevAssert(PQ_Index.First == PQ_Dynamic.First.id);
                check_same(PQ_Index, PQ_Dynamic);

                Random r = new Random(31337);

                System.Console.WriteLine("updating...");

                id = 0; count = 0;
                while (count++ < MAXCOUNT)
                {
                    id = (id + mod) % MAXID;
                    float new_p = count + ((r.Next() % 1000) - 1000);
                    PQ_Index.Update(id, new_p);
                    PQ_Dynamic.Update(DynamicNodes[id], new_p);
                }
                Util.gDevAssert(PQ_Index.IsValidQueue());
                Util.gDevAssert(PQ_Dynamic.IsValidQueue());
                check_same(PQ_Index, PQ_Dynamic);

                System.Console.WriteLine("removing...");

                while (PQ_Index.Count > 0)
                {
                    int             index_id = PQ_Index.Dequeue();
                    TestDynamicNode node     = PQ_Dynamic.Dequeue();
                    Util.gDevAssert(index_id == node.id);
                }
            }
        }