public static ForeignKeyViolationException TernaryUnary(string fromRelvar, int column, string toRelvar, Obj[] fromTuple, Obj toArg) { ForeignKeyType type = new TernaryUnaryForeignKeyType(column); Obj[] toTuple = toArg != null ? new Obj[] { toArg } : null; return(new ForeignKeyViolationException(type, fromRelvar, toRelvar, fromTuple, toTuple)); }
public void NeTernRelObj(NeTernRelObj obj) { Obj[] col1 = obj.Col1(); Obj[] col2 = obj.Col2(); Obj[] col3 = obj.Col3(); int len = col1.Length; writer.Write('['); if (IsMultiline(obj)) { writer.Indent(); if (writer.IsNewLine()) { writer.Write(' '); } else { writer.NewLine(); } for (int i = 0; i < len; i++) { Obj arg1 = col1[i]; Obj arg2 = col2[i]; Obj arg3 = col3[i]; bool multiline = IsMultiline(arg1) || IsMultiline(arg2) || IsMultiline(arg3); arg1.Visit(this); writer.Write(","); if (multiline) { writer.NewLine(); } else { writer.Write(' '); } arg2.Visit(this); writer.Write(","); if (multiline) { writer.NewLine(); } else { writer.Write(' '); } arg3.Visit(this); if (i == 0 | i < len - 1) { writer.Write(";"); } writer.NewLine(); } writer.UnindentedNewLine(); } else { for (int i = 0; i < len; i++) { if (i > 0) { writer.Write("; "); } col1[i].Visit(this); writer.Write(", "); col2[i].Visit(this); writer.Write(", "); col3[i].Visit(this); } if (len == 1) { writer.Write(';'); } } writer.Write(']'); }
//////////////////////////////////////////////////////////////////////////// private void ConsumeSize(Obj obj, int size) { lastVisitedObjSize = size; }
public static void PrintNoFlush(Obj obj, DataWriter writer) { ObjPrinter printer = new ObjPrinter(writer, new HashSet <Obj>()); obj.Visit(printer); }
public static bool PrintSizeFits(Obj obj, int maxSize) { return(!Multiliner.IsMultiline(obj, maxSize)); }
public static int[] BinSearchRange(int[] idxs, Obj[] major, Obj[] minor, Obj majorVal, Obj minorVal) { int offset = 0; int length = major.Length; int low = offset; int high = offset + length - 1; int lowerBound = low; int upperBound = high; while (low <= high) { int mid = (int)(((long)low + (long)high) / 2); int midIdx = idxs[mid]; int ord = majorVal.QuickOrder(major[midIdx]); if (ord == 0) { ord = minorVal.QuickOrder(minor[midIdx]); } if (ord == -1) { // major[mid] > majorVal | (major[mid] == majorVal & minor[mid] > minorVal) upperBound = high = mid - 1; } else if (ord == 1) { // major[mid] < majorVal | (major[mid] == majorVal) & minor[mid] < minorVal) lowerBound = low = mid + 1; } else { bool isFirst = mid == offset; if (!isFirst) { int prevIdx = idxs[mid - 1]; isFirst = !major[prevIdx].IsEq(majorVal) || !minor[prevIdx].IsEq(minorVal); } if (isFirst) { int first = mid; low = lowerBound; high = upperBound; while (low <= high) { mid = (int)(((long)low + (long)high) / 2); midIdx = idxs[mid]; ord = majorVal.QuickOrder(major[midIdx]); if (ord == 0) { ord = minorVal.QuickOrder(minor[midIdx]); } if (ord == -1) { // major[mid] > majorVal | (major[mid] == majorVal & minor[mid] > minorVal) high = mid - 1; } else if (ord == 1) { // major[mid] < majorVal | (major[mid] == majorVal) & minor[mid] < minorVal) low = mid + 1; } else { bool isLast = mid == upperBound; if (!isLast) { int nextIdx = idxs[mid + 1]; isLast = !major[nextIdx].IsEq(majorVal) || !minor[nextIdx].IsEq(minorVal); } if (isLast) { return(new int[] { first, mid - first + 1 }); } else { low = mid + 1; } } } // We're not supposed to ever get here. throw ErrorHandler.InternalFail(); } else { high = mid - 1; } } } return(new int[] { 0, 0 }); }
public static int[] BinSearchRange(Obj[] objs, int offset, int length, Obj obj) { int first; int low = offset; int high = offset + length - 1; int lowerBound = low; int upperBound = high; while (low <= high) { int mid = (int)(((long)low + (long)high) / 2); int ord = obj.QuickOrder(objs[mid]); if (ord == -1) { upperBound = high = mid - 1; // objs[mid] > obj } else if (ord == 1) { lowerBound = low = mid + 1; // objs[mid] < obj } else { if (mid == offset || !objs[mid - 1].IsEq(obj)) { first = mid; low = lowerBound; high = upperBound; while (low <= high) { mid = (int)(((long)low + (long)high) / 2); ord = obj.QuickOrder(objs[mid]); if (ord == -1) { high = mid - 1; // objs[mid] > obj } else if (ord == 1) { low = mid + 1; // objs[mid] < obj } else { if (mid == upperBound || !objs[mid + 1].IsEq(obj)) { return new int[] { first, mid - first + 1 } } ; else { low = mid + 1; } } } // We're not supposed to ever get here. throw ErrorHandler.InternalFail(); } else { high = mid - 1; } } } return(new int[] { 0, 0 }); }
public static ForeignKeyViolationException UnarySym12Ternary(string fromRelvar, string toRelvar, Obj delArg12, Obj otherArg12, Obj arg3) { return(new ForeignKeyViolationException(UNARY_SYM_TERNARY, fromRelvar, toRelvar, new Obj[] { delArg12 }, new Obj[] { delArg12, otherArg12, arg3 })); }
public static ForeignKeyViolationException BinaryTernary(string fromRelvar, string toRelvar, Obj arg1, Obj arg2, Obj arg3) { return(new ForeignKeyViolationException(BINARY_TERNARY, fromRelvar, toRelvar, new Obj[] { arg1, arg2 }, new Obj[] { arg1, arg2, arg3 })); }
public static ForeignKeyViolationException UnarySymBinary(string fromRelvar, string toRelvar, Obj arg, Obj otherArg) { return(new ForeignKeyViolationException(UNARY_SYM_BINARY, fromRelvar, toRelvar, new Obj[] { arg }, new Obj[] { arg, otherArg })); }
////////////////////////////////////////////////////////////////////////////// public static ForeignKeyViolationException UnarySym12Ternary(string fromRelvar, string toRelvar, Obj arg) { return(new ForeignKeyViolationException(UNARY_SYM_TERNARY, fromRelvar, toRelvar, new Obj[] { arg }, null)); }
////////////////////////////////////////////////////////////////////////////// public static ForeignKeyViolationException UnaryTernary(string fromRelvar, int column, string toRelvar, Obj fromArg) { ForeignKeyType type = new UnaryTernaryForeignKeyType(column); return(new ForeignKeyViolationException(type, fromRelvar, toRelvar, new Obj[] { fromArg }, null)); }
public static ForeignKeyViolationException SymTernary3Unary(string fromRelvar, string toRelvar, Obj[] fromTuple, Obj toArg) { return(TernaryUnary(fromRelvar, 3, toRelvar, fromTuple, toArg)); }
public static ForeignKeyViolationException SymTernary12Unary(string fromRelvar, string toRelvar, Obj[] fromTuple, Obj toArg) { return(new ForeignKeyViolationException(SYM_TERNARY_UNARY, fromRelvar, toRelvar, fromTuple, new Obj[] { toArg })); }
protected abstract Obj CreateTaggedObj(ushort tagId, Obj obj);
public static void Print_P(Obj str, object env) { IO.StdOutWrite(str.GetString()); }
public static int BinSearch(Obj[] objs, Obj obj) { return(BinSearch(objs, 0, objs.Length, obj)); }
public static void Exit_P(Obj code, object env) { IO.Exit((int)code.GetLong()); }
static void SortIdxs(int[] indexes, int first, int last, Obj[] ord1, Obj[] ord2, Obj[] ord3) { if (first >= last) { return; } int pivotIdx = first + (last - first) / 2; int pivot = indexes[pivotIdx]; Obj pivotOrd1 = ord1[pivot]; Obj pivotOrd2 = ord2[pivot]; Obj pivotOrd3 = ord3[pivot]; if (pivotIdx > first) { indexes[pivotIdx] = indexes[first]; } // indexes[first] = pivot; // Not necessary int low = first + 1; int high = last; while (low <= high) { while (low <= last) { int idx = indexes[low]; int ord = ord1[idx].QuickOrder(pivotOrd1); if (ord == 0) { ord = ord2[idx].QuickOrder(pivotOrd2); } if (ord == 0) { ord = ord3[idx].QuickOrder(pivotOrd3); } if (ord > 0) // Including all elements that are lower or equal than the pivot { break; } else { low++; } } // <low> is now the lowest index that does not contain a value that is // lower or equal than the pivot. It may be outside the bounds of the array while (high >= first) { int idx = indexes[high]; int ord = ord1[idx].QuickOrder(pivotOrd1); if (ord == 0) { ord = ord2[idx].QuickOrder(pivotOrd2); } if (ord == 0) { ord = ord3[idx].QuickOrder(pivotOrd3); } if (ord <= 0) // Including only elements that are greater than the pivot { break; } else { high--; } } // <high> is not the highest index that does not contain an element that // is greater than the pivot. It may be outside the bounds of the array Debug.Assert(low != high); if (low < high) { int tmp = indexes[low]; indexes[low] = indexes[high]; indexes[high] = tmp; low++; high--; } } if (low - 1 > first) { indexes[first] = indexes[low - 1]; } indexes[low - 1] = pivot; if (low - 2 > first) { SortIdxs(indexes, first, low - 2, ord1, ord2, ord3); } if (high < last) { SortIdxs(indexes, high + 1, last, ord1, ord2, ord3); } }
public static string ExportAsText(Obj obj) { return(obj.ToString()); }
private void Record(NeBinRelObj obj) { Obj[] values = obj.Col2(); int len = values.Length; ushort[] labels; if (obj is RecordObj) { RecordObj recObj = (RecordObj)obj; labels = recObj.fieldIds; } else { labels = new ushort[len]; Obj[] fields = obj.Col1(); for (int i = 0; i < len; i++) { labels[i] = fields[i].GetSymbId(); } } writer.Write('('); if (IsMultiline(obj)) { int maxLabelLen = 0; for (int i = 0; i < len; i++) { int labelLen = Cell.Runtime.SymbObj.IdxToStr(labels[i]).Length; if (labelLen > maxLabelLen) { maxLabelLen = labelLen; } } int[] idxs = SortedIdxs(labels, values); writer.Indent(); if (writer.IsNewLine()) { writer.Write(' '); } else { writer.NewLine(); } for (int i = 0; i < len; i++) { int idx = idxs[i]; string label = Cell.Runtime.SymbObj.IdxToStr(labels[idx]); writer.Write(label); writer.Write(':'); Obj value = values[idx]; if (IsMultiline(value)) { writer.IndentedNewLine(); value.Visit(this); writer.Unindent(); } else { writer.WriteSpaces(maxLabelLen - label.Length + 1); value.Visit(this); } if (i < len - 1) { writer.Write(','); } else { writer.Unindent(); } writer.NewLine(); } } else { for (int i = 0; i < len; i++) { if (i > 0) { writer.Write(", "); } writer.Write(Cell.Runtime.SymbObj.IdxToStr(labels[i])); writer.Write(": "); values[i].Visit(this); } } writer.Write(')'); }
public static DateTime ObjToDate(Obj date) { long epochDay = date.GetInnerLong(); return(epoch.AddDays(epochDay)); }
private void Map(NeBinRelObj obj) { Obj[] col1 = obj.Col1(); Obj[] col2 = obj.Col2(); int len = col1.Length; writer.Write('['); if (IsMultiline(obj)) { writer.Indent(); if (writer.IsNewLine()) { writer.Write(' '); } else { writer.NewLine(); } for (int i = 0; i < len; i++) { Obj arg1 = col1[i]; Obj arg2 = col2[i]; arg1.Visit(this); writer.Write(" ->"); if (IsMultiline(arg2)) { writer.IndentedNewLine(); arg2.Visit(this); writer.Unindent(); } else { writer.Write(' '); arg2.Visit(this); } if (i < len - 1) { writer.Write(','); } else { writer.Unindent(); } writer.NewLine(); } } else { for (int i = 0; i < len; i++) { if (i > 0) { writer.Write(", "); } col1[i].Visit(this); writer.Write(" -> "); col2[i].Visit(this); } } writer.Write(']'); }
public static DateTime ObjToDateTime(Obj time) { long epochNanoSecs = time.GetInnerLong(); return(epoch.AddTicks(epochNanoSecs / 100)); }
//////////////////////////////////////////////////////////////////////////// private bool IsMultiline(Obj obj) { return(multilineObjs.Contains(obj)); }
public static void Trace(string msg, string var1Name, Obj obj1, string var2Name, Obj obj2) { if (debugMode) { ErrWriteLine(msg); DumpVar(var1Name, obj1); DumpVar(var2Name, obj2); } }
public static bool IsMultiline(Obj obj, int maxLineLen) { Multiliner multiliner = new Multiliner(obj, true, maxLineLen, null); return(multiliner.done); }
//////////////////////////////////////////////////////////////////////////////// Obj ParseSymbOrTaggedObj() { ushort symbId = ReadSymbol(); if (!TryConsumingOpenPar()) { return(SymbObj.Get(symbId)); } TokenType type = PeekType(); Obj firstValue = null; if (type == TokenType.Int) { long value = ReadLong(); if (TryConsumingClosePar()) { return(Builder.CreateTaggedIntObj(symbId, value)); } // Here we've consumed the opening parenthesis and the integer // Since the opening parenthesis was not follow by a label, // we're dealing with a sequence, possibly a sequence of integers //## OPTIMIZE FOR SEQUENCES OF INTEGERS firstValue = IntObj.Get(value); } else if (type == TokenType.Symbol) { ushort labelId = TryReadingLabel(); if (labelId != SymbObj.InvalidSymbId) { return(CreateTaggedObj(symbId, ParseRec(labelId))); } firstValue = ParseObj(); } else { firstValue = ParseObj(); } if (TryConsumingClosePar()) { return(CreateTaggedObj(symbId, firstValue)); } Obj[] elts = new Obj[16]; elts[0] = firstValue; int i = 1; while (TryConsumingComma()) { if (i >= elts.Length) { elts = Array.Extend(elts, 2 * elts.Length); } elts[i++] = ParseObj(); } ConsumeClosePar(); return(CreateTaggedObj(symbId, Builder.CreateSeq(elts, i))); }
////////////////////////////////////////////////////////////////////////////// public override int InternalOrder(Obj other) { throw ErrorHandler.InternalFail(this); }
public static ForeignKeyViolationException SymBinarySymTernary(string fromRelvar, string toRelvar, Obj arg1, Obj arg2, Obj arg3) { Obj[] fromTuple = new Obj[] { arg1, arg2 }; Obj[] toTuple = new Obj[] { arg1, arg2, arg3 }; return(new ForeignKeyViolationException(SYM_BINARY_SYM_TERNARY, fromRelvar, toRelvar, fromTuple, toTuple)); }