예제 #1
0
        private int FindPageOrLowerPosition(T key, ref bool found)
        {
            if (_pageList.Count == 0)
            {
                return(0);
            }
            // binary search
            int lastlower = 0;
            int first     = 0;
            int last      = _pageList.Count - 1;
            int mid       = 0;

            while (first <= last)
            {
                mid = (first + last) >> 1;
                T   k       = _pageList.GetKey(mid);
                int compare = k.CompareTo(key);
                if (compare < 0)
                {
                    lastlower = mid;
                    first     = mid + 1;
                }
                if (compare == 0)
                {
                    found = true;
                    return(mid);
                }
                if (compare > 0)
                {
                    last = mid - 1;
                }
            }

            return(lastlower);
        }
예제 #2
0
        private void CreatePageListData(SafeSortedList <T, PageInfo> _pages, int offset, int rowindex, int counter, byte[] page, int blocknum)
        {
            int idx = rowindex + _rowSize * counter;

            // key bytes
            byte[] kk;
            byte   size;

            if (_externalStrings == false)
            {
                kk   = _T.GetBytes(_pages.GetKey(counter + offset));
                size = (byte)kk.Length;
                if (size > _maxKeySize)
                {
                    size = _maxKeySize;
                }
            }
            else
            {
                kk = new byte[4];
                Buffer.BlockCopy(Helper.GetBytes(counter + offset, false), 0, kk, 0, 4);
                size = 4;
            }
            // key size = 1 byte
            page[idx] = size;
            Buffer.BlockCopy(kk, 0, page, idx + 1, page[idx]);
            // offset = 4 bytes
            byte[] b = Helper.GetBytes(_pages.GetValue(offset + counter).PageNumber, false);
            Buffer.BlockCopy(b, 0, page, idx + 1 + _maxKeySize, b.Length);
            // add counts
            b = Helper.GetBytes(_pages.GetValue(offset + counter).UniqueCount, false);
            Buffer.BlockCopy(b, 0, page, idx + 1 + _maxKeySize + 4, b.Length);
            // FEATURE : add dup counts
        }
예제 #3
0
        private void CreatePageListData(SafeSortedList <T, PageInfo> _pages, int i, byte[] page, int index, int j)
        {
            int idx = index + _rowSize * j;

            // key bytes
            byte[] kk   = _T.GetBytes(_pages.GetKey(j + i));
            byte   size = (byte)kk.Length;

            if (size > _maxKeySize)
            {
                size = _maxKeySize;
            }
            // key size = 1 byte
            page[idx] = size;
            Buffer.BlockCopy(kk, 0, page, idx + 1, page[idx]);
            // offset = 4 bytes
            byte[] b = Helper.GetBytes(_pages.GetValue(i + j).PageNumber, false);
            Buffer.BlockCopy(b, 0, page, idx + 1 + _maxKeySize, b.Length);
            // add counts
            b = Helper.GetBytes(_pages.GetValue(i + j).UniqueCount, false);
            Buffer.BlockCopy(b, 0, page, idx + 1 + _maxKeySize + 4, b.Length);
            // FEATURE : add dup counts
        }