?? myldbbtree.pas
字號:
property RightPageNo: TMYLDBPageNo read GetRightPageNo write SetRightPageNo;
property HasKeys: Boolean read GetHasKeys write SetHasKeys;
property HasSuffixes: Boolean read GetHasSuffixes write SetHasSuffixes;
property KeyPrefixSize: Word read GetKeyPrefixSize write SetKeyPrefixSize;
property EntryCount: Integer read GetEntryCount write SetEntryCount;
property PagePrefixSize: Word read GetPagePrefixSize write SetPagePrefixSize;
// calculated
property EntrySize: Integer read GetEntrySize;
property ReferenceSize: Integer read GetReferenceSize;
property EntriesOffset: Integer read GetEntriesOffset;
property SuffixPtrSize: Integer read GetSuffixPtrSize;
property KeyRef: TMYLDBBTreeKeyRef read LKeyRef write LKeyRef;
end;
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBBTreePageController
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBBTreePageController = class(TObject)
protected
FPage: TMYLDBBTreePage;
function GetKeyRef: TMYLDBBTreeKeyRef;
function CanAddEntry: Boolean;
function IsOverflow: Boolean;
function CanUnderflow: Boolean;
function CanMergeWithPage(Page: TMYLDBBTreePage): Boolean;
procedure EnlargePageBuffer;
function CompareKeys(MayUseFullKeys: Boolean;
SessionID: TMYLDBSessionID;
Key1: PChar; Key2Index: Word): Integer;
function CompareReferences(Reference1: PChar; Reference2Index: Word): Integer;
function CompareEntries(MayUseFullKeys: Boolean;
SessionID: TMYLDBSessionID;
Key1: PChar; Reference1: PChar;
Entry2Index: Word): Integer; virtual; abstract;
function GetKeyPosition(
MayUseFullKeys: Boolean;
SessionID: TMYLDBSessionID;
Key: PChar;
Reference: PChar; // if finding entry
StartPosition: Integer = 0;
PositionType: PMYLDBKeyPathPosition = nil;
SearchType: TMYLDBKeySearchType = kstAny
): Word;
procedure InsertEntry(Key, Reference: PChar; Position: Integer);
procedure DeleteEntry(Position: Integer);
procedure RootSplit(SessionID: TMYLDBSessionID; KeyPath: TMYLDBKeyPath);
procedure NonRootSplit(SessionID: TMYLDBSessionID; KeyPath: TMYLDBKeyPath);
function TryMergeWithPage(
SessionID: TMYLDBSessionID;
MergePageNo: TMYLDBPageNo;
KeyPath: TMYLDBKeyPath
): Boolean;
function TryMerge(SessionID: TMYLDBSessionID; KeyPath: TMYLDBKeyPath): Boolean;
procedure MergeWithLeftPage(
SessionID: TMYLDBSessionID;
LeftPage: TMYLDBBTreePage;
KeyPath: TMYLDBKeyPath
);
procedure MergeWithRightPage(
SessionID: TMYLDBSessionID;
RightPage: TMYLDBBTreePage;
KeyPath: TMYLDBKeyPath
);
public
constructor Create(aPage: TMYLDBBTreePage);
procedure InsertLeafEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar; KeyPath: TMYLDBKeyPath); virtual; abstract;
function DeleteLeafEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar; KeyPath: TMYLDBKeyPath): Boolean; virtual; abstract;
procedure FreeAllPages(SessionID: TMYLDBSessionID; KeepRootPage: Boolean); virtual; abstract;
procedure CheckIntegrity(SessionID: TMYLDBSessionID; KeyPath: TMYLDBKeyPath); virtual; abstract;
function FindEntry(
SessionID: TMYLDBSessionID;
Key: PChar;
Reference: PChar;
Position: TMYLDBKeyPath
): Boolean; virtual; abstract;
function GetFirstPosition(SessionID: TMYLDBSessionID; Position: TMYLDBKeyPath): Boolean; virtual; abstract;
function GetLastPosition(SessionID: TMYLDBSessionID; Position: TMYLDBKeyPath): Boolean; virtual; abstract;
function FindByCondition(
SessionID: TMYLDBSessionID;
First: Boolean; // if False => Last
Key: PChar;
Operator: TMYLDBSearchCondition;
Position: TMYLDBKeyPath
): Boolean; virtual; abstract;
function GetPKey(KeyPosition: Integer): PChar;
function GetPReference(RefPosition: Integer): PChar;
procedure GetFirstKey(SessionID: TMYLDBSessionID; Key: PChar); virtual; abstract;
procedure GetLastKey(SessionID: TMYLDBSessionID; Key: PChar); virtual; abstract;
procedure GetFirstEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar); virtual; abstract;
procedure GetLastEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar); virtual; abstract;
procedure Split(SessionID: TMYLDBSessionID; KeyPath: TMYLDBKeyPath);
property KeyRef: TMYLDBBTreeKeyRef read GetKeyRef;
end;// TMYLDBBTreePageController
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBBTreeLeafController
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBBTreeLeafController = class(TMYLDBBTreePageController)
private
function FindEntryOnPage(SessionID: TMYLDBSessionID;
Key, Reference: PChar; var EntryNo: Integer): Boolean;
function FindFirstByCondition(
SessionID: TMYLDBSessionID;
Key: PChar;
Operator: TMYLDBSearchCondition;
Position: TMYLDBKeyPath
): Boolean;
function FindLastByCondition(
SessionID: TMYLDBSessionID;
Key: PChar;
Operator: TMYLDBSearchCondition;
Position: TMYLDBKeyPath
): Boolean;
protected
function CompareEntries(MayUseFullKeys: Boolean;
SessionID: TMYLDBSessionID;
Key1: PChar; Reference1: PChar;
Entry2Index: Word): Integer; override;
public
procedure InsertLeafEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar; KeyPath: TMYLDBKeyPath); override;
function DeleteLeafEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar; KeyPath: TMYLDBKeyPath): Boolean; override;
procedure GetFirstKey(SessionID: TMYLDBSessionID; Key: PChar); override;
procedure GetLastKey(SessionID: TMYLDBSessionID; Key: PChar); override;
procedure GetFirstEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar); override;
procedure GetLastEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar); override;
function FindEntry(
SessionID: TMYLDBSessionID;
Key: PChar;
Reference: PChar;
Position: TMYLDBKeyPath
): Boolean; override;
function GetFirstPosition(SessionID: TMYLDBSessionID; Position: TMYLDBKeyPath): Boolean; override;
function GetLastPosition(SessionID: TMYLDBSessionID; Position: TMYLDBKeyPath): Boolean; override;
function FindByCondition(
SessionID: TMYLDBSessionID;
First: Boolean; // if False => Last
Key: PChar;
Operator: TMYLDBSearchCondition;
Position: TMYLDBKeyPath
): Boolean; override;
procedure FreeAllPages(SessionID: TMYLDBSessionID; KeepRootPage: Boolean); override;
procedure CheckIntegrity(SessionID: TMYLDBSessionID; KeyPath: TMYLDBKeyPath); override;
end;// TMYLDBBTreeLeafController
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBBTreeNodeController
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBBTreeNodeController = class(TMYLDBBTreePageController)
private
function FindByConditionOnOneOfPages(
SessionID: TMYLDBSessionID;
First: Boolean; // if False => Last
StartEntryNo: Integer;
EndEntryNo: Integer;
Key: PChar;
Operator: TMYLDBSearchCondition;
Position: TMYLDBKeyPath
): Boolean;
function FindEntryOnOneOfPages(
SessionID: TMYLDBSessionID;
StartEntryNo: Integer;
EndEntryNo: Integer;
Key: PChar;
Reference: PChar;
Position: TMYLDBKeyPath
): Boolean;
procedure GetChildPagesToCheck(
SessionID: TMYLDBSessionID;
Key: PChar;
SearchCondition: TMYLDBSearchCondition;
var StartEntryNo: Integer;
var EndEntryNo: Integer
);
procedure DecreaseTreeDepth(SessionID: TMYLDBSessionID);
protected
function CompareEntries(MayUseFullKeys: Boolean;
SessionID: TMYLDBSessionID;
Key1: PChar; Reference1: PChar;
Entry2Index: Word): Integer; override;
public
procedure InsertLeafEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar; KeyPath: TMYLDBKeyPath); override;
procedure InsertNodeEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar; KeyPath: TMYLDBKeyPath);
function DeleteLeafEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar; KeyPath: TMYLDBKeyPath): Boolean; override;
procedure DeleteNodeEntry(
SessionID: TMYLDBSessionID;
KeyPath: TMYLDBKeyPath;
MergeWithLeft: Boolean
);
procedure GetFirstKey(SessionID: TMYLDBSessionID; Key: PChar); override;
procedure GetLastKey(SessionID: TMYLDBSessionID; Key: PChar); override;
procedure GetFirstEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar); override;
procedure GetLastEntry(SessionID: TMYLDBSessionID; Key, Reference: PChar); override;
function FindEntry(
SessionID: TMYLDBSessionID;
Key: PChar;
Reference: PChar;
Position: TMYLDBKeyPath
): Boolean; override;
function GetFirstPosition(SessionID: TMYLDBSessionID; Position: TMYLDBKeyPath): Boolean; override;
function GetLastPosition(SessionID: TMYLDBSessionID; Position: TMYLDBKeyPath): Boolean; override;
function FindByCondition(
SessionID: TMYLDBSessionID;
First: Boolean; // if False => Last
Key: PChar;
Operator: TMYLDBSearchCondition;
Position: TMYLDBKeyPath
): Boolean; override;
procedure FreeAllPages(SessionID: TMYLDBSessionID; KeepRootPage: Boolean); override;
procedure CheckIntegrity(SessionID: TMYLDBSessionID; KeyPath: TMYLDBKeyPath); override;
end;// TMYLDBBTreeNodeController
////////////////////////////////////////////////////////////////////////////////
//
// TMYLDBBTreeRecordIndex
//
////////////////////////////////////////////////////////////////////////////////
TMYLDBBTreeSearchInfo = packed record
GoForward: Boolean;
IsFilled: Boolean;
EndKeyPath: TMYLDBKeyPath;
CurrentKeyPath: TMYLDBKeyPath;
end;
PMYLDBBTreeSearchInfo = ^TMYLDBBTreeSearchInfo;
TMYLDBBTreeRecordIndex = class (TMYLDBIndex)
private
FRootPage: TMYLDBBTreePage;
FKeyRef: TMYLDBRecordKeyRef;
function AddIndexPage(SessionID: TMYLDBSessionID): TMYLDBBTreePage;
function GetIndexPage(SessionID: TMYLDBSessionID; PageNo: TMYLDBPageNo): TMYLDBBTreePage;
procedure PutIndexPage(Page: TMYLDBBTreePage);
function GetRecordID(SessionID: TMYLDBSessionID; Position: TMYLDBKeyPath): TMYLDBRecordID;
function GetFirstPosition(SessionID: TMYLDBSessionID; Position: TMYLDBKeyPath): Boolean;
function GetLastPosition(SessionID: TMYLDBSessionID; Position: TMYLDBKeyPath): Boolean;
function GetNextPosition(SessionID: TMYLDBSessionID; Position: TMYLDBKeyPath): Boolean;
function GetPriorPosition(SessionID: TMYLDBSessionID; Position: TMYLDBKeyPath): Boolean;
function GetPosition(SessionID: TMYLDBSessionID; Restart, GoForward: Boolean; Position: TMYLDBKeyPath): Boolean;
public
constructor Create(aIndexManager: TMYLDBBaseIndexManager);
destructor Destroy; override;
procedure CreateIndex(Cursor: TMYLDBCursor; aIndexDef: TMYLDBIndexDef); override;
procedure DropIndex(SessionID: TMYLDBSessionID); override;
procedure EmptyIndex(SessionID: TMYLDBSessionID); override;
procedure OpenIndex(aIndexDef: TMYLDBIndexDef); override;
procedure RebuildTemporaryIndex(Cursor: TMYLDBCursor); override;
procedure GetRecordBuffer(
SessionID: TMYLDBSessionID;
var NavigationInfo: TMYLDBNavigationInfo;
IndexPositionCache: TMYLDBIndexPositionCache;
TableState: Integer
); override;
procedure GetClosestRecordBuffer(
SessionID: TMYLDBSessionID;
var NavigationInfo: TMYLDBNavigationInfo;
IndexPositionCache: TMYLDBIndexPositionCache;
TableState: Integer
); override;
function CreateIndexPosition: TMYLDBIndexPosition; override;
procedure FreeIndexPosition(var IndexPosition: TMYLDBIndexPosition); override;
function GetIndexPosition(
SessionID: TMYLDBSessionID;
RecordID: TMYLDBRecordID;
RecordBuffer: TMYLDBRecordBuffer;
IndexPosition: TMYLDBIndexPosition
): Boolean; override;
// return 0, 1, -1 if (Pos1 = Pos2), (Pos1 > Pos2), (Pos1 < Pos2)
function CompareRecordPositionsInIndex(
RecordPosition1: TMYLDBIndexPosition;
RecordPosition2: TMYLDBIndexPosition
): Integer; override;
function GetRecNoByRecordID(
SessionID: TMYLDBSessionID;
RecordID: TMYLDBRecordID;
RecordBuffer: TMYLDBRecordBuffer
): TMYLDBRecordNo; override;
function GetRecordIDByRecNo(
SessionID: TMYLDBSessionID;
RecNo: TMYLDBRecordNo
): TMYLDBRecordID; override;
procedure ApplyDistinctToRecordBitmap(
SessionID: TMYLDBSessionID;
Bitmap: TMYLDBRecordBitmap;
DistinctFieldCount: Integer
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -