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 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 override bool Write(RCSymbolScalar key, int index, object box, bool force) { T val = (T)box; T old; // The key may be null if there is no timeline. if (_last != null && key != null) { if (!force && _last.TryGetValue(key, out old)) { if (Comparer <T> .Default.Compare(val, old) == 0) { return(false); } } _last[key] = val; } if (_index.Count == 0 || _index[_index.Count - 1] < index) { _data.Write(val); _index.Write(index); } else { // Do we need to look for this? bool found; int existing = _index.BinarySearch(index, out found); if (existing < 0) { throw new Exception("Invalid index " + index); } _data.Write(existing, val); } return(true); }
public override RCSymbolScalar ParseSymbol(RCLexer lexer, RCToken token) { if (token.Text == "#") { return(RCSymbolScalar.Empty); } string[] parts = token.Text.Split(','); string first = parts[0]; // When "casting" strings into symbols, the initial # may be omitted // so that "a" becomes #a. if (first[0] == '#') { first = first.Substring(1); } RCToken child = lexer.LexSingle(first); object part = child.Parse(lexer); RCSymbolScalar result = new RCSymbolScalar(null, part); for (int i = 1; i < parts.Length; ++i) { child = lexer.LexSingle(parts[i]); result = new RCSymbolScalar(result, child.Parse(lexer)); } return(result); }
public override void VisitNull <T> (string name, Column <T> column, int row) { if (_source.Axis.Symbol != null) { T last; RCSymbolScalar scalar = _source.Axis.Symbol[_row]; // We use the last value from the TARGET, otherwise you pull values backwards - // not good ColumnBase targetBaseColumn = _target.GetColumn(name); if (targetBaseColumn != null) { Column <T> targetColumn = (Column <T>)targetBaseColumn; if (targetColumn != null && targetColumn.Last(scalar, out last)) { _target.WriteCell(name, scalar, last, _row, true, true); } } } else { if (_last.ContainsKey(name)) { T lastVal = (T)_last[name]; _target.WriteCell(name, null, lastVal, _row, true, true); } } }
public SpecRecord Get(RCSymbolScalar scalar) { SpecRecord result; // This is for cubes that don't have a timeline: the symbol will be null. if (scalar == null) { return(_records[RCSymbolScalar.Empty]); } RCSymbolScalar current = scalar; while (current != null) { // This will make sure counts are allocated to the most specific symbol first // if you have multiple symbols in the same heirarchy within the same spec. if (_records.TryGetValue(current, out result) && result.count < result.limit && ((current == scalar) || (!result.Concrete && scalar.IsConcreteOf(result.original)))) { return(result); } current = current.Previous; } return(null); }
public override void BeforeRow(long e, RCTimeScalar t, RCSymbolScalar symbol, int row) { if (_source.Axis.Has("G")) { _row = new RCBlock(RCBlock.Empty, "G", ":", new RCLong(_source.Axis.Global[row])); } if (_source.Axis.Has("E")) { _row = new RCBlock(_row, "E", ":", new RCLong(_source.Axis.Event[row])); } if (_source.Axis.Has("T")) { _row = new RCBlock(_row, "T", ":", new RCTime(_source.Axis.Time[row])); } if (_source.Axis.Has("S")) { // Include S as both a field on the row blocks and as the names of the rows // themselves // This is so that you can get back to what you had with "flip block $my_cube" // While also being able to treat the result of "block $my_cube" as a dictionary // if you wish _row = new RCBlock(_row, "S", ":", new RCSymbol(_source.Axis.Symbol[row])); _rowName = _source.Axis.Symbol[row].Key.ToString(); } }
public override void AfterRow(long e, RCTimeScalar t, RCSymbolScalar symbol, int row) { if (!_writeAxis) { return; } long g = _initg + row; // I think this needs to change to a sequence number. 2015.06.03 e = _e; // I need a unit test for not incrementing this after each row. ++_e; // This needs to change to a sequence number but // the _e logic is not quite right yet. 2015.09.17 if (_source.Axis.Has("E")) { e = _source.Axis.Event[row]; } // Things I do not understand, why doesn't every row have the same g? // Why does G reset to zero after clearing, even though initg > 0? // I think it is probably correct internally but that the reader below assigns G // based on its own count. // No it's even worse than that, there isn't and never has been any G row at all on // the // blackboard cubes. Wow. // So to solve this initially I can add _initg to row to get g. // But ultimately we need to make G truly global. long targetLastG = -1; if (_target.Axis.Global != null && _target.Axis.Global.Count > 0) { targetLastG = Math.Abs(_target.Axis.Global[_target.Axis.Global.Count - 1]); } if (_source.Axis.Has("G")) { // This means force specific G values into the blackboard. // This could be good or bad. if (_source.Axis.Global[row] <= targetLastG) { throw new Exception("G values may not be written out of order."); } g = _source.Axis.Global[row]; } else if (targetLastG > -1) { g = targetLastG + 1; } if (_delete) { g = -g; } // I just moved this from the top of the function to the bottom // The tests are ok but I keep this note til all the concurrency examples run if (_counter != null) { _counter.Write(symbol, (int)g); } _target.Axis.Write(g, e, t, symbol); }
public override void AfterRow(long e, RCTimeScalar t, RCSymbolScalar s, int row) { if (_rowChanged) { long g = -1; _target.Write(g, e, t, s); } }
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 override void AfterRow(long e, RCTimeScalar t, RCSymbolScalar s, int row) { if (_indicator[row]) { // g needs to be included in the signature above. long g = -1; _target.Write(g, e, t, s); } }
public override void AfterRow(long e, RCTimeScalar t, RCSymbolScalar s, int row) { if (_indicator) { long g = -1; _target.Write(g, e, t, s); } _indicator = false; }
public override void Cubify(RCCube target, Stack <object> names) { object[] array = names.ToArray(); System.Array.Reverse(array); RCSymbolScalar symbol = RCSymbolScalar.From(array); target.WriteCell(this.TypeCode.ToString(), symbol, Name, -1, true, false); target.Write(symbol); }
public override void VisitScalar <T> (string name, Column <T> column, int row) { if (!_accept) { return; } RCSymbolScalar symbol = _source.Axis.SymbolAt(column.Index[row]); _target.WriteCell(name, symbol, column.Data[row], -1, false, _spec.Force); }
public override void SymbolCol(RCSymbolScalar symbol) { string scalar = symbol.ToString(); int max = _max[_col]; if (scalar.Length > max) { _max[_col] = scalar.Length; } _columns[_col].Add(scalar); _col = (_col + 1) % _names.Count; }
public void Write(RCTimeScalar t, RCSymbolScalar s) { // You will get an exception if these arrays have been locked from writing. if (Time != null) { Time.Write(t); } if (Symbol != null) { Symbol.Write(s); } ++_count; }
public RCSymbolScalar GetSymbol(string name, RCSymbolScalar def) { RCSymbol val = (RCSymbol)Get(name); if (val == null) { return(def); } else { return(val[0]); } }
public void Write(long e, RCSymbolScalar s) { // You will get an exception if these arrays have been locked from writing. if (Event != null) { Event.Write(e); } if (Symbol != null) { Symbol.Write(s); } ++_count; }
public override void VisitScalar <T> (string name, Column <T> column, int row) { if (_source.Axis.Symbol != null) { RCSymbolScalar scalar = _source.Axis.Symbol[column.Index[row]]; _target.WriteCell(name, scalar, column.Data[row], column.Index[row], true, true); } else { T val = column.Data[row]; _last[name] = val; _target.WriteCell(name, null, val, column.Index[row], true, true); } }
public CountRecord Get(RCSymbolScalar scalar) { CountRecord result; if (!scalar.Key.Equals("*")) { _records.TryGetValue(scalar, out result); } else { _abstracts.TryGetValue(scalar.Previous, out result); } return(result); }
public override void Cubify(RCCube target, Stack <object> names) { object[] array = names.ToArray(); System.Array.Reverse(array); RCSymbolScalar symbol = RCSymbolScalar.From(array); for (int i = 0; i < Count; ++i) { T val = this[i]; RCSymbolScalar symboli = new RCSymbolScalar(symbol, (long)i); // Do not try to evaluate incrs during cubification target.WriteCell(this.TypeCode.ToString(), symboli, val, -1, true, false); target.Write(symboli); } }
public override bool BoxLast(RCSymbolScalar key, out object box) { T val; if (Last(key, out val)) { box = val; return(true); } else { box = null; return(false); } }
public override void AfterRow(long e, RCTimeScalar t, RCSymbolScalar s, int row) { if (!_accept) { return; } // Do this after writing the individual cells, // the correct behavior of WriteCell depends on it. // Do not pass the counter here. long g = row; if (_source.Axis.Global != null) { g = _source.Axis.Global[row]; } _target.Write(g, e, t, s); }
public void Write(RCSymbolScalar scalar, int line) { CountRecord record; Dictionary <RCSymbolScalar, CountRecord> map = _records; // It's a delete if (line < 0) { if (map.TryGetValue(scalar, out record)) { record.deleted = true; } // map.Remove (scalar); scalar = scalar.Previous; while (scalar != null) { if (map.TryGetValue(scalar, out record)) { --record.count; --record.total; record.end = Math.Abs(line); } scalar = scalar.Previous; } } else { while (scalar != null) { if (!map.TryGetValue(scalar, out record)) { record = new CountRecord(scalar, map == _records); map[scalar] = record; record.start = line; } // I have to take stuff into account here when clearing... // But How? Can I just blow away the counters? ++record.count; ++record.total; record.end = line; scalar = scalar.Previous; map = _abstracts; } _dispatched.Add(false); } }
public void Dispatch(RCSymbolScalar scalar, long line) { Dictionary <RCSymbolScalar, CountRecord> map = _records; while (scalar != null) { // I assume you wouldn't try to dispatch if the symbol was not represented... CountRecord record = map[scalar]; if (line == record.start) { ++record.start; } --record.count; scalar = scalar.Previous; map = _abstracts; } _dispatched[(int)line] = true; }
public override void Cubify(RCCube target, Stack <object> names) { if (this.Left != null) { names.Push("L"); this.Left.Cubify(target, names); names.Pop(); } names.Push("R"); this.Right.Cubify(target, names); names.Pop(); object[] array = names.ToArray(); System.Array.Reverse(array); RCSymbolScalar symbol = RCSymbolScalar.From(array); target.WriteCell("o", symbol, Name); target.Write(symbol); }
public override void BeforeRow(long e, RCTimeScalar t, RCSymbolScalar s, int row) { bool found; int vrow = _locator.Index.BinarySearch(row, out found); if (found && vrow < _locator.Index.Count) { _indicator = (bool)_locator.BoxCell(vrow); _last[s] = _indicator; } else { if (!_last.TryGetValue(s, out _indicator)) { _indicator = false; } } }
public override void VisitScalar <T> (string name, Column <T> column, int i) { // Can I turn this into WriteCell<T> and get rid of the boxing? bool delete; RCSymbolScalar result = _target.WriteCell(name, _source.Axis.SymbolAt(column.Index[i]), column.Data[i], -1, _keepIncrs, _force, out delete); _delete = _delete || delete; if (result != null || _target.Axis.ColCount == 0) { _result.Add(result); _writeAxis = true; } }
public static RCSymbolScalar ReadScalarSymbol(RCArray <byte> data, ref int start) { RCSymbolScalar result = null; int count = BitConverter.ToInt32(data._source, start); start += sizeof(int); for (int i = 0; i < count; ++i) { char type = (char)data[start]; start += 1; switch (type) { case 'l': result = new RCSymbolScalar(result, BitConverter.ToInt64(data._source, start)); start += sizeof(long); break; case 'd': result = new RCSymbolScalar(result, BitConverter.ToDouble(data._source, start)); start += sizeof(double); break; case 'm': result = new RCSymbolScalar(result, Binary.ReadScalarDecimal(data, start)); start += sizeof(decimal); break; case 'b': result = new RCSymbolScalar(result, BitConverter.ToBoolean(data._source, start)); start += sizeof(bool); break; case 's': result = new RCSymbolScalar(result, Binary.ReadScalarString(data, ref start)); break; default: throw new Exception( "Unknown or unsupported type code in symbol:" + type); } } return(result); }
public SpecRecord(RCSymbolScalar scalar) { original = scalar; RCSymbolScalar current = scalar; while (current != null) { if (current.Key.Equals("*")) { Concrete = false; scalar = current.Previous; if (current.Length < scalar.Length) { LeadingStar = true; } } current = current.Previous; } symbol = scalar; }