* Fixed warnings.

* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37248 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-06-25 08:02:37 +00:00
parent 1e0ea42a25
commit 2f0e75de7b
2 changed files with 46 additions and 38 deletions
@@ -1,10 +1,9 @@
/* BPlusTree - BFS B+Tree implementation /*
* Copyright 2001-2010, Axel Dörfler, [email protected].
* This file may be used under the terms of the MIT License.
* *
* Roughly based on 'btlib' written by Marcus J. Ranum - it shares * Roughly based on 'btlib' written by Marcus J. Ranum - it shares
* no code but achieves binary compatibility with the on disk format. * no code but achieves binary compatibility with the on disk format.
*
* Copyright 2001-2005, Axel Dörfler, [email protected].
* This file may be used under the terms of the MIT License.
*/ */
@@ -23,6 +22,7 @@
using namespace BFS; using namespace BFS;
// Node Caching for the BPlusTree class // Node Caching for the BPlusTree class
// //
// With write support, there is the need for a function that allocates new // With write support, there is the need for a function that allocates new
@@ -35,6 +35,7 @@ using namespace BFS;
// Since BFS supports block sizes of 1024 bytes or greater, and the node size // Since BFS supports block sizes of 1024 bytes or greater, and the node size
// is hard-coded to 1024 bytes, that's not an issue now. // is hard-coded to 1024 bytes, that's not an issue now.
void void
CachedNode::Unset() CachedNode::Unset()
{ {
@@ -68,13 +69,14 @@ CachedNode::SetTo(off_t offset, bool check)
if (!header->IsValidLink(fNode->LeftLink()) if (!header->IsValidLink(fNode->LeftLink())
|| !header->IsValidLink(fNode->RightLink()) || !header->IsValidLink(fNode->RightLink())
|| !header->IsValidLink(fNode->OverflowLink()) || !header->IsValidLink(fNode->OverflowLink())
|| (int8 *)fNode->Values() + fNode->NumKeys() * sizeof(off_t) > || (int8 *)fNode->Values() + fNode->NumKeys() * sizeof(off_t)
(int8 *)fNode + fTree->fNodeSize) { > (int8 *)fNode + fTree->fNodeSize) {
dprintf("invalid node read from offset %Ld, inode at %Ld\n", dprintf("invalid node read from offset %Ld, inode at %Ld\n",
offset, fTree->fStream->ID()); offset, fTree->fStream->ID());
return NULL; return NULL;
} }
} }
return fNode; return fNode;
} }
@@ -111,7 +113,8 @@ CachedNode::InternalSetTo(off_t offset)
if (fBlock == NULL) if (fBlock == NULL)
return NULL; return NULL;
} }
if (read_pos(volume.Device(), fBlockNumber << volume.BlockShift(), fBlock, volume.BlockSize()) < (ssize_t)volume.BlockSize()) if (read_pos(volume.Device(), fBlockNumber << volume.BlockShift(),
fBlock, volume.BlockSize()) < (ssize_t)volume.BlockSize())
return NULL; return NULL;
// the node is somewhere in that block... (confusing offset calculation) // the node is somewhere in that block... (confusing offset calculation)
@@ -166,13 +169,16 @@ BPlusTree::SetTo(Stream *stream)
fNodeSize = fHeader->NodeSize(); fNodeSize = fHeader->NodeSize();
{ {
uint32 toMode[] = {S_STR_INDEX, S_INT_INDEX, S_UINT_INDEX, S_LONG_LONG_INDEX, uint32 toMode[] = {S_STR_INDEX, S_INT_INDEX, S_UINT_INDEX,
S_ULONG_LONG_INDEX, S_FLOAT_INDEX, S_DOUBLE_INDEX}; S_LONG_LONG_INDEX, S_ULONG_LONG_INDEX, S_FLOAT_INDEX,
uint32 mode = stream->Mode() & (S_STR_INDEX | S_INT_INDEX | S_UINT_INDEX | S_LONG_LONG_INDEX S_DOUBLE_INDEX};
| S_ULONG_LONG_INDEX | S_FLOAT_INDEX | S_DOUBLE_INDEX); uint32 mode = stream->Mode() & (S_STR_INDEX | S_INT_INDEX
| S_UINT_INDEX | S_LONG_LONG_INDEX | S_ULONG_LONG_INDEX
| S_FLOAT_INDEX | S_DOUBLE_INDEX);
if (fHeader->DataType() > BPLUSTREE_DOUBLE_TYPE if (fHeader->DataType() > BPLUSTREE_DOUBLE_TYPE
|| (stream->Mode() & S_INDEX_DIR) && toMode[fHeader->DataType()] != mode || ((stream->Mode() & S_INDEX_DIR) != 0
&& toMode[fHeader->DataType()] != mode)
|| !stream->IsContainer()) { || !stream->IsContainer()) {
return fStatus = B_BAD_TYPE; return fStatus = B_BAD_TYPE;
} }
@@ -181,8 +187,8 @@ BPlusTree::SetTo(Stream *stream)
// although it's in stat.h, the S_ALLOW_DUPS flag is obviously unused // although it's in stat.h, the S_ALLOW_DUPS flag is obviously unused
// in the original BFS code - we will honour it nevertheless // in the original BFS code - we will honour it nevertheless
fAllowDuplicates = ((stream->Mode() & S_INDEX_DIR) == S_INDEX_DIR fAllowDuplicates = ((stream->Mode() & S_INDEX_DIR) == S_INDEX_DIR
&& stream->BlockRun() != stream->Parent()) && stream->BlockRun() != stream->Parent())
|| (stream->Mode() & S_ALLOW_DUPS) != 0; || (stream->Mode() & S_ALLOW_DUPS) != 0;
#endif #endif
} }
@@ -546,33 +552,32 @@ TreeIterator::Traverse(int8 direction, void *key, uint16 *keyLength, uint16 maxL
bplustree_node *node; bplustree_node *node;
#ifdef BPLUSTREE_SUPPORTS_DUPLICATES #ifdef BPLUSTREE_SUPPORTS_DUPLICATES
if (fDuplicateNode != BPLUSTREE_NULL) if (fDuplicateNode != BPLUSTREE_NULL) {
{ // regardless of traverse direction the duplicates are always presented
// regardless of traverse direction the duplicates are always presented in // in the same order; since they are all considered as equal, this
// the same order; since they are all considered as equal, this shouldn't // shouldn't cause any problems
// cause any problems
if (!fIsFragment || fDuplicate < fNumDuplicates) if (!fIsFragment || fDuplicate < fNumDuplicates) {
node = cached.SetTo(bplustree_node::FragmentOffset(fDuplicateNode), false); node = cached.SetTo(bplustree_node::FragmentOffset(fDuplicateNode),
else false);
} else
node = NULL; node = NULL;
if (node != NULL) if (node != NULL) {
{ if (!fIsFragment && fDuplicate >= fNumDuplicates) {
if (!fIsFragment && fDuplicate >= fNumDuplicates) // if the node is out of duplicates, we go directly to the next
{ // one
// if the node is out of duplicates, we go directly to the next one
fDuplicateNode = node->right_link; fDuplicateNode = node->right_link;
if (fDuplicateNode != BPLUSTREE_NULL if (fDuplicateNode != BPLUSTREE_NULL
&& (node = cached.SetTo(fDuplicateNode, false)) != NULL) && (node = cached.SetTo(fDuplicateNode, false)) != NULL) {
{ fNumDuplicates
fNumDuplicates = node->CountDuplicates(fDuplicateNode, false); = node->CountDuplicates(fDuplicateNode, false);
fDuplicate = 0; fDuplicate = 0;
} }
} }
if (fDuplicate < fNumDuplicates) if (fDuplicate < fNumDuplicates) {
{ *value = node->DuplicateAt(fDuplicateNode, fIsFragment,
*value = node->DuplicateAt(fDuplicateNode, fIsFragment, fDuplicate++); fDuplicate++);
if (duplicate) if (duplicate)
*duplicate = 2; *duplicate = 2;
return B_OK; return B_OK;
@@ -1,7 +1,7 @@
/* /*
** Copyright 2003-2004, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2003-2010, Axel Dörfler, [email protected].
** Distributed under the terms of the OpenBeOS License. * Distributed under the terms of the MIT License.
*/ */
#include "Directory.h" #include "Directory.h"
@@ -22,6 +22,7 @@ extern Node *get_node_from(int fd);
namespace BFS { namespace BFS {
Directory::Directory(Volume &volume, block_run run) Directory::Directory(Volume &volume, block_run run)
: :
fStream(volume, run), fStream(volume, run),
@@ -170,11 +171,12 @@ Directory::IsEmpty()
char name[BPLUSTREE_MAX_KEY_LENGTH]; char name[BPLUSTREE_MAX_KEY_LENGTH];
uint16 length; uint16 length;
off_t id; off_t id;
while (iterator.GetNextEntry(name, &length, B_FILE_NAME_LENGTH, &id) == B_OK) { while (iterator.GetNextEntry(name, &length, B_FILE_NAME_LENGTH, &id)
== B_OK) {
if (fStream.Mode() & (S_ATTR_DIR | S_INDEX_DIR)) if (fStream.Mode() & (S_ATTR_DIR | S_INDEX_DIR))
return false; return false;
if (++count > 2 || strcmp(".", name) && strcmp("..", name)) if (++count > 2 || (strcmp(".", name) && strcmp("..", name)))
return false; return false;
} }
return true; return true;
@@ -199,4 +201,5 @@ Directory::Inode() const
return fStream.ID(); return fStream.ID();
} }
} // namespace BFS } // namespace BFS