本文整理汇总了C++中STORM_PageHandle::GetDataPtr方法的典型用法代码示例。如果您正苦于以下问题:C++ STORM_PageHandle::GetDataPtr方法的具体用法?C++ STORM_PageHandle::GetDataPtr怎么用?C++ STORM_PageHandle::GetDataPtr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类STORM_PageHandle
的用法示例。
在下文中一共展示了STORM_PageHandle::GetDataPtr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateLastDataPage
t_rc INXM_IndexHandle::CreateLastDataPage(STORM_PageHandle &pageHandle) {
t_rc rc;
int pageID;
rc = this->sfh.ReservePage(pageHandle);
if (rc != OK) { return rc; }
rc = pageHandle.GetPageID(pageID);
if (rc != OK) { return rc; }
char *pageData;
rc = pageHandle.GetDataPtr(&pageData);
if (rc != OK) { return rc; }
/* Write index init page header */
INXM_InitPageHeader pageHeader = { 1, 0 };
memcpy(pageData, &pageHeader, INXM_INITPAGEHEADER_SIZE);
/* Update file header (new lastDataPage). */
this->inxmFileHeader.lastDataPage = pageID;
memcpy(this->pData_FileHeader, &this->inxmFileHeader, INXM_FILEHEADER_SIZE);
rc = this->sfh.FlushPage(this->pageNum_FileHeader);
if (rc != OK) { return rc; }
return(OK);
}
示例2: CreateNodePage
t_rc INXM_IndexHandle::CreateNodePage(STORM_PageHandle &pageHandle, int &pageID, int parent, int next, int previous, bool isLeaf) {
t_rc rc;
rc = this->sfh.ReservePage(pageHandle);
if (rc != OK) { return rc; }
rc = pageHandle.GetPageID(pageID);
if (rc != OK) { return rc; }
char *pageData;
rc = pageHandle.GetDataPtr(&pageData);
if (rc != OK) { return rc; }
/* Write index init page header */
INXM_InitPageHeader pageHeader = { 0, 0 };
memcpy(pageData, &pageHeader, INXM_INITPAGEHEADER_SIZE);
/* Write index node page header */
INXM_NodePageHeader nPageHeader = { isLeaf, parent, next, previous };
memcpy(&pageData[INXM_INITPAGEHEADER_SIZE], &nPageHeader, INXM_NODEPAGEHEADER_SIZE);
return(OK);
}
示例3: ReadRecord
/* We have a const problem with the method. We call GetPage from STORM which is not const!!! */
t_rc REM_RecordFileHandle::ReadRecord(const REM_RecordID &rid, REM_RecordHandle &rh) {
/* Check is file is open. */
if (!this->isOpen) {
return REM_FHCLOSED;
}
t_rc rc;
/* Get pageID and slot number to find the record. */
int pageID, slot;
rc = rid.GetPageID(pageID);
if (rc != OK) {
return rc;
}
rc = rid.GetSlot(slot);
if (rc != OK) {
return rc;
}
/* Get the STORM page that contains the record we need. */
STORM_PageHandle pageHandle;
rc = this->sfh.GetPage(pageID, pageHandle);
if (rc != OK) {
return rc;
}
/* Check if REM Record Handler has data. If it doesn't, allocate the needed space. */
if (rh.pData == NULL) {
rh.pData = new char[this->remFileHeader.recordSize];
}
else {
delete rh.pData;
rh.pData = new char[this->remFileHeader.recordSize];
}
char *pData;
REM_PageHeader pageHeader;
pageHandle.GetDataPtr(&pData);
/* Check if slot number is not correct. */
memcpy(&pageHeader, pData, REM_PAGEHEADER_SIZE);
if (slot > pageHeader.nRecords) {
return REM_INVALIDRID;
}
/* Find the record we want and copy the data to the record handler. */
memcpy(rh.pData, &pData[REM_PAGEHEADER_SIZE+((slot-1)*this->remFileHeader.recordSize)], this->remFileHeader.recordSize);
/* Add the recordID to the record handler. */
rh.rid = rid;
/* Make Record Handler valid. */
rh.isValid = true;
return (OK);
}
示例4: UpdateRecord
t_rc REM_RecordFileHandle::UpdateRecord(const REM_RecordHandle &rh) {
/* Check is file is open. */
if (!this->isOpen) {
return REM_FHCLOSED;
}
t_rc rc;
/* Exctract RID and get pageID and slot numbers. */
REM_RecordID rid;
int pageID, slot;
rc = rh.GetRecordID(rid);
if (rc != OK) {
return rc;
}
rc = rid.GetPageID(pageID);
if (rc != OK) {
return rc;
}
rc = rid.GetSlot(slot);
if (rc != OK) {
return rc;
}
/* Get the record and a pointer to the data inside. */
STORM_PageHandle pageHandle;
char *pData;
rc = this->sfh.GetPage(pageID, pageHandle);
if (rc != OK) {
return rc;
}
rc = pageHandle.GetDataPtr(&pData);
if (rc != OK) {
return rc;
}
/* Copy the new data. */
memcpy(&pData[REM_PAGEHEADER_SIZE+((slot-1)*this->remFileHeader.recordSize)], rh.pData, this->remFileHeader.recordSize);
/* Mark the page as dirty because we modified it */
rc = this->sfh.MarkPageDirty(pageID);
if (rc != OK) {
return rc;
}
/* Unpin the page */
rc = this->sfh.UnpinPage(pageID);
if (rc != OK) {
return rc;
}
return (OK);
}
示例5: makeRoot
// Δημιουργία νέου κόμβου/ρίζα
t_rc INXM_IndexHandle::makeRoot(void *pData, const REM_RecordID &rid){
t_rc rc;
int pageID;
STORM_PageHandle myPageHandle;
// Δέσμευση σελίδας
rc = this->fh.ReservePage(myPageHandle);
if (rc != OK) return rc;
rc = this->fh.GetNextPage(this->fileHeaderPageID, myPageHandle);
if (rc != OK) return rc;
rc = myPageHandle.GetPageID(pageID);
if (rc != OK) { return rc; }
char* rData;
rc = myPageHandle.GetDataPtr(&rData);
if (rc != OK) { return rc; }
this->fileHeader.rootPage = pageID;
// Δημιουργία header για τη σελίδα
// Κάθε σελίδα είναι και node
NodeHeader nh;
nh.numberOfItems = 1;
for (int i = 0; i < 1200; i++)
nh.sStatus.set(i,false);
nh.sStatus.set(0, true);
nh.left = -1;
nh.right = -1;
nh.parent = -1;
nh.leaf = true;
LeafItem item = { pData, rid };
// Εγγραφή του αντικειμένου
memcpy(&rData[sizeof(NodeHeader)], this->getLeafItemData(item), this->getLeafItemSize());
this->fileHeader.numberOfNodes++;
this->fileHeader.numberOfLeafNodes++;
// Εγγραφή του nodeheader
memcpy(&rData[0], &nh, sizeof(NodeHeader));
rc = this->fh.MarkPageDirty(pageID);
if (rc != OK) return rc;
rc = this->fh.FlushPage(pageID);
if (rc != OK) return rc;
rc = this->fh.UnpinPage(pageID);
if (rc != OK) return rc;
return(OK);
}
示例6: EditNode
t_rc INXM_IndexHandle::EditNode(STORM_PageHandle pageHandle, int slot, INXM_Node node) {
t_rc rc;
char *dataPageData;
rc = pageHandle.GetDataPtr(&dataPageData);
if (rc != OK) { return rc; }
memcpy(&dataPageData[INXM_INITPAGEHEADER_SIZE+INXM_NODEPAGEHEADER_SIZE+(slot*(INXM_NODE_SIZE+this->inxmFileHeader.attrLength))], &node, INXM_NODE_SIZE+this->inxmFileHeader.attrLength);
return(OK);
}
示例7: EditData
t_rc INXM_IndexHandle::EditData(STORM_PageHandle pageHandle, int slot, INXM_Data data) {
t_rc rc;
char *dataPageData;
rc = pageHandle.GetDataPtr(&dataPageData);
if (rc != OK) { return rc; }
memcpy(&dataPageData[INXM_INITPAGEHEADER_SIZE+(slot*INXM_DATA_SIZE)], &data, INXM_DATA_SIZE);
return(OK);
}
示例8: InsertEntry
t_rc INXM_IndexHandle::InsertEntry(void *pData, const REM_RecordID &rid){
t_rc rc;
STORM_PageHandle pageHandle;
/*
* Έλεγχος αν υπάρχει δέντρο
* Δημιουργία νέου δέντρου/ρίζας
*/
if( this->isOpen && this->fileHeader.numberOfNodes == 0 ){
makeRoot(pData, rid);
return(OK);
}
/*
* Υπάρχει ήδη δέντρο
*/
// Αναζήτηση για την εύρεση της ΣΩΣΤΗΣ σελίδας/φύλλου όπου θα μπεί ή νέα εγγραφή
int rightPageID = searchRightPage( fileHeader.rootPage , pData);
// Διαβάζω τον header αυτής της σελίδας
char* data;
rc = fh.GetPage(rightPageID, pageHandle);
if (rc != OK) return rc;
rc = pageHandle.GetDataPtr(&data);
if (rc != OK) return rc;
NodeHeader rightPageHeader;
memcpy(&rightPageHeader, &data[0], sizeof(NodeHeader));
// Έλεγχος αν η σελίδα έχει χώρο
bool freeSpace = checkLeafNodeForSpace(rightPageHeader);
if(freeSpace){ // περίπτωση που η σελίδα έχει χώρο
insert(rightPageID, pData, rid);
return (OK);
} else { // περίπτωση που η σελίδα ΔΕΝ έχει χώρο
rc = splitLeafNode(rightPageID);
if (rc != OK) return rc;
int pageAfterSplitID = searchRightPage( fileHeader.rootPage , pData);
insert(pageAfterSplitID, pData, rid);
return (OK);
}
}
示例9: LoadInitHeaders
t_rc INXM_IndexHandle::LoadInitHeaders(STORM_PageHandle pageHandle, INXM_InitPageHeader &initPageHeader) {
t_rc rc;
/* Read headers. */
char *nodePage;
rc = pageHandle.GetDataPtr(&nodePage);
if (rc != OK) { return rc; }
/* init page header. */
memcpy(&initPageHeader, nodePage, INXM_INITPAGEHEADER_SIZE);
return(OK);
}
示例10: ReadData
t_rc INXM_IndexHandle::ReadData(STORM_PageHandle pageHandle, int slot, INXM_Data &data) {
t_rc rc;
/* Read headers. */
char *dataPage;
rc = pageHandle.GetDataPtr(&dataPage);
if (rc != OK) { return rc; }
/* Read data. */
memcpy(&data, &dataPage[INXM_INITPAGEHEADER_SIZE+slot*INXM_DATA_SIZE], INXM_DATA_SIZE);
return(OK);
}
示例11: InsertIntoLeaf
t_rc INXM_IndexHandle::InsertIntoLeaf(STORM_PageHandle leafPageHandle, void *key, const REM_RecordID &rid) {
t_rc rc;
/* Find correct point for the new key. */
INXM_InitPageHeader initPageHeader;
LoadInitHeaders(leafPageHandle, initPageHeader);
INXM_Node node;
int insertPoint = 0;
rc = ReadNode(leafPageHandle, insertPoint, node);
if (rc != OK) { return rc; }
while (insertPoint < initPageHeader.nItems && KeyCmp(node.key, key) < 0) {
insertPoint++;
rc = ReadNode(leafPageHandle, insertPoint, node);
if (rc != OK) { return rc; }
}
/* Open needed space at correct point. */
int point = INXM_INITPAGEHEADER_SIZE + INXM_NODEPAGEHEADER_SIZE + insertPoint*(INXM_NODE_SIZE+this->inxmFileHeader.attrLength);
char *leafData;
rc = leafPageHandle.GetDataPtr(&leafData);
if (rc != OK) { return rc; }
memcpy(&leafData[point + INXM_NODE_SIZE+this->inxmFileHeader.attrLength],
&leafData[point],
(initPageHeader.nItems-insertPoint)*(INXM_NODE_SIZE+this->inxmFileHeader.attrLength));
/* Write new data. */
int slot;
STORM_PageHandle lastDataPageHandle;
rc = this->sfh.GetPage(this->inxmFileHeader.lastDataPage, lastDataPageHandle);
if (rc != OK) { return rc; }
rc = WriteData(lastDataPageHandle, rid, slot);
if (rc != OK) { return rc; }
/* Write new node. */
rc = WriteNode(leafPageHandle, insertPoint, key, this->inxmFileHeader.lastDataPage, slot);
if (rc != OK) { return rc; }
return(OK);
}
示例12: UpdateNodeHeaders
t_rc INXM_IndexHandle::UpdateNodeHeaders(STORM_PageHandle pageHandle, INXM_InitPageHeader initPageHeader, INXM_NodePageHeader nodePageHeader) {
t_rc rc;
/* Get page data pointer. */
char *nodePage;
rc = pageHandle.GetDataPtr(&nodePage);
if (rc != OK) { return rc; }
/* init page header. */
memcpy(nodePage, &initPageHeader, INXM_INITPAGEHEADER_SIZE);
/* node page header. */
memcpy(&nodePage[INXM_INITPAGEHEADER_SIZE], &nodePageHeader, INXM_NODEPAGEHEADER_SIZE);
return(OK);
}
示例13: WriteData
t_rc INXM_IndexHandle::WriteData(STORM_PageHandle pageHandle, const REM_RecordID &rid, int &slot) {
t_rc rc;
INXM_Data *inxmData = new INXM_Data();
rid.GetPageID(inxmData->pageID);
rid.GetSlot(inxmData->slot);
char *leafPageData;
rc = pageHandle.GetDataPtr(&leafPageData);
if (rc != OK) { return rc; }
/* Read leaf header. */
INXM_InitPageHeader pageHeader;
memcpy(&pageHeader, leafPageData, INXM_INITPAGEHEADER_SIZE);
/* Write data to correct place. */
memcpy(&leafPageData[INXM_INITPAGEHEADER_SIZE+pageHeader.nItems*INXM_DATA_SIZE], inxmData, INXM_DATA_SIZE);
/* Update page header. */
slot = pageHeader.nItems;
pageHeader.nItems++;
memcpy(leafPageData, &pageHeader, INXM_INITPAGEHEADER_SIZE);
int pageID;
rc = pageHandle.GetPageID(pageID);
if (rc != OK) { return rc; }
/* Mark the page as dirty because we modified it */
rc = this->sfh.MarkPageDirty(pageID);
if (rc != OK) { return rc; }
rc = this->sfh.FlushPage(pageID);
if (rc != OK) { return rc; }
/* Unpin the page */
rc = this->sfh.UnpinPage (pageID);
if (rc != OK) { return rc; }
return(OK);
}
示例14: WriteNode
t_rc INXM_IndexHandle::WriteNode(STORM_PageHandle pageHandle, int insertPoint, void *key, int left, int slot) {
t_rc rc;
INXM_Node *node = new INXM_Node();
node->left = left;
node->slot = slot;
char *nodePageData;
rc = pageHandle.GetDataPtr(&nodePageData);
if (rc != OK) { return rc; }
/* Write data to correct place. */
memcpy(&nodePageData[INXM_INITPAGEHEADER_SIZE+INXM_NODEPAGEHEADER_SIZE+insertPoint*(INXM_NODE_SIZE+this->inxmFileHeader.attrLength)], node, INXM_NODE_SIZE);
memcpy(&nodePageData[INXM_INITPAGEHEADER_SIZE+INXM_NODEPAGEHEADER_SIZE+insertPoint*(INXM_NODE_SIZE+this->inxmFileHeader.attrLength)+INXM_NODE_SIZE], key, this->inxmFileHeader.attrLength);
/* Update page header. */
INXM_InitPageHeader pageHeader;
rc = LoadInitHeaders(pageHandle, pageHeader);
if (rc != OK) { return rc; }
pageHeader.nItems++;
memcpy(nodePageData, &pageHeader, INXM_INITPAGEHEADER_SIZE);
int pageID;
rc = pageHandle.GetPageID(pageID);
if (rc != OK) { return rc; }
/* Mark the page as dirty because we modified it */
rc = this->sfh.MarkPageDirty(pageID);
if (rc != OK) { return rc; }
rc = this->sfh.FlushPage(pageID);
if (rc != OK) { return rc; }
/* Unpin the page */
rc = this->sfh.UnpinPage (pageID);
if (rc != OK) { return rc; }
return(OK);
}
示例15: searchRightPage
// Επιστρέφει το id της σελίδας που θα πρέπει να γίνει η
// εισαγωγή του νέου στοιχείου
int INXM_IndexHandle::searchRightPage(int pageID, void* key){
STORM_PageHandle pageHandle;
char* data;
// Διαβάζουμε τον header της σελίδας
fh.GetPage(pageID, pageHandle);
pageHandle.GetDataPtr(&data);
NodeHeader currentHeader;
memcpy(¤tHeader, &data[0], sizeof(NodeHeader));
if( currentHeader.leaf == true ){
// ο κόμβος που μόλις διάβασα είναι φύλλο, τελειώνει η αναζήτηση
return pageID;
} else {
// ο κόμβος που μόλις διάβασα είναι ενδιάμεσος, ελέγχω τις τιμές
for(int i = 0; i < currentHeader.numberOfItems; i++){
InterItem currentItem, nextItem;
char* currentData = new char[this->getInterItemSize()];
memcpy(currentData, &data[sizeof(NodeHeader)+i*this->getInterItemSize()], this->getInterItemSize());
currentItem = this->getInterItemStruct(currentData);
memcpy(currentData, &data[sizeof(NodeHeader)+(i+1)*this->getInterItemSize()], this->getInterItemSize());
nextItem = this->getInterItemStruct(currentData);
if(keyCompare(key, currentItem.key) < 0 ){
// akoloutha aristero paidi
searchRightPage(currentItem.leftChild, key);
} else if ( (keyCompare(key, currentItem.key) > 0) && ((keyCompare(key, nextItem.key) == 0) || (keyCompare(key, nextItem.key) < 0))) {
// akoloutha aristero paidi
searchRightPage(nextItem.leftChild, key);
} else if ((keyCompare(key, currentItem.key) > 0) || (keyCompare(key, currentItem.key) == 0)){
//akoloutha deksi paidi
searchRightPage(currentItem.leftChild, key);
}
}
}
}