示例#1
0
        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);
        }
示例#2
0
 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));
 }
示例#3
0
 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);
 }
示例#4
0
        static CSVParser()
        {
            RCArray <RCTokenType> types = new RCArray <RCTokenType> ();

            types.Write(RCTokenType.CSVSeparator);
            types.Write(RCTokenType.CSVContent);
            _csvLexer = new RCLexer(types);
        }
示例#5
0
 public static void WriteVectorTime(RCArray <byte> result, RCArray <RCTimeScalar> data)
 {
     WriteScalarInt(result, data.Count);
     for (int i = 0; i < data.Count; ++i)
     {
         result.Write(BitConverter.GetBytes(data[i].Ticks));
         result.Write(BitConverter.GetBytes((int)data[i].Type));
     }
 }
示例#6
0
 public static void WriteScalarString(string scalar, RCArray <byte> result)
 {
     WriteScalarInt(result, scalar.Length);
     for (int j = 0; j < scalar.Length; ++j)
     {
         result.Write((byte)scalar[j]);
         result.Write((byte)(scalar[j] << 8));
     }
 }
示例#7
0
        static LogParser()
        {
            RCArray <RCTokenType> types = new RCArray <RCTokenType> ();

            types.Write(RCTokenType.LogEntryHeader);
            types.Write(RCTokenType.EndOfLine);
            types.Write(RCTokenType.LogEntryBody);
            types.Write(RCTokenType.LogEntryRawLine);
            _logLexer = new RCLexer(types);
        }
示例#8
0
        public static RCArray <string> MultipartName(string text, char delimeter)
        {
            int partStart           = 0;
            RCArray <string> result = new RCArray <string> (4);

            for (int i = 0; i < text.Length; ++i)
            {
                if (i == text.Length - 1)
                {
                    string partString = text.Substring(partStart);
                    RCName part       = GetName(partString);
                    partStart += partString.Length;
                    // Consume the delimeter
                    ++partStart;
                    result.Write(part.Text);
                }
                else if (text[i] == delimeter)
                {
                    string partString = text.Substring(partStart, i - partStart);
                    RCName part       = GetName(partString);
                    partStart += partString.Length;
                    // Consume the delimeter
                    ++partStart;
                    result.Write(part.Text);
                }
                else if (text[i] == '\'')
                {
                    int matchingQuote = text.IndexOf('\'', i + 1);
                    if (matchingQuote < 0)
                    {
                        throw new Exception("Unmatched single quote in name: " + text);
                    }
                    else
                    {
                        while (matchingQuote > 0 && text[matchingQuote - 1] == '\\')
                        {
                            matchingQuote = text.IndexOf('\'', matchingQuote + 1);
                        }
                        if (matchingQuote <= 0 || text[matchingQuote] != '\'')
                        {
                            throw new Exception("Unmatched single quote among escaped single quotes in name: " +
                                                text);
                        }
                        string partString = text.Substring(partStart, 1 + (matchingQuote - partStart));
                        RCName part       = GetName(partString);
                        partStart += partString.Length;
                        result.Write(part.Text);
                        i = matchingQuote;
                    }
                }
            }
            return(result);
        }
示例#9
0
 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;
 }
示例#10
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;
 }
示例#11
0
        public static void ApplyArrayRank <T> (RCArray <T> inputData,
                                               RCArray <int> inputIndex,
                                               Dictionary <long, int> map,
                                               int axisCount,
                                               out RCArray <T> data,
                                               out RCArray <int> index)
        {
            RCArray <long> im = new RCArray <long> (inputData.Count);

            T[]   fd = new T[inputData.Count];
            int[] fi = new int[inputData.Count];
            if (inputIndex != null)
            {
                // Any rows that are lacking values in the sort column will be missing from map.
                // Push these rows so that they come after all the rows with valid values in the
                // sort
                // column.
                // But importantly, they are kept in the original order.
                for (int j = 0; j < inputIndex.Count; ++j)
                {
                    int newRow;
                    if (!map.TryGetValue(inputIndex[j], out newRow))
                    {
                        throw new Exception(string.Format("inputIndex[j]: {0} was not represented in map!",
                                                          inputIndex[j]));
                    }
                    im.Write(newRow);
                }
            }
            else
            {
                for (int j = 0; j < inputData.Count; ++j)
                {
                    int newRow;
                    if (!map.TryGetValue(j, out newRow))
                    {
                        newRow = map.Count + j;
                    }
                    im.Write(newRow);
                }
            }
            // Now rank the values in im ascending.
            long[] rim = DoRank <long> (SortDirection.asc, 'l', im);
            for (int j = 0; j < rim.Length; ++j)
            {
                fd[j] = inputData[(int)rim[j]];
                fi[j] = (int)im[(int)rim[j]];
            }
            index = new RCArray <int> (fi);
            data  = new RCArray <T> (fd);
        }
