Fixed the wrong maintainance of the max_number_of_levels field in the

B+tree's header.
Some style cleanups.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1870 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2002-11-07 12:30:45 +00:00
parent 5f5bb7d7eb
commit e335b08a33
@@ -269,6 +269,8 @@ BPlusTree::~BPlusTree()
}
/** Create a new B+Tree on the specified stream */
status_t
BPlusTree::SetTo(Transaction *transaction, Inode *stream, int32 nodeSize)
{
@@ -429,7 +431,8 @@ BPlusTree::ModeToKeyType(mode_t mode)
void
BPlusTree::UpdateIterators(off_t offset,off_t nextOffset,uint16 keyIndex,uint16 splitAt,int8 change)
BPlusTree::UpdateIterators(off_t offset, off_t nextOffset, uint16 keyIndex, uint16 splitAt,
int8 change)
{
// Although every iterator which is affected by this update currently
// waits on a semaphore, other iterators could be added/removed at
@@ -502,7 +505,8 @@ BPlusTree::CompareKeys(const void *key1, int keyLength1, const void *key2, int k
status_t
BPlusTree::FindKey(bplustree_node *node,const uint8 *key,uint16 keyLength,uint16 *index,off_t *next)
BPlusTree::FindKey(bplustree_node *node, const uint8 *key, uint16 keyLength, uint16 *index,
off_t *next)
{
if (node->all_key_count == 0)
{
@@ -602,7 +606,8 @@ BPlusTree::SeekDown(Stack<node_and_key> &stack,const uint8 *key,uint16 keyLength
status_t
BPlusTree::FindFreeDuplicateFragment(bplustree_node *node,CachedNode *cached,off_t *_offset,bplustree_node **_fragment,uint32 *_index)
BPlusTree::FindFreeDuplicateFragment(bplustree_node *node, CachedNode *cached, off_t *_offset,
bplustree_node **_fragment, uint32 *_index)
{
off_t *values = node->Values();
for (int32 i = 0;i < node->all_key_count;i++) {
@@ -634,7 +639,8 @@ BPlusTree::FindFreeDuplicateFragment(bplustree_node *node,CachedNode *cached,off
status_t
BPlusTree::InsertDuplicate(Transaction *transaction,CachedNode *cached,bplustree_node *node,uint16 index,off_t value)
BPlusTree::InsertDuplicate(Transaction *transaction, CachedNode *cached, bplustree_node *node,
uint16 index, off_t value)
{
CachedNode cachedDuplicate(this);
off_t *values = node->Values();
@@ -684,7 +690,8 @@ BPlusTree::InsertDuplicate(Transaction *transaction,CachedNode *cached,bplustree
// copy the array from the fragment node to the duplicate node
// and free the old entry (by zero'ing all values)
newDuplicate->overflow_link = array->count;
memcpy(&newDuplicate->all_key_count,&array->values[0],array->count * sizeof(off_t));
memcpy(&newDuplicate->all_key_count, &array->values[0],
array->count * sizeof(off_t));
memset(array,0,(NUM_FRAGMENT_VALUES + 1) * sizeof(off_t));
array = newDuplicate->DuplicateArray();
@@ -721,12 +728,13 @@ BPlusTree::InsertDuplicate(Transaction *transaction,CachedNode *cached,bplustree
return B_IO_ERROR;
array = duplicate->DuplicateArray();
if (array->count > NUM_DUPLICATE_VALUES
|| array->count < 0) {
FATAL(("removeDuplicate: Invalid array size in duplicate %Ld == %Ld!\n",duplicateOffset,array->count));
if (array->count > NUM_DUPLICATE_VALUES || array->count < 0) {
FATAL(("removeDuplicate: Invalid array size in duplicate %Ld == %Ld!\n",
duplicateOffset,array->count));
return B_BAD_DATA;
}
} while (array->count >= NUM_DUPLICATE_VALUES && (oldValue = duplicate->right_link) != BPLUSTREE_NULL);
} while (array->count >= NUM_DUPLICATE_VALUES
&& (oldValue = duplicate->right_link) != BPLUSTREE_NULL);
if (array->count < NUM_DUPLICATE_VALUES) {
array->Insert(value);
@@ -782,7 +790,8 @@ BPlusTree::InsertDuplicate(Transaction *transaction,CachedNode *cached,bplustree
void
BPlusTree::InsertKey(bplustree_node *node,uint16 index,uint8 *key,uint16 keyLength,off_t value)
BPlusTree::InsertKey(bplustree_node *node, uint16 index, uint8 *key, uint16 keyLength,
off_t value)
{
// should never happen, but who knows?
if (index > node->all_key_count)
@@ -822,7 +831,8 @@ BPlusTree::InsertKey(bplustree_node *node,uint16 index,uint8 *key,uint16 keyLeng
status_t
BPlusTree::SplitNode(bplustree_node *node,off_t nodeOffset,bplustree_node *other,off_t otherOffset,uint16 *_keyIndex,uint8 *key,uint16 *_keyLength,off_t *_value)
BPlusTree::SplitNode(bplustree_node *node,off_t nodeOffset,bplustree_node *other,
off_t otherOffset, uint16 *_keyIndex, uint8 *key, uint16 *_keyLength, off_t *_value)
{
if (*_keyIndex > node->all_key_count + 1)
return B_BAD_VALUE;
@@ -1073,7 +1083,7 @@ BPlusTree::Insert(Transaction *transaction,const uint8 *key,uint16 keyLength,off
if (status == B_OK) {
if (fAllowDuplicates)
return InsertDuplicate(transaction, &cached, node, nodeAndKey.keyIndex, value);
else
RETURN_ERROR(B_NAME_IN_USE);
}
}
@@ -1116,7 +1126,8 @@ BPlusTree::Insert(Transaction *transaction,const uint8 *key,uint16 keyLength,off
RETURN_ERROR(status);
}
if (SplitNode(node,nodeAndKey.nodeOffset,other,otherOffset,&nodeAndKey.keyIndex,keyBuffer,&keyLength,&value) < B_OK) {
if (SplitNode(node, nodeAndKey.nodeOffset, other, otherOffset,
&nodeAndKey.keyIndex, keyBuffer, &keyLength, &value) < B_OK) {
// free root node & other node here
cachedNewRoot.Free(transaction, newRoot);
cachedOther.Free(transaction, otherOffset);
@@ -1130,7 +1141,8 @@ BPlusTree::Insert(Transaction *transaction,const uint8 *key,uint16 keyLength,off
|| cachedOther.WriteBack(transaction) < B_OK)
RETURN_ERROR(B_ERROR);
UpdateIterators(nodeAndKey.nodeOffset,otherOffset,nodeAndKey.keyIndex,node->all_key_count,1);
UpdateIterators(nodeAndKey.nodeOffset, otherOffset, nodeAndKey.keyIndex,
node->all_key_count, 1);
// update the right link of the node in the left of the new node
if ((other = cachedOther.SetTo(other->left_link)) != NULL) {
@@ -1162,7 +1174,8 @@ BPlusTree::Insert(Transaction *transaction,const uint8 *key,uint16 keyLength,off
status_t
BPlusTree::RemoveDuplicate(Transaction *transaction,bplustree_node *node,CachedNode *cached,uint16 index,off_t value)
BPlusTree::RemoveDuplicate(Transaction *transaction, bplustree_node *node, CachedNode *cached,
uint16 index, off_t value)
{
CachedNode cachedDuplicate(this);
off_t *values = node->Values();
@@ -1447,9 +1460,14 @@ BPlusTree::Remove(Transaction *transaction,const uint8 *key,uint16 keyLength,off
if (cached.WriteBack(transaction) < B_OK)
return B_IO_ERROR;
// if we've cleared the root node, reset the maximum
// number of levels in the header
if (nodeAndKey.nodeOffset == fHeader->root_node_pointer) {
fHeader->max_number_of_levels = 1;
return fCachedHeader.WriteBack(transaction);
}
return B_OK;
}
// if there is only one key left, we don't have to remove
// it, we can just dump the node (index nodes still have
@@ -1656,7 +1674,8 @@ TreeIterator::Goto(int8 to)
*/
status_t
TreeIterator::Traverse(int8 direction,void *key,uint16 *keyLength,uint16 maxLength,off_t *value,uint16 *duplicate)
TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxLength,
off_t *value, uint16 *duplicate)
{
if (fTree == NULL)
return B_INTERRUPTED;