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()); }
private void UpdateIndexsAndPages( int indexToInsert, InsertResult insertResult) { _indexes[indexToInsert] = insertResult.SplitValue; _dataPages[indexToInsert] = insertResult.LeftDataPage; _dataPages[indexToInsert + 1] = insertResult.RightDataPage; }
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)); }
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)); }
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()); }