public void UpdateColmap(RCArray <string> column, RCArray <string> format) { lock (_lock) { _colmap = _colmap.Update(column, format); } }
/// <summary> /// This method creates an identical closure where the left and right /// arguments can be accessed in user space. /// This has to be done by operators that evaluate user provided code. /// </summary> public static RCClosure UserOpClosure(RCClosure previous, RCValue code, RCArray <RCBlock> @this, RCValue left, RCValue right, bool noClimb) { left = left != null ? left : previous.Result.Get("0"); right = right != null ? right : previous.Result.Get("1"); RCBlock result = null; if (@this != null && @this.Count > 0) { result = @this[0]; // This is only for when the this context contains more than one object. // I'm not even sure whether to support this, I guess I should. // But this is not going to be the fastest solution possible. for (int i = 1; i < @this.Count; ++i) { for (int j = 0; j < @this[i].Count; ++j) { RCBlock block = @this[i].GetName(j); result = new RCBlock(result, block.Name, ":", block.Value); } } } if (left == null) { result = new RCBlock(result, "R", ":", right); } else { result = new RCBlock(result, "L", ":", left); result = new RCBlock(result, "R", ":", right); } // Passing code and @this here is important. NextParentOf will look // for the body of the executing function in that variable to detect tail calls. RCClosure replacement = new RCClosure(previous.Bot, previous.Fiber, previous.Locks, previous.Parent, previous.Code, previous.Left, result, previous.Index, code, @this, noClimb, noResolve: false); RCClosure child = new RCClosure(replacement, previous.Bot, code, previous.Left, RCBlock.Empty, 0, code, @this); return(child); }
public static long[] DoRank <T> (SortDirection direction, char typeCode, RCArray <T> array) where T : IComparable <T> { long[] indices = new long[array.Count]; for (long i = 0; i < indices.Length; ++i) { indices[i] = i; } RankStateArray <T> state = new RankStateArray <T> (array, typeCode); Comparison <long> comparison; switch (direction) { case SortDirection.asc: comparison = new Comparison <long> (state.Asc); break; case SortDirection.desc: comparison = new Comparison <long> (state.Desc); break; case SortDirection.absasc: comparison = new Comparison <long> (state.AbsAsc); break; case SortDirection.absdesc: comparison = new Comparison <long> (state.AbsDesc); break; default: throw new Exception("Unknown SortDirection: " + direction.ToString()); } Array.Sort(indices, comparison); return(indices); }
public RCValue Get(RCArray <string> name, RCArray <RCBlock> @this) { RCRefable block = this; RCValue value = null; for (int i = 0; i < name.Count; ++i) { value = block.Get(name[i]); block = value as RCRefable; if (block == null) { // if it is the last value return it if (i == name.Count - 1) { return(value); } // if not, something is wrong else { return(null); } } if (@this != null && i < name.Count - 1) { @this.Write((RCBlock)block); } } return(value); }
public static RCArray <string> ReadVectorString(RCArray <byte> array, ref int start) { // This is the count of unique elements. int count = BitConverter.ToInt32(array._source, start); start += sizeof(int); List <string> unique = new List <string> (); // In the case of strings the length contains the number of unique values. for (int i = 0; i < count; ++i) { string scalar = ReadScalarString(array, ref start); unique.Add(scalar); } // This is the count of actual elements. count = BitConverter.ToInt32(array._source, start); start += sizeof(int); string[] result = new string[count]; for (int i = 0; i < count; ++i) { int index = BitConverter.ToInt32(array._source, start); result[i] = unique[index]; start += sizeof(int); } return(new RCArray <string> (result)); }
public override RCValue Parse(RCArray <RCToken> tokens, out bool fragment, bool canonical) { fragment = false; _result = new RCCube(new Timeline()); _result.ReserveColumn("bot"); _result.ReserveColumn("fiber"); _result.ReserveColumn("module"); _result.ReserveColumn("instance"); _result.ReserveColumn("event"); _result.ReserveColumn("message"); _result.ReserveColumn("document"); for (int i = 0; i < tokens.Count; ++i) { tokens[i].Type.Accept(this, tokens[i]); } if (_bot != null) { if (_builder.Length > 0) { _document = _builder.ToString(); } AppendEntry(); } return(_result); }
public override RCValue Parse(RCArray <RCToken> tokens, out bool fragment, bool canonical) { _initialState = _state; for (int i = 0; i < tokens.Count; ++i) { tokens[i].Type.Accept(this, tokens[i]); } fragment = false; // Console.Out.WriteLine ("Done parsing. Doing cleanup ({0})", _state); FinishQuote(true); while (_values.Count > 0) { EndBlock(); } if (_run.Length > 0) { _value = new RCBlock(_value, "", ":", new RCString(_run.ToString())); } else if (_initialState == MarkdownState.Link && _value == null) { _value = new RCBlock(null, "", ":", new RCString("")); } return(_value); }
public Reader(RCCube source, ReadSpec spec, ReadCounter counter, bool forceGCol, int end) { if (source == null) { throw new ArgumentNullException("source"); } if (spec == null) { throw new ArgumentNullException("spec"); } if (counter == null) { throw new ArgumentNullException("counter"); } _source = source; _spec = spec; _counter = counter; _end = end; RCArray <string> axisCols = new RCArray <string> (source.Axis.Colset); if (forceGCol) { axisCols.Write("G"); } if (_source.Axis.Global != null && _source.Axis.Count > 0) { _initg = _source.Axis.Global[0]; } _target = new RCCube(axisCols); }
public virtual RCArray <RCToken> Lex(string code) { RCArray <RCToken> tokens = new RCArray <RCToken> (); Lex(code, tokens); return(tokens); }
public static RCOperator ReadOperator(RCActivator activator, RCArray <byte> data, ref int start) { int count = BitConverter.ToInt32(data._source, start); start += sizeof(int); RCValue left = null; RCValue right = null; string name = null; if (count == 2) { name = Binary.ReadScalarString(data, ref start); right = Binary.DoParse(activator, data, ref start); } else if (count == 3) { left = Binary.DoParse(activator, data, ref start); name = Binary.ReadScalarString(data, ref start); right = Binary.DoParse(activator, data, ref start); } else { throw new Exception("count of an operator must always be 2 or 3."); } return(activator.New(name, left, right)); }
public static void WriteVectorSymbol(RCArray <byte> result, RCArray <RCSymbolScalar> data) { Dictionary <RCSymbolScalar, int> lookup = new Dictionary <RCSymbolScalar, int> (); RCArray <RCSymbolScalar> unique = new RCArray <RCSymbolScalar> (); int index = 0; for (int i = 0; i < data.Count; ++i) { if (!lookup.ContainsKey(data[i])) { lookup.Add(data[i], index++); unique.Write(data[i]); } } WriteScalarInt(result, unique.Count); for (int i = 0; i < unique.Count; ++i) { int length = (int)unique[i].Length; WriteScalarInt(result, length); data[i].ToByte(result); } WriteScalarInt(result, data.Count); for (int i = 0; i < data.Count; ++i) { index = lookup[data[i]]; WriteScalarInt(result, index); } }
public static void WriteScalarInt(RCArray <byte> result, int val) { result.Write((byte)val); result.Write((byte)(val << 8)); result.Write((byte)(val << 16)); result.Write((byte)(val << 24)); }
protected Column(Timeline timeline, RCArray <int> index, object data) { _tlcount = timeline.Count; RCArray <T> original = (RCArray <T>)data; if (original.Locked()) { _data = new RCArray <T> (original.Count); _index = new RCArray <int> (original.Count); for (int i = 0; i < original.Count; ++i) { _data.Write(original[i]); _index.Write(index[i]); } } else { _data = (RCArray <T>)data; _index = index; } if (timeline.Has("S")) { _last = new Dictionary <RCSymbolScalar, T> (); for (int i = 0; i < _data.Count; ++i) { RCSymbolScalar key = timeline.Symbol[index[i]]; T val = _data[i]; if (_last != null) { _last[key] = val; } } } }
public static void WriteVectorString(RCArray <byte> result, RCArray <string> data) { Dictionary <string, int> lookup = new Dictionary <string, int> (); List <string> unique = new List <string> (); int index = 0; for (int i = 0; i < data.Count; ++i) { if (!lookup.ContainsKey(data[i])) { lookup.Add(data[i], index++); unique.Add(data[i]); } } int uniques = unique.Count; WriteScalarInt(result, uniques); for (int i = 0; i < unique.Count; ++i) { WriteScalarString(unique[i], result); } WriteScalarInt(result, data.Count); for (int i = 0; i < data.Count; ++i) { index = lookup[data[i]]; WriteScalarInt(result, index); } }
/// <summary> /// Array must be an RCArray. Not a native one. /// </summary> public static RCVectorBase FromArray(object array) { Type arrayType = array.GetType(); if (arrayType == typeof(RCArray <byte>)) { return(new RCByte((RCArray <byte>)array)); } else if (arrayType == typeof(RCArray <long>)) { return(new RCLong((RCArray <long>)array)); } else if (arrayType == typeof(RCArray <int>)) { RCArray <int> source = (RCArray <int>)array; RCArray <long> result = new RCArray <long> (source.Count); for (int i = 0; i < source.Count; ++i) { result.Write(source[i]); } return(new RCLong(result)); } else if (arrayType == typeof(RCArray <double>)) { return(new RCDouble((RCArray <double>)array)); } else if (arrayType == typeof(RCArray <decimal>)) { return(new RCDecimal((RCArray <decimal>)array)); } else if (arrayType == typeof(RCArray <string>)) { return(new RCString((RCArray <string>)array)); } else if (arrayType == typeof(RCArray <bool>)) { return(new RCBoolean((RCArray <bool>)array)); } else if (arrayType == typeof(RCArray <RCSymbolScalar>)) { return(new RCSymbol((RCArray <RCSymbolScalar>)array)); } else if (arrayType == typeof(RCArray <RCTimeScalar>)) { return(new RCTime((RCArray <RCTimeScalar>)array)); } else if (arrayType == typeof(RCArray <RCIncrScalar>)) { return(new RCIncr((RCArray <RCIncrScalar>)array)); } // Not sure about this... else if (arrayType == typeof(RCArray <object>)) { return(new RCLong()); } else { throw new Exception("Return values of type: " + arrayType + " are not supported."); } }
public static RCTimeScalar ReadScalarTime(RCArray <byte> array, int start) { long ticks = BitConverter.ToInt64(array._source, start); int type = BitConverter.ToInt32(array._source, start + 8); return(new RCTimeScalar(new DateTime(ticks), (RCTimeType)type)); }
public Timeline(RCArray <long> g, RCArray <long> e, RCArray <RCTimeScalar> t, RCArray <RCSymbolScalar> s) { Colset = new RCArray <string> (4); if (g != null) { Colset.Write("G"); Global = g; _count = Global.Count; } if (e != null) { Colset.Write("E"); Event = e; _count = Event.Count; } if (t != null) { Colset.Write("T"); Time = t; _count = Time.Count; } if (s != null) { Colset.Write("S"); Symbol = s; _count = Symbol.Count; } Proto = CubeProto.Create(this); }
public static RCArray <RCSymbolScalar> ReadVectorSymbol(RCArray <byte> data, ref int start) { // count of unique elements in the vector. int count = BitConverter.ToInt32(data._source, start); start += sizeof(int); RCArray <RCSymbolScalar> unique = new RCArray <RCSymbolScalar> (); for (int i = 0; i < count; ++i) { RCSymbolScalar scalar = ReadScalarSymbol(data, ref start); unique.Write(scalar); } // count of actual elements in the vector. count = BitConverter.ToInt32(data._source, start); start += sizeof(int); RCSymbolScalar[] result = new RCSymbolScalar[count]; for (int i = 0; i < count; ++i) { int index = BitConverter.ToInt32(data._source, start); result[i] = unique[index]; start += sizeof(int); } return(new RCArray <RCSymbolScalar> (result)); }
public static RCClosure UserOpClosure(RCClosure previous, RCValue code, RCArray <RCBlock> @this, bool noClimb) { return(UserOpClosure(previous, code, @this, null, null, noClimb)); }
/// <summary> /// Find and return the value referenced by name. Throw if not found. /// </summary> public static RCValue Resolve(RCBlock context, RCClosure closure, RCArray <string> name, RCArray <RCBlock> @this) { return(Resolve(context, closure, name, @this, false)); }
public static bool CheckForRecursion(RCValue op, RCClosure previous, ref RCValue userop, ref RCArray <RCBlock> useropContext) { RCUserOperator name = op as RCUserOperator; if (name != null) { PreresolveUserOp(previous, op, ref userop, ref useropContext); RCClosure current = previous.Parent; while (current != null) { RCUserOperator code = current.Code as RCUserOperator; if (code != null) { if (userop == current.UserOp) { // Tail recursion detected return(true); } } current = current.Parent; } } // No tail recursion here return(false); }
public RCVector(RCArray <T> data) { if (data == null) { data = new RCArray <T> (new T[0]); } _data = data; }
public static void WriteScalarDecimal(decimal val, RCArray <byte> result) { int[] bits = decimal.GetBits(val); for (int i = 0; i < bits.Length; ++i) { WriteScalarInt(result, bits[i]); } }
static CSVParser() { RCArray <RCTokenType> types = new RCArray <RCTokenType> (); types.Write(RCTokenType.CSVSeparator); types.Write(RCTokenType.CSVContent); _csvLexer = new RCLexer(types); }
public static RCClosure UserOpClosure(RCClosure previous, RCValue code, RCArray <RCBlock> @this, RCValue left, RCValue right) { return(UserOpClosure(previous, code, @this, left, right, noClimb: false)); }
public Timeline(RCArray <RCSymbolScalar> s) { Colset = new RCArray <string> (1); Colset.Write("S"); Symbol = s; _count = Symbol.Count; Proto = CubeProto.Create(this); }
public void EvalBinary(RCRunner runner, RCClosure closure, object right) { RCValue val = (RCValue)right; RCArray <byte> result = new RCArray <byte> (); val.ToByte(result); runner.Yield(closure, new RCByte(result)); }
public void Dispatch(RCCube target, RCArray <int> lines) { for (int i = 0; i < lines.Count; ++i) { RCSymbolScalar scalar = target.Axis.SymbolAt(lines[i]); Dispatch(scalar, lines[i]); } }
public static void ArrayHasOneElement <T> (RCArray <T> array) { if (array.Count != 1) { throw new RCDebugException("The array must contain exactly one element. Array was {0}", array); } }
public RCVector(params T[] data) { if (data == null) { data = new T[0]; } _data = new RCArray <T> (data); }