예제 #1
0
 public void UpdateColmap(RCArray <string> column, RCArray <string> format)
 {
     lock (_lock)
     {
         _colmap = _colmap.Update(column, format);
     }
 }
예제 #2
0
        /// <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);
        }
예제 #3
0
        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);
        }
예제 #4
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);
        }
예제 #5
0
        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));
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
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);
        }
예제 #9
0
        public virtual RCArray <RCToken> Lex(string code)
        {
            RCArray <RCToken> tokens = new RCArray <RCToken> ();

            Lex(code, tokens);
            return(tokens);
        }
예제 #10
0
        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));
        }
예제 #11
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);
            }
        }
예제 #12
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));
 }
예제 #13
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;
                    }
                }
            }
        }
예제 #14
0
        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);
            }
        }
예제 #15
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.");
            }
        }
예제 #16
0
        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));
        }
예제 #17
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);
 }
예제 #18
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));
        }
예제 #19
0
 public static RCClosure UserOpClosure(RCClosure previous,
                                       RCValue code,
                                       RCArray <RCBlock> @this,
                                       bool noClimb)
 {
     return(UserOpClosure(previous, code, @this, null, null, noClimb));
 }
예제 #20
0
 /// <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));
 }
예제 #21
0
        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);
        }
예제 #22
0
 public RCVector(RCArray <T> data)
 {
     if (data == null)
     {
         data = new RCArray <T> (new T[0]);
     }
     _data = data;
 }
예제 #23
0
 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]);
     }
 }
예제 #24
0
        static CSVParser()
        {
            RCArray <RCTokenType> types = new RCArray <RCTokenType> ();

            types.Write(RCTokenType.CSVSeparator);
            types.Write(RCTokenType.CSVContent);
            _csvLexer = new RCLexer(types);
        }
예제 #25
0
 public static RCClosure UserOpClosure(RCClosure previous,
                                       RCValue code,
                                       RCArray <RCBlock> @this,
                                       RCValue left,
                                       RCValue right)
 {
     return(UserOpClosure(previous, code, @this, left, right, noClimb: false));
 }
예제 #26
0
 public Timeline(RCArray <RCSymbolScalar> s)
 {
     Colset = new RCArray <string> (1);
     Colset.Write("S");
     Symbol = s;
     _count = Symbol.Count;
     Proto  = CubeProto.Create(this);
 }
예제 #27
0
        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));
        }
예제 #28
0
 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]);
     }
 }
예제 #29
0
 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);
     }
 }
예제 #30
0
 public RCVector(params T[] data)
 {
     if (data == null)
     {
         data = new T[0];
     }
     _data = new RCArray <T> (data);
 }