Ejemplo n.º 1
0
 public TernaryTableUpdater(string relvarName, TernaryTable table, ValueStoreUpdater store1, ValueStoreUpdater store2, ValueStoreUpdater store3)
 {
     this.relvarName = relvarName;
     this.table      = table;
     this.store1     = store1;
     this.store2     = store2;
     this.store3     = store3;
 }
Ejemplo n.º 2
0
 public Iter3(TernaryTable table, int arg3, int index) : base(table)
 {
     this.arg3  = arg3;
     this.index = index;
     if (index != Empty && !IsMatch())
     {
         Next();
     }
 }
Ejemplo n.º 3
0
 public Iter12(TernaryTable table, int arg1, int arg2, int index) : base(table)
 {
     this.arg1  = arg1;
     this.arg2  = arg2;
     this.index = index;
     if (index != Empty && !IsMatch())
     {
         Next();
     }
 }
Ejemplo n.º 4
0
 public Iter123(TernaryTable table) : base(table)
 {
     if (table.count > 0)
     {
         index = 0;
         while (table.Field2OrEmptyMarker(index) == Empty)
         {
             index++;
         }
     }
     else
     {
         index = Empty;
     }
 }
Ejemplo n.º 5
0
        //////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////

        public static Obj Copy(TernaryTable[] tables, int idx1, int idx2, int idx3)
        {
            int count = 0;

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

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

            Obj[] objs1 = new Obj[count];
            Obj[] objs2 = new Obj[count];
            Obj[] objs3 = new Obj[count];

            int next = 0;

            for (int iT = 0; iT < tables.Length; iT++)
            {
                TernaryTable  table   = tables[iT];
                SurrObjMapper mapper1 = table.mapper1;
                SurrObjMapper mapper2 = table.mapper2;
                SurrObjMapper mapper3 = table.mapper3;
                int           size    = table.Capacity();
                for (int iS = 0; iS < size; iS++)
                {
                    int field2 = table.Field2OrEmptyMarker(iS);
                    if (field2 != Empty)
                    {
                        objs1[next] = mapper1(table.Field1OrNext(iS));
                        objs2[next] = mapper2(field2);
                        objs3[next] = mapper3(table.Field3(iS));
                        next++;
                    }
                }
            }
            Debug.Assert(next == count);

            Obj[][] cols = new Obj[3][];
            cols[idx1] = objs1;
            cols[idx2] = objs2;
            cols[idx3] = objs3;

            return(Builder.CreateTernRel(cols[0], cols[1], cols[2], count));
        }
Ejemplo n.º 6
0
 protected Iter(TernaryTable table)
 {
     this.table = table;
 }
Ejemplo n.º 7
0
        //////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////


        public static void Write(DataWriter writer, int fieldSymbId, TernaryTable[] tables, int col1, int col2, int col3, 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 < tables.Length; i++)
            {
                count += tables[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 < tables.Length; i++)
                {
                    TernaryTable      table   = tables[i];
                    SurrObjMapper     mapper1 = table.mapper1;
                    SurrObjMapper     mapper2 = table.mapper2;
                    SurrObjMapper     mapper3 = table.mapper3;
                    TernaryTable.Iter it      = table.GetIter();
                    while (!it.Done())
                    {
                        writer.Write(entryWs);
                        Obj obj1 = mapper1(it.Get1());
                        Obj obj2 = mapper2(it.Get2());
                        Obj obj3 = mapper3(it.Get3());

                        if (col1 == 0)
                        {
                            ObjPrinter.PrintNoFlush(obj1, writer);
                        }
                        else if (col1 == 1)
                        {
                            ObjPrinter.PrintNoFlush(obj2, writer);
                        }
                        else
                        {
                            ObjPrinter.PrintNoFlush(obj3, writer);
                        }

                        writer.Write(", ");

                        if (col2 == 0)
                        {
                            ObjPrinter.PrintNoFlush(obj1, writer);
                        }
                        else if (col2 == 1)
                        {
                            ObjPrinter.PrintNoFlush(obj2, writer);
                        }
                        else
                        {
                            ObjPrinter.PrintNoFlush(obj3, writer);
                        }

                        writer.Write(", ");

                        if (col3 == 0)
                        {
                            ObjPrinter.PrintNoFlush(obj1, writer);
                        }
                        else if (col3 == 1)
                        {
                            ObjPrinter.PrintNoFlush(obj2, writer);
                        }
                        else
                        {
                            ObjPrinter.PrintNoFlush(obj3, writer);
                        }

                        written++;
                        writer.Write(written < count || count == 1 ? ";\n" : "\n");
                        it.Next();
                    }
                }
                Debug.Assert(written == count);

                writer.Write(baseWs);
            }

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