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); }
public DeletionMarker <Action <T> > Subscribe(Action <T> cb) => callbacks.Add(cb);