Ejemplo n.º 1
0
        public void DMCArrayPriority()
        {
            var ca = new DMCompactingArray <I>(4);

            DeletionMarker <I>[] dmi = new DeletionMarker <I> [12];
            for (int ii = 0; ii < 8; ++ii)
            {
                var x = new I(ii);
                dmi[ii] = ca.AddPriority(x, 10 - ii);
            }
            for (int ii = 0; ii < 8; ++ii)
            {
                //Inserted backwards!
                Assert.AreEqual(ca[7 - ii].x, ii);
            }
            ca.Compact();
            dmi[7].MarkForDeletion();
            dmi[6].MarkForDeletion();
            dmi[5].MarkForDeletion();
            dmi[3].MarkForDeletion();
            ca.Compact();
            Assert.AreEqual(ca.Count, 4);
            Assert.AreEqual(ca[0].x, 4);
            Assert.AreEqual(ca[1].x, 2);
            Assert.AreEqual(ca[2].x, 1);
            Assert.AreEqual(ca[3].x, 0);
            ca.AddPriority(new I(999), -1);
            Assert.AreEqual(ca[0].x, 999);
            Assert.AreEqual(ca[4].x, 0);
            ca.AddPriority(new I(555), 1000);
            Assert.AreEqual(ca[4].x, 0);
            Assert.AreEqual(ca[5].x, 555);
            ca.Empty();
            Assert.AreEqual(ca.Count, 0);
        }
Ejemplo n.º 2
0
        public void DMCArray()
        {
            var ca = new DMCompactingArray <I>(4);

            DeletionMarker <I>[] dmi = new DeletionMarker <I> [12];
            for (int ii = 0; ii < 8; ++ii)
            {
                var x = new I(ii);
                dmi[ii] = ca.Add(x);
            }
            for (int ii = 0; ii < 8; ++ii)
            {
                Assert.AreEqual(ca[ii].x, ii);
            }
            ca.Compact();
            dmi[0].MarkForDeletion();
            dmi[1].MarkForDeletion();
            dmi[2].MarkForDeletion();
            dmi[4].MarkForDeletion();
            ca.Compact();
            Assert.AreEqual(ca.Count, 4);
            Assert.AreEqual(ca[0].x, 3);
            Assert.AreEqual(ca[1].x, 5);
            Assert.AreEqual(ca[2].x, 6);
            Assert.AreEqual(ca[3].x, 7);
            dmi[8]  = ca.Add(new I(20));
            dmi[9]  = ca.Add(new I(30));
            dmi[10] = ca.Add(new I(40));
            dmi[11] = ca.Add(new I(50));
            dmi[11].MarkForDeletion();
            dmi[8].MarkForDeletion();
            dmi[3].MarkForDeletion(); //ca[0]
            ca.Compact();
            Assert.AreEqual(ca[1].x, 6);
            Assert.AreEqual(ca[3].x, 30);
            Assert.AreEqual(ca[4].x, 40);
            Assert.AreEqual(ca.Count, 5);
            ca.Empty();
            Assert.AreEqual(ca.Count, 0);
        }
Ejemplo n.º 3
0
 public Service(bool unique)
 {
     this.providers = new DMCompactingArray <T>();
     this.unique    = unique;
 }