MTreeBookmark(SDictBookmark <Variant, Variant> outer, SList <TreeInfo <K> > info,
               bool changed, MTreeBookmark <K>?inner, Bookmark <ValueTuple <long, bool> >?pmk,
               int pos, SCList <Variant>?key = null) : base(pos)
 {
     _outer = outer; _info = info; _changed = changed;
     _inner = inner; _pmk = pmk; _filter = key ?? SCList <Variant> .Empty;
 }
        protected SMTree <K> Remove(SCList <Variant> k, long p)
        {
            SITree?st = _impl;

            if (!Contains(k) || _impl == null)
            {
                return(this);
            }
            var     k0 = k.element;
            Variant tv = _impl.Lookup(k0);
            var     nc = Length;

            switch (tv.variant)
            {
            case Variants.Compound:
            {
                var mt = (SMTree <K>)tv.ob;
                var c  = mt.Length;
                mt  = mt.Remove((SCList <Variant>)k.next, p) as SMTree <K>;     // not null
                nc -= c - mt.Length;
                if (mt.Length == 0)
                {
                    st = st?.Remove(k0);
                }
                else
                {
                    st = st?.Update(k0, new Variant(Variants.Compound, mt));
                }
                break;
            }

            case Variants.Partial:
            {
                var bt = (SDict <long, bool>)tv.ob;
                if (!bt.Contains(p))
                {
                    return(this);
                }
                nc--;
                bt = bt - p;
                if (bt.Length == 0)
                {
                    st = st?.Remove(k0);
                }
                else
                {
                    st = st?.Update(k0, new Variant(Variants.Partial, bt));
                }
                break;
            }

            case Variants.Ascending:
            case Variants.Descending:
                nc--;
                st = st?.Remove(k0);
                break;
            }
            return(new SMTree <K>(_info, st, nc ?? 0));
        }
Exemple #3
0
        public new static SCList <K> New(params K[] els)
        {
            var r = Empty;

            for (var i = els.Length - 1; i >= 0; i--)
            {
                r = new SCList <K>(els[i], r);
            }
            return(r);
        }
 public bool Contains(SCList <Variant> k)
 {
     return((k.Length == 0) ?
            Length != 0 :
            (_impl?.Lookup(k.element) is Variant v) ?
            ((v.variant == Variants.Compound) ?
             ((SMTree <K>)v.ob).Contains((SCList <Variant>)k.next) :   // not null
             true) :
            false);
 }
        static STransaction Rdc(STransaction tr, SIndex ix, SCList <Variant> _key)
        {
            if (_key.Length == 0)
            {
                return(tr + ix.table);
            }
            var mb = ix.rows.PositionAt(_key);

            if (mb == null)
            {
                return(tr);
            }
            if (mb.hasMore(tr, ix.cols.Length ?? 0))
            {
                return(tr + ix.table);
            }
            return(tr + mb.Value.Item2);
        }
        public static MTreeBookmark <K>?New(SMTree <K> mt, SCList <Variant>?key)
        {
            if (key == null || key.Length == 0)
            {
                return(New(mt));
            }
            var outer = mt._impl?.PositionAt(key.element) as SDictBookmark <Variant, Variant>;

            if (outer == null)
            {
                return(null);
            }
            var ov = outer.Value.Item2;

            switch (ov.variant)
            {
            case Variants.Compound:
                if ((ov.ob as SMTree <K>)?.PositionAt((SCList <Variant>)key.next) is MTreeBookmark <K> inner)  // next not null
                {
                    return(new MTreeBookmark <K>(outer, mt._info, true, inner, null, 0, key));
                }
                break;

            case Variants.Partial:
                if ((ov.ob as SDict <long, bool>)?.First() is Bookmark <ValueTuple <long, bool> > pmk)
                {
                    return(new MTreeBookmark <K>(outer, mt._info, true, null, pmk, 0, key));
                }
                break;

            case Variants.Ascending:
            case Variants.Descending:
                if (key.next.Length == 0)
                {
                    return(new MTreeBookmark <K>(outer, mt._info, true, null, null, 0, key));
                }
                break;
            }
            return(null);
        }
 public IndexRowSet(STransaction tr, STable t, SIndex ix, SCList <Variant> key, SList <Serialisable> wh)
     : base(Rdc(tr, ix, key), t, SDict <long, SFunction> .Empty, t.rows.Length)
 {
     _ix     = ix; _key = key; _wh = wh;
     _unique = key.Length == _ix.cols.Length;
 }
Exemple #8
0
 public SCList(K el, SCList <K> nx) : base(el, nx)
 {
 }
Exemple #9
0
 internal SCListBookmark(SCList <K> s, int p = 0) : base(s, p)
 {
     _s = s;
 }
        protected SMTree <K> Add(SCList <Variant> k, long v)
        {
            var r = Add(k, v, out TreeBehaviour tb);

            return((tb == TreeBehaviour.Allow)?r:throw new Exception("Duplicate key"));
        }
        public SMTree <K> Add(SCList <Variant> k, long v, out TreeBehaviour tb)
        {
            if (k == null)
            {
                if (_info.element.onNullKey != TreeBehaviour.Allow)
                {
                    tb = _info.element.onNullKey;
                    return(this);
                }
                k = SCList <Variant> .Empty;
            }
            if (Contains(k) && _info.element.onDuplicate != TreeBehaviour.Allow)
            {
                tb = _info.element.onDuplicate;
                return(this);
            }
            if (_impl == null)
            {
                tb = TreeBehaviour.Allow;
                return(new SMTree <K>(_info, k, v));
            }
            Variant nv;
            SITree  st = _impl;

            if (st.Contains(k.element))
            {
                Variant tv = st.Lookup(k.element);
                switch (tv.variant)
                {
                case Variants.Compound:
                    nv = new Variant(Variants.Compound, (SMTree <K>)tv.ob + ((SCList <Variant>)k.next, v));   // care: immutable
                    break;

                case Variants.Partial:
                    nv = new Variant(Variants.Partial, (SDict <long, bool>)tv.ob + (v, true));    // care: immutable
                    break;

                default:
                    throw new Exception("internal error");
                }
                st = _impl.Update(k.element, nv) ?? throw new Exception("Impossible");
            }
            else
            {
                switch (st.variant)
                {
                case Variants.Compound:
                    nv = new Variant(Variants.Compound, new SMTree <K>(_info.next, (SCList <Variant>)k.next, v));   // these are not null);
                    break;

                case Variants.Partial:
                    nv = new Variant(Variants.Partial, new SDict <long, bool>(v, true));
                    break;

                case Variants.Ascending:
                case Variants.Descending:
                    if (_info.element.onDuplicate == TreeBehaviour.Allow)
                    {
                        goto case Variants.Partial;
                    }
                    nv = new Variant(v);
                    break;

                default:     // assure VS that nv has been assigned!
                    nv = new Variant(0);
                    break;
                }
                st = (SITree)(_impl + (k.element, nv));
            }
            tb = TreeBehaviour.Allow;
            return(new SMTree <K>(_info, st, (Length ?? 0) + 1));
        }
        public SMTree <K> Add(long v, params Variant[] k)
        {
            var r = Add(SCList <Variant> .New(k), v, out TreeBehaviour tb);

            return((tb == TreeBehaviour.Allow) ? r : throw new Exception(tb.ToString()));
        }
 public MTreeBookmark <K>?PositionAt(SCList <Variant>?k)
 {
     return(MTreeBookmark <K> .New(this, k));
 }