| 3383 | |
| 3384 | |
| 3385 | static contents delete_node(thread_db* tdbb, WIN* window, UCHAR* pointer) |
| 3386 | { |
| 3387 | /************************************** |
| 3388 | * |
| 3389 | * d e l e t e _ n o d e |
| 3390 | * |
| 3391 | ************************************** |
| 3392 | * |
| 3393 | * Functional description |
| 3394 | * Delete a node from a page and return whether it |
| 3395 | * empty, if there is a single node on it, or if it |
| 3396 | * is above or below the threshold for garbage collection. |
| 3397 | * |
| 3398 | **************************************/ |
| 3399 | |
| 3400 | SET_TDBB(tdbb); |
| 3401 | const Database* dbb = tdbb->getDatabase(); |
| 3402 | CHECK_DBB(dbb); |
| 3403 | |
| 3404 | btree_page* page = (btree_page*) window->win_buffer; |
| 3405 | |
| 3406 | CCH_MARK(tdbb, window); |
| 3407 | |
| 3408 | const bool leafPage = (page->btr_level == 0); |
| 3409 | |
| 3410 | // Read node that need to be removed |
| 3411 | IndexNode removingNode; |
| 3412 | UCHAR* localPointer = removingNode.readNode(pointer, leafPage); |
| 3413 | const USHORT offsetDeletePoint = (pointer - (UCHAR*) page); |
| 3414 | |
| 3415 | // Read the next node after the removing node |
| 3416 | IndexNode nextNode; |
| 3417 | const USHORT offsetNextPoint = (localPointer - (UCHAR*) page); |
| 3418 | localPointer = nextNode.readNode(localPointer, leafPage); |
| 3419 | |
| 3420 | // Save data in tempKey so we can rebuild from it |
| 3421 | USHORT newNextPrefix = nextNode.prefix; |
| 3422 | USHORT newNextLength = 0; |
| 3423 | USHORT length = MAX(removingNode.length + removingNode.prefix, nextNode.length + nextNode.prefix); |
| 3424 | HalfStaticArray<UCHAR, MAX_KEY> tempBuf; |
| 3425 | UCHAR* tempData = tempBuf.getBuffer(length); |
| 3426 | length = 0; |
| 3427 | if (nextNode.prefix > removingNode.prefix) |
| 3428 | { |
| 3429 | // The next node uses data from the node that is going to |
| 3430 | // be removed so save it. |
| 3431 | length = nextNode.prefix - removingNode.prefix; |
| 3432 | newNextPrefix -= length; |
| 3433 | newNextLength += length; |
| 3434 | memcpy(tempData, removingNode.data, length); |
| 3435 | } |
| 3436 | memcpy(tempData + length, nextNode.data, nextNode.length); |
| 3437 | newNextLength += nextNode.length; |
| 3438 | |
| 3439 | // Update the page prefix total. |
| 3440 | page->btr_prefix_total -= (removingNode.prefix + (nextNode.prefix - newNextPrefix)); |
| 3441 | |
| 3442 | // Update the next node so we are ready to save it. |
no test coverage detected