//////////////////////////////////////////////////////////////////////////////

        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();
        }
Beispiel #2
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();
        }
        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);
        }