示例#12
0
        static RCName()
        {
            RCName empty = new RCName("", 0, false);

            _names.Add("", empty);
            _index.Write(empty);
            RCName trueLiteral = new RCName("'true'", 1, true);

            _names.Add("true", trueLiteral);
            _index.Write(trueLiteral);
            RCName falseLiteral = new RCName("'false'", 2, true);

            _names.Add("false", falseLiteral);
            _index.Write(falseLiteral);
        }
示例#13
0
        public static void WriteVectorIncr(RCArray <byte> result, RCArray <RCIncrScalar> data)
        {
            WriteScalarInt(result, data.Count);
            for (int i = 0; i < data.Count; ++i)
            {
                switch (data[i])
                {
                case RCIncrScalar.Increment: result.Write(0x00); break;

                case RCIncrScalar.Decrement: result.Write(0x01); break;

                case RCIncrScalar.Delete:    result.Write(0x02); break;
                }
            }
        }
示例#14
0
        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));
        }
示例#15
0
        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);
            }
        }
示例#16
0
        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);
        }
示例#17
0
        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;
                    }
                }
            }
        }
示例#18
0
        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);
        }
示例#19
0
        /// <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.");
            }
        }
示例#20
0
 public Timeline(RCArray <RCSymbolScalar> s)
 {
     Colset = new RCArray <string> (1);
     Colset.Write("S");
     Symbol = s;
     _count = Symbol.Count;
     Proto  = CubeProto.Create(this);
 }
示例#21
0
 public static void WriteReference(RCArray <byte> result, RCReference reference)
 {
     result.Write((byte)'r');
     WriteScalarInt(result, reference.Parts.Count);
     for (int i = 0; i < reference.Parts.Count; ++i)
     {
         Binary.WriteScalarString(reference.Parts[i], result);
     }
 }
示例#22
0
        static JSONParser()
        {
            RCArray <RCTokenType> types = new RCArray <RCTokenType> ();

            types.Write(RCTokenType.WhiteSpace);
            types.Write(RCTokenType.String);
            types.Write(RCTokenType.Number);
            types.Write(RCTokenType.Boolean);
            types.Write(RCTokenType.Block);
            types.Write(RCTokenType.Cube);
            types.Write(RCTokenType.Null);
            types.Write(RCTokenType.CSVSeparator);
            types.Write(RCTokenType.Evaluator);
            _jsonLexer = new RCLexer(types);
        }
示例#23
0
 public void Write(long g, long e, RCTimeScalar t, RCSymbolScalar s)
 {
     if (Global != null)
     {
         Global.Write(g);
     }
     if (Event != null)
     {
         Event.Write(e);
     }
     if (Time != null)
     {
         Time.Write(t);
     }
     if (Symbol != null)
     {
         Symbol.Write(s);
     }
     ++_count;
 }
示例#24
0
        public void EvalLexType(RCRunner runner, RCClosure closure, RCString right)
        {
            RCArray <RCToken> output = new RCArray <RCToken> ();

            RCLParser._o2Lexer.Lex(right[0], output);
            RCArray <string> result = new RCArray <string> (right.Count);

            for (int i = 0; i < output.Count; i++)
            {
                result.Write(output[i].Type.TypeName);
            }
            runner.Yield(closure, new RCString(result));
        }
