static void SetContainmentTest() { var set = new ChangeableSet <int> { 1, 2, 3, 4 }; var greater1 = from i in set where i > 1 select i; var contains5 = greater1.ContainsMod(5); var contains2And4 = greater1.ContainsAll(2, 4); Report.Begin("set = {1,2,3,4}"); greater1.UnsafeRegisterCallbackNoGcRoot(deltas => { foreach (var d in deltas) { if (d.Count > 0) { Report.Line("add {0}", d.Value); } else { Report.Line("rem {0}", d.Value); } } }); contains5.UnsafeRegisterCallbackNoGcRoot(c => Report.Line("contains 5 = {0}", c)); contains2And4.UnsafeRegisterCallbackNoGcRoot(c => Report.Line("contains [2,4] = {0}", c)); Report.End(); Report.Begin("set = {1,2,3,4,5,6}"); using (Adaptive.Transaction) { set.Add(5); set.Add(6); } Report.End(); Report.Begin("set = {2,4,6}"); using (Adaptive.Transaction) { set.Remove(1); set.Remove(3); set.Remove(5); } Report.End(); Report.Begin("set = {4,6}"); using (Adaptive.Transaction) { set.Remove(2); } Report.End(); Report.Begin("set = {4,5,6}"); using (Adaptive.Transaction) { set.Add(5); } Report.End(); }
static void AdvancedASetTest() { Action <IOpReader <hrefset <int>, hdeltaset <int> > > print = (r) => { var deltas = r.GetOperations(); var content = r.State; var deltaStr = deltas.Select(d => d.Count > 0 ? string.Format("Add {0}", d.Value) : string.Format("Rem {0}", d.Value)).Join(", "); var contentStr = content.OrderBy(a => a).Select(i => i.ToString()).Join(", "); Report.Line("deltas = [{0}]", deltaStr); Report.Line("content = [{0}]", contentStr); }; var i0 = new ChangeableSet <int> { 1, 2, 3 }; var i1 = new ChangeableSet <int> { 4, 5 }; var i2 = new ChangeableSet <int> { 6, 7 }; var input = new ChangeableSet <IAdaptiveSet <int> > { i0, i1 }; var flat = input.SelectMany(a => a); Report.Begin("initial"); var reader = flat.GetReader(); print(reader); Report.End(); Report.Begin("add i2; i1.rem 4"); Report.Line("all changes (inner and outer) shall be seen consistently"); using (Adaptive.Transaction) { input.Add(i2); i1.Remove(4); } print(reader); Report.End(); Report.Begin("rem i0; i0.add 10"); Report.Line("the set shall not see the (Add 10) operation since i0 was removed as a whole"); using (Adaptive.Transaction) { input.Remove(i0); i0.Add(10); } print(reader); Report.End(); Report.Begin("add i0; i0.rem 10"); Report.Line("the set shall not see the (Add 10) operation since 10 was removed from i0"); using (Adaptive.Transaction) { input.Add(i0); i0.Remove(10); } print(reader); Report.End(); reader.Dump(); }