Ejemplo n.º 1
0
        private InsertResult InsertWithoutSplit(
            CustomerRecord newCustomerRecord,
            AdditionalSpaceAction additionalSpaceAction)
        {
            var pageSize = GetCorrectPageSize(additionalSpaceAction);

            for (int recordIndex = 0; recordIndex < pageSize; recordIndex++)
            {
                if (_customerRecords[recordIndex] == null)
                {
                    _customerRecords[recordIndex] = newCustomerRecord;

                    break;
                }

                if (_customerRecords[recordIndex].CustomerId > newCustomerRecord.CustomerId)
                {
                    _customerRecords = ShiftAndInsert(
                        _customerRecords,
                        newCustomerRecord,
                        recordIndex, pageSize);

                    break;
                }
            }

            return(InsertResult.CreateWithoutSplit());
        }
Ejemplo n.º 2
0
 private void UpdateIndexsAndPages(
     int indexToInsert,
     InsertResult insertResult)
 {
     _indexes[indexToInsert]       = insertResult.SplitValue;
     _dataPages[indexToInsert]     = insertResult.LeftDataPage;
     _dataPages[indexToInsert + 1] = insertResult.RightDataPage;
 }
Ejemplo n.º 3
0
        private InsertResult CreateSplit()
        {
            var splitCount = (int)Math.Ceiling(PageSize / 2.0d);

            var leftPage  = CreateLeftPage(splitCount);
            var rightPage = CreateRightPage(splitCount);

            return(InsertResult.CreateAsSplit(
                       _indexes[splitCount],
                       leftPage,
                       rightPage));
        }
Ejemplo n.º 4
0
        private InsertResult CreateSplitResult(
            CustomerRecord[] customerRecords)
        {
            var splitCount = (int)Math.Ceiling(PageSize / 2.0d);

            var leftDataPage  = CreateLeftDataPage(customerRecords, splitCount);
            var rightDataPage = CreateRightDataPage(customerRecords, splitCount);

            return(InsertResult.CreateAsSplit(
                       customerRecords[splitCount].CustomerId,
                       leftDataPage,
                       rightDataPage));
        }
Ejemplo n.º 5
0
        public InsertResult Insert(CustomerRecord newCustomerRecord)
        {
            var indexToInsert = FindIndexToInsert(newCustomerRecord);

            var insertResult = _dataPages[indexToInsert].Insert(newCustomerRecord);

            if (insertResult.WasSplitCaused)
            {
                if (_indexes[indexToInsert] > 0)
                {
                    ShiftIndexes(indexToInsert);
                    ShiftPages(indexToInsert);
                }

                UpdateIndexsAndPages(indexToInsert, insertResult);
            }

            if (PageIsFull())
            {
                return(CreateSplit());
            }

            return(InsertResult.CreateWithoutSplit());
        }