示例#25
0
 public override void AcceptColumnData(RCToken token)
 {
     if (_header)
     {
         _names.Write(token.Text);
         _data.Write(new RCArray <string> ());
     }
     else
     {
         _data[_column].Write(token.ParseString(_lexer));
         _column = (_column + 1) % _data.Count;
     }
 }
示例#26
0
        public RCSymbol ConcreteSymbols(RCSymbol symbol, bool showDeleted)
        {
            RCArray <RCSymbolScalar> result = new RCArray <RCSymbolScalar> (8);

            foreach (CountRecord count in _records.Values)
            {
                if (count.deleted && !showDeleted)
                {
                    continue;
                }
                for (int i = 0; i < symbol.Count; ++i)
                {
                    RCSymbolScalar scalar = symbol[i];
                    if (scalar.Key.Equals("'*'") || symbol[i].Key.Equals("*"))
                    {
                        if (count.Concrete && !result.Contains(count.symbol))
                        {
                            if (count.symbol.IsConcreteOf(scalar))
                            {
                                result.Write(count.symbol);
                            }
                            else if (count.symbol.Equals(scalar))
                            {
                                result.Write(count.symbol);
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < symbol.Count; ++i)
            {
                if (!(symbol[i].Key.Equals("'*'") || symbol[i].Key.Equals("*")) &&
                    !result.Contains(symbol[i]))
                {
                    result.Write(symbol[i]);
                }
            }
            return(new RCSymbol(result));
        }
示例#27
0
 public static void WriteBlock(RCArray <byte> result, RCBlock block)
 {
     // Pre-order traversal of the expression tree.
     result.Write((byte)'k');
     WriteScalarInt(result, block.Count);
     for (int i = 0; i < block.Count; ++i)
     {
         RCBlock name = block.GetName(i);
         Binary.WriteScalarString(name.Name, result);
         // Binary.WriteScalarString (RCEvaluator.For (name.Evaluator), result);
         Binary.WriteScalarString(name.Evaluator.Symbol, result);
         name.Value.ToByte(result);
     }
 }
示例#28
0
        public static void WriteOperator(RCArray <byte> result, RCOperator op)
        {
            // Pre-order traversal of the expression tree.
            result.Write((byte)'o');
            int count = op.Left == null ? 2 : 3;

            WriteScalarInt(result, count);
            if (op.Left != null)
            {
                op.Left.ToByte(result);
            }
            Binary.WriteScalarString(op.Name, result);
            op.Right.ToByte(result);
        }
示例#29
0
        public static void WriteScalarSymbol(RCArray <byte> result, RCSymbolScalar scalar)
        {
            // This is not going to be a triumph of efficiency.
            // I am considering rewriting RCSymbolScalar so that it stores all of its
            // data as an array of bytes.  Then the ToByte operation would just
            // return the internal representation.
            for (int i = 0; i < scalar.Length; ++i)
            {
                object part = scalar.Part(i);
                char   type = RCVectorBase.EmptyOf(part.GetType()).TypeCode;
                result.Write((byte)type);
                switch (type)
                {
                case 'l':
                    result.Write(BitConverter.GetBytes((long)part));
                    break;

                case 'd':
                    result.Write(BitConverter.GetBytes((double)part));
                    break;

                case 'm':
                    Binary.WriteScalarDecimal((decimal)part, result);
                    break;

                case 'b':
                    result.Write(BitConverter.GetBytes((bool)part));
                    break;

                case 's':
                    Binary.WriteScalarString((string)part, result);
                    break;

                default: throw new Exception("Unknown type:" + type + " found in symbol");
                }
            }
        }
示例#30
0
 public RCRunner(long workers)
 {
     _ctorThread             = Thread.CurrentThread;
     _bots[0]                = new RCBot(this, 0);
     _output[0]              = new Queue <RCAsyncState> ();
     _parser                 = new RCLParser(RCSystem.Activator);
     Console.CancelKeyPress += HandleConsoleCancelKeyPress;
     for (int i = 0; i < workers; ++i)
     {
         Thread worker = new Thread(Work);
         worker.IsBackground = true;
         _workers.Write(worker);
         worker.Start();
     }
 }