public void EvalFlip(RCRunner runner, RCClosure closure, RCBlock right) { RCBlock prototype = (RCBlock)right.Get(0); string[] names = new string[prototype.Count]; RCVectorBase[] columns = new RCVectorBase[prototype.Count]; for (int i = 0; i < prototype.Count; ++i) { RCBlock name = prototype.GetName(i); RCVectorBase scalar = (RCVectorBase)name.Value; columns[i] = RCVectorBase.FromScalar(scalar.Child(0)); names[i] = name.Name; } for (int i = 1; i < right.Count; ++i) { RCBlock row = (RCBlock)right.Get(i); for (int j = 0; j < row.Count; ++j) { RCBlock name = (RCBlock)row.GetName(j); int n = Array.IndexOf(names, name.Name); if (n >= 0) { RCVectorBase scalar = (RCVectorBase)name.Value; columns[n].Write(scalar.Child(0)); } } } RCBlock result = RCBlock.Empty; for (int i = 0; i < names.Length; ++i) { result = new RCBlock(result, names[i], ":", columns[i]); } runner.Yield(closure, result); }
public void EvalUnflip(RCRunner runner, RCClosure closure, RCBlock right) { // Take a block of arrays and turn them into a block of rows. RCBlock[] blocks = new RCBlock[right.Get(0).Count]; for (int i = 0; i < blocks.Length; ++i) { blocks[i] = RCBlock.Empty; } for (int i = 0; i < right.Count; ++i) { RCBlock name = right.GetName(i); RCVectorBase vector = (RCVectorBase)name.Value; for (int j = 0; j < vector.Count; ++j) { RCValue box = RCVectorBase.FromScalar(vector.Child(j)); blocks[j] = new RCBlock(blocks[j], name.Name, ":", box); } } RCBlock result = RCBlock.Empty; for (int i = 0; i < blocks.Length; ++i) { result = new RCBlock(result, "", ":", blocks[i]); } runner.Yield(closure, result); }