public static ISigo SetN(ISigo sigo, IReadOnlyList <string> keys, ISigo value, int start) { switch (keys.Count - start) { case 0: return(value); case 1: return(sigo.Set1(keys[start], value)); default: { var key = keys[start]; return(sigo.Set1(key, SetN(sigo.Get1(key), keys, value, start + 1))); } } }
public static ISigo Solid(int lm1, ISigo b) { // {3} * {0, x:{3}} ISigo ret = null; // new if b not frozen or miss some lm1 if (16 + lm1 != ((16 + lm1) & b.Flags)) { ret = Sigo.Create(7 & (lm1 | b.Flags)); } foreach (var e in b) { var k = e.Key; var bk = e.Value; var rk = Solid(3, bk); if (ret != null) { ret = ret.Set1(k, rk); } else { if (ReferenceEquals(rk, bk)) { continue; } ret = Sigo.Create(7 & (lm1 | b.Flags)); foreach (var t in b) { if (t.Key != k) { ret = ret.Set1(t.Key, t.Value); } else { ret = ret.Set1(k, rk); break; } } } } return(ret ?? b); }
public void ChangeFlagsOnly() { var s0 = e0.Set1("k", e3).Freeze(); // change parent proton by adding a child with L effect var s1 = s0.Set1("k2", e4).Freeze(); SigoAssert.Equal(e3, s1.Get1("k")); SigoAssert.Equal(Bits.LM, s1.Flags & Bits.LMR); }
public void Donot_createNewObject_ifNothingChange() { var v = Sigo.From("v"); var s = e3.Set1("k", v).Freeze(); SigoAssert.Same(s, s.Set1("k", v)); SigoAssert.Same(s, s.Set1("k1", e3)); SigoAssert.Same(s, s.Set1("k1", e7)); // using Sigo.Same(), insteadOf referenceEquals SigoAssert.Same(s, s.Set1("k", Sigo.From("v"))); }
public static ISigo Set(ISigo sigo, string path, ISigo value) { if (string.IsNullOrEmpty(path)) { return(value); } if (!Paths.ShouldSplit(path)) { return(sigo.Set1(path, value)); } var keys = Paths.Split(path); return(SetN(sigo, keys, value, 0)); }
public void Return_self() { SigoAssert.Same(s, s.Set1("k", Sigo.Create(3))); }