Пример #1
0
        //////////////////////////////////////////////////////////////////////////////

        public static Obj Copy(ColumnBase[] columns, bool flipCols)
        {
            int totalSize = 0;

            for (int i = 0; i < columns.Length; i++)
            {
                totalSize += columns[i].count;
            }

            if (totalSize == 0)
            {
                return(EmptyRelObj.singleton);
            }

            Obj[] objs1 = new Obj[totalSize];
            Obj[] objs2 = new Obj[totalSize];

            int next = 0;

            for (int i = 0; i < columns.Length; i++)
            {
                ColumnBase col = columns[i];
                if (col is IntColumn)
                {
                    IntColumn      intCol = (IntColumn)col;
                    IntColumn.Iter it     = intCol.GetIter();
                    while (!it.Done())
                    {
                        objs1[next] = intCol.mapper(it.GetIdx());
                        objs2[next] = IntObj.Get(it.GetValue());
                        next++;
                        it.Next();
                    }
                }
                else if (col is FloatColumn)
                {
                    FloatColumn      floatCol = (FloatColumn)col;
                    FloatColumn.Iter it       = floatCol.GetIter();
                    while (!it.Done())
                    {
                        objs1[next] = floatCol.mapper(it.GetIdx());
                        objs2[next] = new FloatObj(it.GetValue());
                        next++;
                        it.Next();
                    }
                }
                else
                {
                    ObjColumn      objCol = (ObjColumn)col;
                    ObjColumn.Iter it     = objCol.GetIter();
                    while (!it.Done())
                    {
                        objs1[next] = objCol.mapper(it.GetIdx());
                        objs2[next] = it.GetValue();
                        next++;
                        it.Next();
                    }
                }
            }
            Debug.Assert(next == totalSize);

            if (flipCols)
            {
                Obj[] tmp = objs1;
                objs1 = objs2;
                objs2 = tmp;
            }

            return(Builder.CreateBinRel(objs1, objs2));
        }
Пример #2
0
        //////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////

        public static void Write(DataWriter writer, int fieldSymbId, ColumnBase[] columns, bool flipCols, int indentation, bool indentFirstLine, bool writeSeparator)
        {
            string baseWs  = new string(Array.Repeat(' ', indentation));
            string entryWs = new string(Array.Repeat(' ', indentation + 2));

            int count = 0;

            for (int i = 0; i < columns.Length; i++)
            {
                count += columns[i].Size();
            }

            if (indentFirstLine)
            {
                writer.Write(baseWs);
            }
            writer.Write(SymbObj.IdxToStr(fieldSymbId));
            writer.Write(": [");

            if (count > 0)
            {
                writer.Write("\n");

                int written = 0;
                for (int i = 0; i < columns.Length; i++)
                {
                    ColumnBase    col    = columns[i];
                    SurrObjMapper mapper = col.mapper;

                    if (col is IntColumn)
                    {
                        IntColumn      intCol = (IntColumn)col;
                        IntColumn.Iter it     = intCol.GetIter();
                        while (!it.Done())
                        {
                            writer.Write(entryWs);
                            Obj  key   = mapper(it.GetIdx());
                            long value = it.GetValue();
                            if (flipCols)
                            {
                                writer.Write(value);
                                writer.Write(", ");
                                ObjPrinter.PrintNoFlush(key, writer);
                                written++;
                                writer.Write(written == 1 | written < count ? ";\n" : "\n");
                            }
                            else
                            {
                                ObjPrinter.PrintNoFlush(key, writer);
                                writer.Write(" -> ");
                                writer.Write(value);
                                written++;
                                writer.Write(written < count ? ",\n" : "\n");
                            }
                            it.Next();
                        }
                    }
                    else if (col is FloatColumn)
                    {
                        FloatColumn      floatCol = (FloatColumn)col;
                        FloatColumn.Iter it       = floatCol.GetIter();
                        while (!it.Done())
                        {
                            writer.Write(entryWs);
                            Obj    key   = mapper(it.GetIdx());
                            double value = it.GetValue();
                            if (flipCols)
                            {
                                writer.Write(FloatObjPrinter.Print(value));
                                writer.Write(", ");
                                ObjPrinter.PrintNoFlush(key, writer);
                                written++;
                                writer.Write(written == 1 | written < count ? ";\n" : "\n");
                            }
                            else
                            {
                                ObjPrinter.PrintNoFlush(key, writer);
                                writer.Write(" -> ");
                                writer.Write(FloatObjPrinter.Print(value));
                                written++;
                                writer.Write(written < count ? ",\n" : "\n");
                            }
                            it.Next();
                        }
                    }
                    else
                    {
                        ObjColumn      objCol = (ObjColumn)col;
                        ObjColumn.Iter it     = objCol.GetIter();
                        while (!it.Done())
                        {
                            writer.Write(entryWs);
                            Obj key   = mapper(it.GetIdx());
                            Obj value = it.GetValue();
                            if (flipCols)
                            {
                                ObjPrinter.PrintNoFlush(value, writer);
                                writer.Write(", ");
                                ObjPrinter.PrintNoFlush(key, writer);
                                written++;
                                writer.Write(written == 1 | written < count ? ";\n" : "\n");
                            }
                            else
                            {
                                ObjPrinter.PrintNoFlush(key, writer);
                                writer.Write(" -> ");
                                ObjPrinter.PrintNoFlush(value, writer);
                                written++;
                                writer.Write(written < count ? ",\n" : "\n");
                            }
                            it.Next();
                        }
                    }
                }
                Debug.Assert(written == count);

                writer.Write(baseWs);
            }

            writer.Write(writeSeparator ? "],\n" : "]\n");
        }