public static MTreeBookmark <K>?New(SMTree <K> mt) { for (var outer = mt._impl?.First() as SDictBookmark <Variant, Variant>; outer != null; outer = outer.Next() as SDictBookmark <Variant, Variant> ) { var ov = outer.Value.Item2; switch (ov.variant) { case Variants.Compound: if ((ov.ob as SMTree <K>)?.First() is MTreeBookmark <K> inner) { return(new MTreeBookmark <K>(outer, mt._info, false, inner, null, 0)); } 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, false, null, pmk, 0)); } break; case Variants.Ascending: case Variants.Descending: return(new MTreeBookmark <K>(outer, mt._info, false, null, null, 0)); } } return(null); }
public OrderedRowSet(RowSet sce, SSelectStatement sel, Context cx) : base(sce._tr, sel, sce._aggregates, sce.Length) { _sce = sce; var ti = SList <TreeInfo <Serialisable> > .Empty; int n = 0; for (var b = sel.order.First(); b != null; b = b.Next()) { ti = ti + (new TreeInfo <Serialisable>(b.Value, 'A', 'D', !b.Value.desc), n++); } var t = new SMTree <Serialisable>(ti); var r = SDict <int, SRow> .Empty; int m = 0; for (var b = sce.First() as RowBookmark; b != null; b = b.Next() as RowBookmark) { var k = new Variant[n]; var i = 0; for (var c = sel.order.First(); c != null; c = c.Next()) { k[i] = new Variant(c.Value.col.Lookup(new Context(b, cx)), !c.Value.desc); } t = t.Add(m, k); r += (m++, b._ob); } _tree = t; _rows = r; }
/// <summary> /// A primary or unique index /// </summary> /// <param name="t"></param> /// <param name="c"></param> public SIndex(STransaction tr, long t, bool p, SList <long> c) : base(Types.SIndex, tr) { table = t; primary = p; cols = c; rows = new SMTree(Info((STable)tr.objects.Lookup(table), cols)); }
public SIndex(STransaction tr, SIndex x, AStream f) : base(x, f) { table = tr.Fix(x.table); long[] c = new long[x.cols.Length]; var i = 0; for (var b = x.cols.First(); b != null; b = b.Next()) { c[i++] = tr.Fix(b.Value); } cols = SList <long> .New(c); rows = x.rows; }
SIndex(SDatabase d, AStream f) : base(Types.SIndex, f) { table = f.GetLong(); var n = f.ReadByte(); var c = new long[n]; for (var i = 0; i < n; i++) { c[i] = f.GetInt(); } cols = SList <long> .New(c); rows = new SMTree(Info((STable)d.objects.Lookup(table), cols)); }
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 OrderedRowSet(RowSet sce, SList <TreeInfo <Serialisable> > ti, Context cx) : base(sce._tr, sce._qry, sce._aggregates, null) { _sce = sce; var t = new SMTree <Serialisable>(ti); var r = SDict <int, SRow> .Empty; int m = 0; for (var b = sce.First() as RowBookmark; b != null; b = b.Next() as RowBookmark) { var k = new Variant[ti.Length.Value]; var i = 0; for (var c = ti.First(); c != null; c = c.Next()) { k[i] = new Variant(c.Value.headName.Lookup(new Context(b, cx))); } t = t.Add(m, k); r += (m++, b._ob); } _tree = t; _rows = r; }
static void Main(string[] args) { // Tests for SList (unordered list) var sl = SList <string> .New("Red", "Blue", "Green"); sl = sl.InsertAt("Yellow", 0); var s2 = sl; sl = sl.RemoveAt(3); sl = sl.UpdateAt("Pink", 1); sl = sl.InsertAt("Orange", 2); Check <string>(sl.ToArray(), "Yellow", "Pink", "Orange", "Blue"); Check <string>(s2.ToArray(), "Yellow", "Red", "Blue", "Green"); Console.WriteLine("SList done"); // Tests for SArray var sa = new SArray <string>("Red", "Blue", "Green"); sa = sa.InsertAt(0, "Yellow"); sa = sa.RemoveAt(3); var sb = sa; sa = sa.InsertAt(2, "Orange", "Violet"); Check(sa.ToArray(), "Yellow", "Red", "Orange", "Violet", "Blue"); Check(sb.ToArray(), "Yellow", "Red", "Blue"); Console.WriteLine("SArray done"); // Tests for SSearchTree<string> var ss = SSearchTree <string> .New("InfraRed", "Red", "Orange", "Yellow", "Green", "Blue", "Violet"); Check(ss.ToArray(), "Blue", "Green", "InfraRed", "Orange", "Red", "Violet", "Yellow"); var si = SSearchTree <int> .New(56, 22, 24, 31, 23); Check(si.ToArray(), 22, 23, 24, 31, 56); Console.WriteLine("SSearchTree done"); // Tests for SDict var sd = SDict <string, string> .Empty; sd = sd.Add("Y", "Yellow"); sd = sd.Add("G", "Green"); sd = sd.Add("B", "Blue"); sd = sd.Remove("G"); var sr = new string[sd.Count]; var j = 0; for (var b = sd.First(); b != null; b = b.Next()) { sr[j++] = b.Value.key + ": " + b.Value.val; } Check(sr, "B: Blue", "Y: Yellow"); Console.WriteLine("SDict done"); // Tests for SMTree var ti = SList <TreeInfo> .Empty; ti = ti.InsertAt(new TreeInfo("0", 'D', 'D'), 0); // onDuplicate must be Disallow on all except last entry ti = ti.InsertAt(new TreeInfo("1", 'A', 'A'), 1); var sm = new SMTree(ti); var test = new string[] { "BALTIM", "ANNU", "A", "ANNO", "BALTIC", "BRAIL" }; for (var i = 0; i < test.Length; i++) { sm = Add(sm, test[i], i); } var sorted = new string[test.Length]; j = 0; for (var b = sm.First(); b != null; b = b.Next()) { sorted[j++] = test[((MTreeBookmark)b).value()]; } // we are only sorting on the first two letters! // Check() we should offer some alternatives here Check(sorted, "A", "ANNU", "ANNO", "BALTIM", "BALTIC", "BRAIL"); Console.WriteLine("SMTree done"); File.Delete("strong"); File.Create("strong").Close(); var d = SDatabase.Open("strong"); var tr = new STransaction(d); tr = new STransaction(tr, new SString("This is Strong")); new STable(tr, "tbl"); var c = tr.Commit(); d.Close(); d = SDatabase.Open("strong"); Console.WriteLine(d.objects.First().Value.val.ToString()); Console.ReadKey(); }
static SMTree Add(SMTree t, string s, int i) { return(t.Add(i, V(s, 0), V(s, 1))); }
internal SIndex(SIndex x, long t, SList <long> c) : base(x) { table = t; cols = c; primary = x.primary; rows = x.rows; }