Пример #1
0
        public bool Contains23(int surr2, int surr3)
        {
            Prepare231();

            if (Ints231.Contains23(insertList, insertCount, surr2, surr3))
            {
                return(true);
            }

            if (!table.Contains23(surr2, surr3))
            {
                return(false);
            }

            int idx = Ints231.IndexFirst23(deleteList, deleteCount, surr2, surr3);

            if (idx == -1)
            {
                return(true);
            }
            int count = Ints231.Count23(deleteList, deleteCount, surr2, surr3, idx);

            TernaryTable.Iter it = table.GetIter23(surr2, surr3);
            while (!it.Done())
            {
                // Tuples in the [idx, idx+count) range are sorted in any order, since two arguments are the same
                if (!Ints123.Contains1(deleteList, idx, count, it.Get1()))
                {
                    return(true);
                }
                it.Next();
            }

            return(false);
        }
Пример #2
0
 public void Clear()
 {
     deleteCount = 0;
     TernaryTable.Iter it = table.GetIter();
     while (!it.Done())
     {
         deleteIdxs = Array.Append(deleteIdxs, deleteCount, it.Index());
         deleteList = Array.Append3(deleteList, deleteCount++, it.Get1(), it.Get2(), it.Get3());
         it.Next();
     }
 }
Пример #3
0
        public bool Contains13(int surr1, int surr3)
        {
            Prepare312();

            if (Ints312.Contains13(insertList, insertCount, surr1, surr3))
            {
                return(true);
            }

            if (!table.Contains13(surr1, surr3))
            {
                return(false);
            }

            int idx = Ints312.IndexFirst31(deleteList, deleteCount, surr3, surr1);

            if (idx == -1)
            {
                return(true);
            }
            int count = Ints312.Count13(deleteList, deleteCount, surr1, surr3, idx);

            TernaryTable.Iter it = table.GetIter13(surr1, surr3);
            while (!it.Done())
            {
                // Tuples in the [idx, idx+count) range are sorted in both 3/1/2
                // and 2/3/1 order, since the first and last argument are the same
                if (!Ints231.Contains2(deleteList, idx, count, it.Get1()))
                {
                    return(true);
                }
                it.Next();
            }

            return(false);
        }
Пример #4
0
        public bool Contains12(int surr1, int surr2)
        {
            Prepare123();

            if (Ints123.Contains12(insertList, insertCount, surr1, surr2))
            {
                return(true);
            }

            if (!table.Contains12(surr1, surr2))
            {
                return(false);
            }

            int idx = Ints123.IndexFirst12(deleteList, deleteCount, surr1, surr2);

            if (idx == -1)
            {
                return(true);
            }
            int count = Ints123.Count12(deleteList, deleteCount, surr1, surr2, idx);

            TernaryTable.Iter it = table.GetIter12(surr1, surr2);
            while (!it.Done())
            {
                // Tuples in the [idx, idx+count) range are sorted in both 1/2/3
                // and 3/1/2 order, since the first two arguments are the same
                if (!Ints312.Contains3(deleteList, idx, count, it.Get1()))
                {
                    return(true);
                }
                it.Next();
            }

            return(false);
        }
Пример #5
0
        public bool Contains3(int surr3)
        {
            Prepare312();

            if (Ints312.Contains3(insertList, insertCount, surr3))
            {
                return(true);
            }

            if (!table.Contains3(surr3))
            {
                return(false);
            }

            int idx = Ints312.IndexFirst3(deleteList, deleteCount, surr3);

            if (idx == -1)
            {
                return(true);
            }
            int count = Ints312.Count3(deleteList, deleteCount, surr3, idx);

            TernaryTable.Iter it = table.GetIter3(surr3);
            while (!it.Done())
            {
                // Tuples in the [idx, idx+count) range are sorted in both 3/1/2
                // and 1/2/3 order, since the third argument is always the same
                if (!Ints123.Contains12(deleteList, idx, count, it.Get1(), it.Get2()))
                {
                    return(true);
                }
                it.Next();
            }

            return(false);
        }
Пример #6
0
        public bool Contains2(int surr2)
        {
            Prepare231();

            if (Ints231.Contains2(insertList, insertCount, surr2))
            {
                return(true);
            }

            if (!table.Contains2(surr2))
            {
                return(false);
            }

            int idx = Ints231.IndexFirst2(deleteList, deleteCount, surr2);

            if (idx == -1)
            {
                return(true);
            }
            int count = Ints231.Count2(deleteList, deleteCount, surr2, idx);

            TernaryTable.Iter it = table.GetIter2(surr2);
            while (!it.Done())
            {
                // Tuples in the [idx, idx+count) range are sorted in both 2/3/1
                // and 3/1/2 order, since the second argument is always the same
                if (!Ints312.Contains13(deleteList, idx, count, it.Get1(), it.Get2()))
                {
                    return(true);
                }
                it.Next();
            }

            return(false);
        }
Пример #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");
        }