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

        public int LookupAny12(int surr1, int surr2)
        {
            Prepare123();

            if (Ints123.Contains12(insertList, insertCount, surr1, surr2))
            {
                int idxFirst = Ints123.IndexFirst12(insertList, insertCount, surr1, surr2);
                return(insertList[3 * idxFirst + 2]);
            }

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

            if (idx == -1)
            {
                return(table.GetIter12(surr1, surr2).Get1());
            }

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

            TernaryTable.Iter12 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(it.Get1());
                }
                it.Next();
            }

            throw ErrorHandler.InternalFail();
        }
Пример #2
0
        //////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////

        public void CheckKey_12()
        {
            if (insertCount != 0)
            {
                Prepare123();

                int prevArg1 = -1;
                int prevArg2 = -1;
                int prevArg3 = -1;

                for (int i = 0; i < insertCount; i++)
                {
                    int arg1 = insertList[3 * i];
                    int arg2 = insertList[3 * i + 1];
                    int arg3 = insertList[3 * i + 2];

                    if (arg1 == prevArg1 & arg2 == prevArg2 & arg3 != prevArg3)
                    {
                        throw Cols12KeyViolationException(arg1, arg2, arg3, prevArg3);
                    }

                    if (!Ints123.Contains12(deleteList, deleteCount, arg1, arg2) && table.Contains12(arg1, arg2))
                    {
                        throw Cols12KeyViolationException(arg1, arg2, arg3);
                    }

                    prevArg1 = arg1;
                    prevArg2 = arg2;
                    prevArg3 = arg3;
                }
            }
        }
Пример #3
0
        //////////////////////////////////////////////////////////////////////////////

        public int LookupAny12(int surr1, int surr2)
        {
            if (surr1 > surr2)
            {
                int tmp = surr1;
                surr1 = surr2;
                surr2 = tmp;
            }

            Prepare();

            if (Ints123.Contains12(insertList, insertCount, surr1, surr2))
            {
                int idxFirst = Ints123.IndexFirst12(insertList, insertCount, surr1, surr2);
                return(insertList[3 * idxFirst + 2]);
            }

            if (table.Contains12(surr1, surr2))
            {
                Sym12TernaryTable.Iter12 it = table.GetIter12(surr1, surr2);
                Debug.Assert(!it.Done());
                do
                {
                    if (!Ints123.Contains(deleteList, deleteCount, surr1, surr2, it.Get1()))
                    {
                        return(it.Get1());
                    }
                    it.Next();
                } while (!it.Done());
            }

            throw ErrorHandler.InternalFail();
        }
Пример #4
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);
        }
Пример #5
0
        public bool Contains3(int surr3)
        {
            PrepareInsert3();

            if (Array.SortedArrayContains(insertList3, surr3))
            {
                return(true);
            }

            if (table.Contains3(surr3))
            {
                //## THIS COULD BE MADE FASTER BY CHECKING FIRST WHETHER surr3 APPEARS IN THE DELETE LIST AT ALL
                Prepare();
                Sym12TernaryTable.Iter3 it = table.GetIter3(surr3);
                Debug.Assert(!it.Done());
                do
                {
                    if (!Ints123.Contains(deleteList, deleteCount, it.Get1(), it.Get2(), surr3))
                    {
                        return(true);
                    }
                    it.Next();
                } while (!it.Done());
            }

            return(false);
        }
Пример #6
0
        public bool contains_1_2(int arg12)
        {
            PrepareInsert12();
            if (Array.SortedArrayContains(insertList12, arg12))
            {
                return(true);
            }

            if (table.contains_1_2(arg12))
            {
                //## THIS COULD BE MADE FASTER BY CHECKING FIRST WHETHER arg12 APPEARS IN THE DELETE LIST AT ALL
                Prepare();
                Sym12TernaryTable.Iter it = table.getIter_1_2(arg12);
                Debug.Assert(!it.Done());
                do
                {
                    int arg1 = arg12;
                    int arg2 = it.Get1();
                    int arg3 = it.Get2();
                    if (arg1 >= arg2)
                    {
                        arg1 = arg2;
                        arg2 = arg12;
                    }
                    if (!Ints123.Contains(deleteList, deleteCount, arg1, arg2, arg3))
                    {
                        return(true);
                    }
                    it.Next();
                } while (!it.Done());
            }

            return(false);
        }
Пример #7
0
        //////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////

        public bool Contains12(int surr1, int surr2)
        {
            if (surr1 > surr2)
            {
                int tmp = surr1;
                surr1 = surr2;
                surr2 = tmp;
            }

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

            if (table.Contains12(surr1, surr2))
            {
                Sym12TernaryTable.Iter12 it = table.GetIter12(surr1, surr2);
                Debug.Assert(!it.Done());
                do
                {
                    if (!Ints123.Contains(deleteList, deleteCount, surr1, surr2, it.Get1()))
                    {
                        return(true);
                    }
                    it.Next();
                } while (!it.Done());
            }

            return(false);
        }
Пример #8
0
        //////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////

        public void Prepare123()
        {
            if (deleteCount != 0 | insertCount != 0)
            {
                Debug.Assert(currOrd == Ord.ORD_NONE | currOrd == Ord.ORD_123);
                if (currOrd != Ord.ORD_123)
                {
                    Ints123.Sort(deleteList, deleteCount);
                    Ints123.Sort(insertList, insertCount);
                    currOrd = Ord.ORD_123;
                }
            }
        }
Пример #9
0
        //////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////

        private void Prepare()
        {
            if (!prepared)
            {
                for (int i = 0; i < deleteCount; i++)
                {
                    Debug.Assert(deleteList[3 * i] <= deleteList[3 * i + 1]);
                }
                Ints123.Sort(deleteList, deleteCount);
                Ints123.Sort(insertList, insertCount);
                prepared = true;
            }
        }
Пример #10
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);
        }
Пример #11
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);
        }