public void EvalSplitw(RCRunner runner, RCClosure closure, RCString left, RCString right) { RCArray <string> result = new RCArray <string> (); for (int i = 0; i < right.Count; ++i) { int start = 0; int end; while (true) { end = right[i].IndexOf(left[0], start); if (end >= 0) { result.Write(right[i].Substring(start, end - start)); start = end + left[0].Length; } else { result.Write(right[i].Substring(start)); break; } } } runner.Yield(closure, new RCString(result)); }
public void Enqueue(RCSymbol symbol, RCClosure closure) { if (_symbolsByFiber.ContainsKey(closure.Fiber)) { throw new Exception("Fiber " + closure.Fiber.ToString() + " is already waiting, something is wrong."); } RCArray <RCSymbolScalar> stripped = new RCArray <RCSymbolScalar> (symbol.Count); for (int i = 0; i < symbol.Count; ++i) { if (symbol[i].Key.Equals("*")) { stripped.Write(symbol[i].Previous); } else { stripped.Write(symbol[i]); } } _symbolsByFiber.Add(closure.Fiber, new HashSet <RCSymbolScalar> (stripped)); for (int i = 0; i < stripped.Count; ++i) { HashSet <long> fibers; if (!_fibersBySymbol.TryGetValue(stripped[i], out fibers)) { _fibersBySymbol[stripped[i]] = fibers = new HashSet <long> (); } fibers.Add(closure.Fiber); } _waitOrder.Enqueue(closure); }
public void EvalPartsAfter(RCRunner runner, RCClosure closure, RCSymbol left, RCLong right) { RCArray <RCSymbolScalar> result = new RCArray <RCSymbolScalar> (left.Count); if (right.Count == 1) { for (int i = 0; i < left.Count; ++i) { result.Write(left[i].PartsAfter(right[0])); } } else if (right.Count == left.Count) { for (int i = 0; i < left.Count; ++i) { result.Write(left[i].PartsAfter(right[i])); } } else { throw new RCException(closure, RCErrors.Count, "partsBefore requires a single part index or an array having the same count as the left argument"); } runner.Yield(closure, new RCSymbol(result)); }
protected RCArray <T> DoAppend <T> (RCBlock right) { RCVector <T> current = (RCVector <T>)right.Get(0); RCArray <T> result = new RCArray <T> (current.Count * 3); result.Write(current.Data); for (int i = 1; i < right.Count; ++i) { current = (RCVector <T>)right.Get(i); result.Write(current.Data); } return(result); }
protected 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 = RankUtils.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); }
protected RCArray <T> DoAlternate <T> (RCVector <T> left, RCVector <T> right) { if (left.Count != right.Count) { throw new Exception("alternate requires equal length vectors"); } RCArray <T> result = new RCArray <T> (left.Count * 2); for (int i = 0; i < left.Count; ++i) { result.Write(left[i]); result.Write(right[i]); } return(result); }
public static void ListExec(RCRunner runner, RCClosure closure) { RCArray <Exec> modules = new RCArray <Exec> (); RCArray <long> keys = new RCArray <long> (); lock (runner._botLock) { foreach (KeyValuePair <long, RCBot> kv in runner._bots) { keys.Write(kv.Key); modules.Write((Exec)runner._bots[kv.Key].GetModule(typeof(Exec))); } } RCCube result = new RCCube("S"); for (int i = 0; i < modules.Count; ++i) { lock (modules[i]._lock) { foreach (KeyValuePair <long, Exec.ChildProcess> kv in modules[i]._process) { RCSymbolScalar sym = RCSymbolScalar.From("exec", keys[i], kv.Key); result.WriteCell("bot", sym, keys[i]); result.WriteCell("handle", sym, (long)kv.Key); result.WriteCell("pid", sym, (long)kv.Value._pid); result.WriteCell("program", sym, kv.Value._program); result.WriteCell("arguments", sym, kv.Value._arguments); result.WriteCell("exit", sym, kv.Value._exitCode); result.Write(sym); } } } runner.Yield(closure, result); }
public void EvalIndexOfLast(RCRunner runner, RCClosure closure, RCString left, RCString right) { if (left.Count != 1) { throw new Exception("indexoflast can only take one string on the left."); } RCArray <long> result = new RCArray <long> (); string value = left[0]; int totalIndex = 0; for (int i = 0; i < right.Count; ++i) { int startIndex = 0; while (true) { startIndex = right[i].LastIndexOf(value, startIndex, right[i].Length - startIndex, StringComparison.InvariantCulture); if (startIndex > -1) { result.Write(totalIndex + startIndex); startIndex += value.Length; } else { break; } } totalIndex += right[i].Length; } runner.Yield(closure, new RCLong(result)); }
public static RCArray <O> ContextualOp <C, L, R, O> (RCArray <L> left, RCArray <R> right, ConScalarOp <C, L, R, O> op) where C : Context <L>, new () { // Things left to do to make this work: // Add the equivalent on CubeMath. // Update both type constructors. // I think it will work well, perhaps a little overengineered... // Most people would just expand these two operations by hand rather than adding a // new profile. // I have a feeling I will use this facility for other operations... I dunno, I'm // going skiing. C c = new C(); c.Init(left); RCArray <O> output = new RCArray <O> (); for (int i = 0; i < right.Count; ++i) { output.Write(op(c, right[i])); } return(output); }
public static void ListRequest(RCRunner runner, RCClosure closure) { RCArray <HttpServer> modules = new RCArray <HttpServer> (); RCArray <long> keys = new RCArray <long> (); lock (runner._botLock) { foreach (KeyValuePair <long, RCBot> kv in runner._bots) { keys.Write(kv.Key); modules.Write((HttpServer)runner._bots[kv.Key].GetModule(typeof(HttpServer))); } } RCCube result = new RCCube("S"); for (int i = 0; i < modules.Count; ++i) { lock (modules[i]._lock) { foreach (KeyValuePair <int, HttpServer.RequestInfo> kv in modules[i]._contexts) { RCSymbolScalar urlsym = RCSymbolScalar.From("request", keys[i], (long)kv.Key); result.WriteCell("bot", urlsym, keys[i]); result.WriteCell("handle", urlsym, (long)kv.Key); result.WriteCell("url", urlsym, kv.Value.Context.Request.RawUrl); result.Write(urlsym); } } } runner.Yield(closure, result); }
/* * public static void ListFibers (RCRunner runner, RCClosure closure) * { * RCArray<Fiber> modules = new RCArray<Fiber> (); * RCArray<long> keys = new RCArray<long> (); * lock (runner._botLock) * { * foreach (KeyValuePair<long, RCBot> kv in runner._bots) * { * keys.Write (kv.Key); * modules.Write ((Fiber) runner._bots[kv.Key].GetModule (typeof (Fiber))); * } * } * RCArray<long> bots = new RCArray<long> (); * RCArray<long> fibers = new RCArray<long> (); * RCArray<string> states = new RCArray<string> (); * for (int i = 0; i < modules.Count; ++i) * { * lock (modules[i]._fiberLock) * { * foreach (KeyValuePair<long, Fiber.FiberState> kv in modules[i]._fibers) * { * bots.Write (keys[i]); * fibers.Write (kv.Key); * states.Write (kv.Value.State); * } * } * } * RCBlock result = RCBlock.Empty; * if (states.Count > 0) * { * result = new RCBlock (result, "bot", ":", new RCLong (bots)); * result = new RCBlock (result, "fiber", ":", new RCLong (fibers)); * result = new RCBlock (result, "state", ":", new RCString (states)); * } * * runner.Yield (closure, result); * } */ public static void ListFibers(RCRunner runner, RCClosure closure) { RCArray <Fiber> modules = new RCArray <Fiber> (); RCArray <long> keys = new RCArray <long> (); lock (runner._botLock) { foreach (KeyValuePair <long, RCBot> kv in runner._bots) { keys.Write(kv.Key); modules.Write((Fiber)runner._bots[kv.Key].GetModule(typeof(Fiber))); } } RCCube result = new RCCube("S"); for (int i = 0; i < modules.Count; ++i) { lock (modules[i]._fiberLock) { foreach (KeyValuePair <long, Fiber.FiberState> kv in modules[i]._fibers) { RCSymbolScalar sym = RCSymbolScalar.From("fiber", keys[i], kv.Key); result.WriteCell("bot", sym, keys[i]); result.WriteCell("fiber", sym, kv.Key); result.WriteCell("state", sym, kv.Value.State); result.Write(sym); } } } runner.Yield(closure, result); }
public virtual void EvalHas(RCRunner runner, RCClosure closure, RCBlock left, RCString right) { RCArray <bool> result = new RCArray <bool> (); for (int i = 0; i < right.Count; ++i) { result.Write(left.Get(right[i]) != null); } runner.Yield(closure, new RCBoolean(result)); }
public void EvalFile(RCRunner runner, RCClosure closure, RCSymbol right) { RCArray <bool> result = new RCArray <bool> (right.Count); for (int i = 0; i < right.Count; ++i) { result.Write(File.Exists(PathSymbolToLocalString(right[i]))); } runner.Yield(closure, new RCBoolean(result)); }
public void EvalPath(RCRunner runner, RCClosure closure, RCSymbol right) { RCArray <string> result = new RCArray <string> (right.Count); for (int i = 0; i < right.Count; ++i) { result.Write(PathSymbolToLocalString(right[i])); } runner.Yield(closure, new RCString(result)); }
public void EvalTrimEnd(RCRunner runner, RCClosure closure, RCString right) { RCArray <string> result = new RCArray <string> (right.Count); for (int i = 0; i < right.Count; ++i) { result.Write(right[i].TrimEnd()); } runner.Yield(closure, new RCString(result)); }
public void EvalDir(RCRunner runner, RCClosure closure, RCString right) { RCArray <bool> result = new RCArray <bool> (right.Count); for (int i = 0; i < right.Count; ++i) { result.Write(Directory.Exists(right[i])); } runner.Yield(closure, new RCBoolean(result)); }
public void EvalIsName(RCRunner runner, RCClosure closure, RCString right) { RCArray <bool> result = new RCArray <bool> (right.Count); for (int i = 0; i < right.Count; ++i) { result.Write(RCTokenType.LengthOfStrictIdentifier(right[i], 0) == right[i].Length); } runner.Yield(closure, new RCBoolean(result)); }
protected RCArray <T> DoReverse <T> (RCVector <T> right) { RCArray <T> results = new RCArray <T> (right.Count); for (int i = right.Count - 1; i >= 0; --i) { results.Write(right[i]); } return(results); }
public void UrlDecode(RCRunner runner, RCClosure closure, RCString right) { RCArray <string> result = new RCArray <string> (right.Count); for (int i = 0; i < right.Count; ++i) { result.Write(HttpUtility.UrlDecode(right[i])); } runner.Yield(closure, new RCString(result)); }
public void EvalParseTime(RCRunner runner, RCClosure closure, RCString left, RCString right) { RCArray <RCTimeScalar> result = new RCArray <RCTimeScalar> (); for (int i = 0; i < right.Count; ++i) { result.Write(TimeToken.ParseTime(right[i], left.ToArray(), smartType: false)); } runner.Yield(closure, new RCTime(result)); }
protected RCArray <T> DoPop <T> (RCArray <T> right) { RCArray <T> results = new RCArray <T> (right.Count); for (int i = 0; i < right.Count - 1; ++i) { results.Write(right[i]); } return(results); }
public static RCArray <O> MonadicOp <R, O> (RCArray <R> right, ScalarOp <R, O> op) { RCArray <O> output = new RCArray <O> (right.Count); for (int i = 0; i < right.Count; ++i) { output.Write(op(right[i])); } return(output); }
public void EvalDayOfWeek(RCRunner runner, RCClosure closure, RCTime right) { RCArray <string> result = new RCArray <string> (right.Count); for (int i = 0; i < right.Count; ++i) { DateTime date = new DateTime(right[i].Ticks); result.Write(date.DayOfWeek.ToString()); } runner.Yield(closure, new RCString(result)); }
protected RCArray <T> DoRepeat <T> (RCVector <long> left, RCVector <T> right) { long count = left[0]; RCArray <T> result = new RCArray <T> ((int)count * right.Count); for (int i = 0; i < count; ++i) { result.Write(right.Data); } return(result); }
public void EvalSplit(RCRunner runner, RCClosure closure, RCString left, RCString right) { // Would be nice to support muliple strings on the left, like "\" "/" split $blah RCArray <string> result = new RCArray <string> (); for (int i = 0; i < right.Count; ++i) { result.Write(right[i].Split(left[0].ToCharArray())); } runner.Yield(closure, new RCString(result)); }
public void EvalPad(RCRunner runner, RCClosure closure, RCString left, RCLong right) { RCArray <string> result = new RCArray <string> (right.Count); for (int i = 0; i < right.Count; ++i) { string padding = "".PadRight((int)right[i], left[0][0]); result.Write(padding); } runner.Yield(closure, new RCString(result)); }
public void EvalNow(RCRunner runner, RCClosure closure, RCTime right) { RCArray <RCTimeScalar> result = new RCArray <RCTimeScalar> (right.Count); for (int i = 0; i < right.Count; ++i) { DateTime date = new DateTime(right[i].Ticks); DateTime adjustedDate = date.ToLocalTime(); result.Write(new RCTimeScalar(adjustedDate, right[i].Type)); } runner.Yield(closure, new RCTime(result)); }
public void EvalTime(RCRunner runner, RCClosure closure, RCSymbol left, RCTime right) { RCArray <RCTimeScalar> result = new RCArray <RCTimeScalar> (); string name = left[0].Part(0).ToString(); RCTimeType type = (RCTimeType)Enum.Parse(typeof(RCTimeType), name, true); for (int i = 0; i < right.Count; ++i) { result.Write(new RCTimeScalar(new DateTime(right[i].Ticks), type)); } runner.Yield(closure, new RCTime(result)); }
public void EvalTuple(RCRunner runner, RCClosure closure, RCString left, RCString right) { RCArray <RCSymbolScalar> result = new RCArray <RCSymbolScalar> (); for (int i = 0; i < right.Count; ++i) { string[] parts = right[i].Split(left[0].ToCharArray()); RCSymbolScalar sym = RCSymbolScalar.From(parts); result.Write(sym); } runner.Yield(closure, new RCSymbol(result)); }
public void EvalGuid(RCRunner runner, RCClosure closure, RCLong right) { int guids = (int)right[0]; RCArray <string> result = new RCArray <string> (guids); for (int i = 0; i < guids; ++i) { Guid guid = Guid.NewGuid(); result.Write(guid.ToString()); } runner.Yield(closure, new RCString(result)); }