public ComparisonResult(IImmutableArray <T> before, IImmutableArray <T> after, int cost, SesCollection <T> ses) { Before = before; After = after; Cost = cost; Ses = ses; }
public override bool Equals(object obj) { IImmutableArray other = obj as IImmutableArray; if (other != null) { return(this.array == other.Array); } return(false); }
public void SetOnInterface() { var source = new[] { 1, 4, 5 }; IImmutableArray <int> arrayInterface = ImmutableArray.Create(source); arrayInterface = arrayInterface.Set(1, 6); Assert.AreEqual(1, arrayInterface[0]); Assert.AreEqual(6, arrayInterface[1]); Assert.AreEqual(5, arrayInterface[2]); Assert.AreEqual(1, source[0]); Assert.AreEqual(4, source[1]); Assert.AreEqual(5, source[2]); }
internal (int cost, SesCollection <T> ses) CalcCost(IImmutableArray <T> before, IImmutableArray <T> after) { var m = before.Length; var n = after.Length; var max = m + n; var v = new int[max * 2 + 1]; var pos = new int[max * 2 + 1]; var epc = new List <(int prev, int x, int y)>(); var offset = max; // initial value of p when cost == 0 && k == 0 pos[1 + offset] = -1; for (int cost = 0; cost <= max; cost++) { for (int k = -cost; k <= cost; k += 2) { int y; var ym1 = v[k - 1 + offset] + 1; var yp1 = v[k + 1 + offset]; var pm1 = pos[k - 1 + offset]; var pp1 = pos[k + 1 + offset]; int p; if (k == -cost) { y = yp1; p = pp1; } else if (k == cost) { y = ym1; p = pm1; } else if (ym1 < yp1) { y = yp1; p = pp1; } else { y = ym1; p = pm1; } var x = y - k; while (x < m && y < n && Compare(before[x], after[y])) { ++x; ++y; } pos[k + offset] = epc.Count; epc.Add((p, x, y)); v[k + offset] = y; if (x >= m && y >= n) { var ses = CalcSes(before, after, epc); return(cost, ses); } } } throw new NotImplementedException(); }