/*
* Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
*
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
File: BTreeTreeOps.c
PanicIf ((level == 1) && (((NodeDescPtr)targetNode->buffer)->kind != kBTLeafNode), "\P InsertLevel: non-leaf at level 1! ");
#endif
leftNode.buffer = nil;
+ leftNode.blockHeader = nil;
targetNodeNum = treePathTable [level].node;
insertParent = false;
updateParent = false;
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, targetNode);
+
////// process first insert //////
-
+
err = InsertNode (btreePtr, primaryKey, targetNode, targetNodeNum, index,
&newNodeNum, &newIndex, &leftNode, &updateParent, &insertParent, &newRoot );
M_ExitOnError (err);
UInt8 * recPtr;
UInt16 recSize;
+ parentNode.buffer = nil;
+ parentNode.blockHeader = nil;
+
secondaryKey = nil;
PanicIf ( (level == btreePtr->treeDepth), "\p InsertLevel: unfinished insert!?");
if ( updateParent )
{
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, &parentNode);
+
//\80\80 debug: check if ptr == targetNodeNum
GetRecordByIndex (btreePtr, parentNode.buffer, index, &keyPtr, &recPtr, &recSize);
PanicIf( (*(UInt32 *) recPtr) != targetNodeNum, "\p InsertLevel: parent ptr doesn't match target node!");
(void) ReleaseNode (btreePtr, targetNode);
(void) ReleaseNode (btreePtr, &leftNode);
- Panic ("\p InsertLevel: an error occured!");
+ Panic ("\p InsertLevel: an error occurred!");
return err;
{
err = GetNode (btreePtr, leftNodeNum, leftNode); // will be released by caller or a split below
M_ExitOnError (err);
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, leftNode);
}
PanicIf ( ((NodeDescPtr) leftNode->buffer)->fLink != node, "\p InsertNode, RotateLeft: invalid sibling link!" );
return noErr;
ErrorExit:
-
(void) ReleaseNode (btreePtr, leftNode);
return err;
Boolean deleteRequired;
Boolean updateRequired;
-
+ // XXXdbg - initialize these to null in case we get an
+ // error and try to exit before it's initialized
+ parentNode.buffer = nil;
+ parentNode.blockHeader = nil;
+
deleteRequired = false;
updateRequired = false;
targetNodePtr = targetNode->buffer;
PanicIf (targetNodePtr == nil, "\pDeleteTree: targetNode has nil buffer!");
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, targetNode);
+
DeleteRecord (btreePtr, targetNodePtr, index);
//\80\80 coalesce remaining records?
deleteRequired = true;
+ siblingNode.buffer = nil;
+ siblingNode.blockHeader = nil;
+
////////////////// Get Siblings & Update Links //////////////////////////
siblingNodeNum = targetNodePtr->bLink; // Left Sibling Node
{
err = GetNode (btreePtr, siblingNodeNum, &siblingNode);
M_ExitOnError (err);
+
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, &siblingNode);
+
((NodeDescPtr)siblingNode.buffer)->fLink = targetNodePtr->fLink;
err = UpdateNode (btreePtr, &siblingNode, 0, kLockTransaction);
M_ExitOnError (err);
{
err = GetNode (btreePtr, siblingNodeNum, &siblingNode);
M_ExitOnError (err);
+
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, &siblingNode);
+
((NodeDescPtr)siblingNode.buffer)->bLink = targetNodePtr->bLink;
err = UpdateNode (btreePtr, &siblingNode, 0, kLockTransaction);
M_ExitOnError (err);
err = UpdateNode (btreePtr, targetNode, 0, kLockTransaction);
M_ExitOnError (err);
+
err = FreeNode (btreePtr, targetNodeNum);
M_ExitOnError (err);
}
UInt16 recSize;
UInt32 insertNode;
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, &parentNode);
+
//\80\80 debug: check if ptr == targetNodeNum
GetRecordByIndex (btreePtr, parentNode.buffer, index, &keyPtr, &recPtr, &recSize);
PanicIf( (*(UInt32 *) recPtr) != targetNodeNum, "\p DeleteTree: parent ptr doesn't match targetNodeNum!!");
return noErr;
ErrorExit:
-
+
(void) ReleaseNode (btreePtr, targetNode);
(void) ReleaseNode (btreePtr, &parentNode);
originalRoot = btreePtr->rootNode;
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, blockPtr);
+
while (true)
{
if ( ((NodeDescPtr)blockPtr->buffer)->numRecords > 1)
//// Get New Root Node
err = GetNode (btreePtr, btreePtr->rootNode, blockPtr);
M_ExitOnError (err);
+
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, blockPtr);
}
if (btreePtr->rootNode != originalRoot)
if ( left != nil )
{
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, leftNode);
+
left->fLink = newNodeNum;
err = UpdateNode (btreePtr, leftNode, 0, kLockTransaction);
M_ExitOnError (err);
err = GetNewNode (btreePtr, newNodeNum, leftNode);
M_ExitOnError (err);
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, leftNode);
+
left = leftNode->buffer;
left->fLink = rightNodeNum;
err = RotateLeft (btreePtr, left, right, index, keyPtr, recPtr, recSize,
insertIndex, insertNodeNum, &recordFit, recsRotated);
- M_ExitOnError (err);
+ M_ExitOnError (err);
+
return noErr;
ErrorExit:
Boolean didItFit;
UInt16 keyLength;
+ rootNode.buffer = nil;
+ rootNode.blockHeader = nil;
+
PanicIf (leftNode == nil, "\pAddNewRootNode: leftNode == nil");
PanicIf (rightNode == nil, "\pAddNewRootNode: rightNode == nil");
err = GetNewNode (btreePtr, rootNum, &rootNode);
M_ExitOnError (err);
+ // XXXdbg
+ ModifyBlockStart(btreePtr->fileRefNum, &rootNode);
+
((NodeDescPtr)rootNode.buffer)->kind = kBTIndexNode;
((NodeDescPtr)rootNode.buffer)->height = ++btreePtr->treeDepth;