예제 #1
0
        /// <summary>
        /// <code>
        /// sigo.Get("user/name") => sigo.Get1("user").Get1("name")
        /// sigo.Get("user") => sigo.Get1("user")
        /// sigo.Get("/") => sigo
        /// </code>
        /// </summary>
        public static ISigo Get(ISigo sigo, string path)
        {
            if (IsLooped(sigo))
            {
                return(sigo);
            }

            if (string.IsNullOrEmpty(path))
            {
                return(sigo);
            }

            if (!path.Contains('/'))
            {
                return(sigo.Get1(path));
            }

            var keys = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var key in keys)
            {
                sigo = sigo.Get1(key);
                if (IsLooped(sigo))
                {
                    return(sigo);
                }
            }

            return(sigo);
        }
예제 #2
0
        /// <summary>
        /// try to return part of a if a is frozen
        /// try to return part of b if b is frozen
        /// return new sigo
        /// </summary>
        public static ISigo Merge(ISigo a, ISigo b)
        {
            ISigo r;

            if (b is SigoLeaf)
            {
                r = b;
                return(Select(r, a, b));
            }

            if (a is SigoLeaf)
            {
                if ((b.Flags & Bits.M) == 0)
                {
                    r = a;

                    return(Select(r, a, b));
                }

                r = Merge(Sigo.Create(Bits.LMR), b);
                return(Select(r, a, b));
            }

            r = Sigo.Create(Bits.Proton(a.Flags | b.Flags));
            var keys = a.Keys.Union(b.Keys);

            foreach (var key in keys)
            {
                r = r.Set1(key, Merge(a.Get1(key), b.Get1(key)));
            }

            return(Select(r, a, b));
        }
예제 #3
0
        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)));
            }
            }
        }
예제 #4
0
        public static bool Equals(ISigo a, ISigo b)
        {
            if (ReferenceEquals(a, b))
            {
                return(true);
            }

            if (Bits.IsSame(a.Flags, b.Flags) == false)
            {
                return(false);
            }

            return(Bits.IsLeaf(a.Flags)
                ? Equals(a.Data, b.Data)
                : a.All(e => Equals(e.Value, b.Get1(e.Key))));
        }