mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-24 04:03:03 +01:00
Formatting and VC6 hack.
This commit is contained in:
parent
63644eb3cb
commit
e058195959
@ -140,7 +140,7 @@ public:
|
|||||||
|
|
||||||
// Delete all items pages
|
// Delete all items pages
|
||||||
NodeList *lists = items->parent;
|
NodeList *lists = items->parent;
|
||||||
while ( items ) {
|
while (items) {
|
||||||
ItemList *t = items->next;
|
ItemList *t = items->next;
|
||||||
items->~ItemList();
|
items->~ItemList();
|
||||||
pool->deallocate(items);
|
pool->deallocate(items);
|
||||||
@ -151,7 +151,7 @@ public:
|
|||||||
while (lists) {
|
while (lists) {
|
||||||
NodeList *list = lists;
|
NodeList *list = lists;
|
||||||
lists = lists->parent;
|
lists = lists->parent;
|
||||||
while ( list ) {
|
while (list) {
|
||||||
NodeList *t = list->next;
|
NodeList *t = list->next;
|
||||||
list->~NodeList();
|
list->~NodeList();
|
||||||
pool->deallocate(list);
|
pool->deallocate(list);
|
||||||
@ -222,7 +222,8 @@ public:
|
|||||||
|
|
||||||
// Compute approximate number of leafs in the tree
|
// Compute approximate number of leafs in the tree
|
||||||
size_t approxCount() const {
|
size_t approxCount() const {
|
||||||
if (!root) return 0;
|
if (!root)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (level == 0) return ((ItemList*)root)->getCount();
|
if (level == 0) return ((ItemList*)root)->getCount();
|
||||||
|
|
||||||
@ -241,7 +242,8 @@ public:
|
|||||||
|
|
||||||
// Compute approximate memory consumption for tree in bytes
|
// Compute approximate memory consumption for tree in bytes
|
||||||
size_t approxSize() const {
|
size_t approxSize() const {
|
||||||
if (!root) return 0;
|
if (!root)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
return sizeof(ItemList);
|
return sizeof(ItemList);
|
||||||
@ -285,7 +287,7 @@ public:
|
|||||||
ItemList *next, *prev;
|
ItemList *next, *prev;
|
||||||
// Adds newly created item to doubly-linked list
|
// Adds newly created item to doubly-linked list
|
||||||
ItemList(ItemList *items) : parent(NULL) {
|
ItemList(ItemList *items) : parent(NULL) {
|
||||||
if ( (next = items->next) )
|
if ((next = items->next))
|
||||||
next->prev = this;
|
next->prev = this;
|
||||||
prev = items;
|
prev = items;
|
||||||
items->next = this;
|
items->next = this;
|
||||||
@ -304,7 +306,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
// Adds newly created item to the doubly-linked list
|
// Adds newly created item to the doubly-linked list
|
||||||
NodeList(NodeList *items) : parent(NULL) {
|
NodeList(NodeList *items) : parent(NULL) {
|
||||||
if ( (next = items->next) )
|
if ((next = items->next))
|
||||||
next->prev = this;
|
next->prev = this;
|
||||||
prev = items;
|
prev = items;
|
||||||
items->next = this;
|
items->next = this;
|
||||||
@ -357,33 +359,33 @@ public:
|
|||||||
if (this != &tree->defaultAccessor)
|
if (this != &tree->defaultAccessor)
|
||||||
tree->defaultAccessor.curr = NULL;
|
tree->defaultAccessor.curr = NULL;
|
||||||
|
|
||||||
if ( !tree->level ) {
|
if (!tree->level) {
|
||||||
curr->remove(curPos);
|
curr->remove(curPos);
|
||||||
return curPos < curr->getCount();
|
return curPos < curr->getCount();
|
||||||
}
|
}
|
||||||
if ( curr->getCount() == 1 ) {
|
if (curr->getCount() == 1) {
|
||||||
// Only one node left in the current page. We cannot remove it directly
|
// Only one node left in the current page. We cannot remove it directly
|
||||||
// because is would invalidate our tree structure
|
// because is would invalidate our tree structure
|
||||||
fb_assert(curPos == 0);
|
fb_assert(curPos == 0);
|
||||||
ItemList *temp;
|
ItemList *temp;
|
||||||
if ( (temp = curr->prev) && NEED_MERGE(temp->getCount(), LeafCount) ) {
|
if ((temp = curr->prev) && NEED_MERGE(temp->getCount(), LeafCount)) {
|
||||||
temp = curr->next;
|
temp = curr->next;
|
||||||
tree->_removePage(0, curr);
|
tree->_removePage(0, curr);
|
||||||
curr = temp;
|
curr = temp;
|
||||||
return curr;
|
return curr;
|
||||||
}
|
}
|
||||||
if ( (temp = curr->next) && NEED_MERGE(temp->getCount(), LeafCount) ) {
|
if ((temp = curr->next) && NEED_MERGE(temp->getCount(), LeafCount)) {
|
||||||
tree->_removePage(0, curr);
|
tree->_removePage(0, curr);
|
||||||
curr = temp;
|
curr = temp;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ( (temp = curr->prev) ) {
|
if ((temp = curr->prev)) {
|
||||||
(*curr)[0] = (*temp)[temp->getCount() - 1];
|
(*curr)[0] = (*temp)[temp->getCount() - 1];
|
||||||
temp->shrink(temp->getCount() - 1);
|
temp->shrink(temp->getCount() - 1);
|
||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
return curr;
|
return curr;
|
||||||
}
|
}
|
||||||
if ( (temp = curr->next) ) {
|
if ((temp = curr->next)) {
|
||||||
(*curr)[0] = (*temp)[0];
|
(*curr)[0] = (*temp)[0];
|
||||||
temp->remove(0);
|
temp->remove(0);
|
||||||
return true;
|
return true;
|
||||||
@ -394,7 +396,7 @@ public:
|
|||||||
}
|
}
|
||||||
curr->remove(curPos);
|
curr->remove(curPos);
|
||||||
ItemList *temp;
|
ItemList *temp;
|
||||||
if ( (temp = curr->prev) && NEED_MERGE(temp->getCount() + curr->getCount(), LeafCount) ) {
|
if ((temp = curr->prev) && NEED_MERGE(temp->getCount() + curr->getCount(), LeafCount)) {
|
||||||
// After join upper levels of the tree remain stable because join doesn't change
|
// After join upper levels of the tree remain stable because join doesn't change
|
||||||
// key of the page. The same applies to lower case too.
|
// key of the page. The same applies to lower case too.
|
||||||
curPos += temp->getCount();
|
curPos += temp->getCount();
|
||||||
@ -404,7 +406,7 @@ public:
|
|||||||
// The code below will adjust current position if needed
|
// The code below will adjust current position if needed
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( (temp = curr->next) && NEED_MERGE(temp->getCount() + curr->getCount(), LeafCount) ) {
|
if ((temp = curr->next) && NEED_MERGE(temp->getCount() + curr->getCount(), LeafCount)) {
|
||||||
curr->join(*temp);
|
curr->join(*temp);
|
||||||
tree->_removePage(0, temp);
|
tree->_removePage(0, temp);
|
||||||
return true;
|
return true;
|
||||||
@ -433,7 +435,10 @@ public:
|
|||||||
for (int lev = tree->level; lev; lev--) {
|
for (int lev = tree->level; lev; lev--) {
|
||||||
size_t pos;
|
size_t pos;
|
||||||
if (!((NodeList *)list)->find(key, pos))
|
if (!((NodeList *)list)->find(key, pos))
|
||||||
if ( pos > 0 ) pos--;
|
{
|
||||||
|
if (pos > 0)
|
||||||
|
pos--;
|
||||||
|
}
|
||||||
list = (*(NodeList *)list)[pos];
|
list = (*(NodeList *)list)[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,19 +453,22 @@ public:
|
|||||||
}
|
}
|
||||||
return found || curr;
|
return found || curr;
|
||||||
case locLessEqual:
|
case locLessEqual:
|
||||||
if (found) return true;
|
if (found)
|
||||||
|
return true;
|
||||||
// NOTE: fall into next case statement
|
// NOTE: fall into next case statement
|
||||||
case locLess:
|
case locLess:
|
||||||
if (curPos == 0) {
|
if (curPos == 0) {
|
||||||
curr = curr->prev;
|
curr = curr->prev;
|
||||||
if (!curr) return false;
|
if (!curr)
|
||||||
|
return false;
|
||||||
curPos = curr->getCount() - 1;
|
curPos = curr->getCount() - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
curPos--;
|
curPos--;
|
||||||
return true;
|
return true;
|
||||||
case locGreat:
|
case locGreat:
|
||||||
if (found) curPos++;
|
if (found)
|
||||||
|
curPos++;
|
||||||
if (curPos == curr->getCount()) {
|
if (curPos == curr->getCount()) {
|
||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
curPos = 0;
|
curPos = 0;
|
||||||
@ -473,7 +481,8 @@ public:
|
|||||||
// position of accessor is not defined.
|
// position of accessor is not defined.
|
||||||
bool getFirst() {
|
bool getFirst() {
|
||||||
void *items = tree->root;
|
void *items = tree->root;
|
||||||
if (!items) return false; // Uninitalized tree
|
if (!items)
|
||||||
|
return false; // Uninitalized tree
|
||||||
for (int i = tree->level; i > 0; i--)
|
for (int i = tree->level; i > 0; i--)
|
||||||
items = (*(NodeList *)items)[0];
|
items = (*(NodeList *)items)[0];
|
||||||
curr = (ItemList *)items;
|
curr = (ItemList *)items;
|
||||||
@ -484,7 +493,8 @@ public:
|
|||||||
// position of accessor is not defined.
|
// position of accessor is not defined.
|
||||||
bool getLast() {
|
bool getLast() {
|
||||||
void *items = tree->root;
|
void *items = tree->root;
|
||||||
if (!items) return false; // Uninitalized tree
|
if (!items)
|
||||||
|
return false; // Uninitalized tree
|
||||||
for (int i = tree->level; i > 0; i--)
|
for (int i = tree->level; i > 0; i--)
|
||||||
items = (*(NodeList *)items)[((NodeList *)items)->getCount() - 1];
|
items = (*(NodeList *)items)[((NodeList *)items)->getCount() - 1];
|
||||||
curr = (ItemList *)items;
|
curr = (ItemList *)items;
|
||||||
@ -551,10 +561,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ItemList *curr;
|
ItemList *curr;
|
||||||
|
size_t curPos;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BePlusTree* tree;
|
BePlusTree* tree;
|
||||||
size_t curPos;
|
|
||||||
|
|
||||||
friend class BePlusTree;
|
friend class BePlusTree;
|
||||||
}; // class Accessor
|
}; // class Accessor
|
||||||
@ -578,7 +588,8 @@ template <typename Value, typename Key, typename Allocator, typename KeyOfValue,
|
|||||||
bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::add(const Value& item, Accessor* accessor)
|
bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::add(const Value& item, Accessor* accessor)
|
||||||
{
|
{
|
||||||
// Finish initialization of the tree if necessary
|
// Finish initialization of the tree if necessary
|
||||||
if (!root) root = new (pool->allocate(sizeof(ItemList))) ItemList();
|
if (!root)
|
||||||
|
root = new (pool->allocate(sizeof(ItemList))) ItemList();
|
||||||
|
|
||||||
// Find leaf page for our item
|
// Find leaf page for our item
|
||||||
void *vList = this->root;
|
void *vList = this->root;
|
||||||
@ -586,7 +597,10 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::a
|
|||||||
for (int lev = this->level; lev > 0 ; lev--) {
|
for (int lev = this->level; lev > 0 ; lev--) {
|
||||||
size_t pos;
|
size_t pos;
|
||||||
if (!((NodeList *)vList)->find(key, pos))
|
if (!((NodeList *)vList)->find(key, pos))
|
||||||
if ( pos > 0 ) pos--;
|
{
|
||||||
|
if (pos > 0)
|
||||||
|
pos--;
|
||||||
|
}
|
||||||
vList = (*(NodeList *)vList)[pos];
|
vList = (*(NodeList *)vList)[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,25 +821,25 @@ void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::_
|
|||||||
list = temp->parent;
|
list = temp->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( list->getCount() == 1 ) {
|
if (list->getCount() == 1) {
|
||||||
// Only one node left in the list. We cannot remove it directly
|
// Only one node left in the list. We cannot remove it directly
|
||||||
// because is would invalidate our tree structure
|
// because is would invalidate our tree structure
|
||||||
NodeList *temp;
|
NodeList *temp;
|
||||||
if ( (temp = list->prev) && NEED_MERGE(temp->getCount(), NodeCount) ) {
|
if ((temp = list->prev) && NEED_MERGE(temp->getCount(), NodeCount)) {
|
||||||
_removePage(nodeLevel + 1, list);
|
_removePage(nodeLevel + 1, list);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if ( (temp = list->next) && NEED_MERGE(temp->getCount(), NodeCount) ) {
|
if ((temp = list->next) && NEED_MERGE(temp->getCount(), NodeCount)) {
|
||||||
_removePage(nodeLevel + 1, list);
|
_removePage(nodeLevel + 1, list);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if ( (temp = list->prev) ) {
|
if ((temp = list->prev)) {
|
||||||
NodeList::setNodeParent(
|
NodeList::setNodeParent(
|
||||||
((*list)[0] = (*temp)[temp->getCount() - 1]), nodeLevel, list);
|
((*list)[0] = (*temp)[temp->getCount() - 1]), nodeLevel, list);
|
||||||
temp->shrink(temp->getCount() - 1);
|
temp->shrink(temp->getCount() - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if ( (temp = list->next) ) {
|
if ((temp = list->next)) {
|
||||||
NodeList::setNodeParent(
|
NodeList::setNodeParent(
|
||||||
((*list)[0] = (*temp)[0]), nodeLevel, list);
|
((*list)[0] = (*temp)[0]), nodeLevel, list);
|
||||||
temp->remove(0);
|
temp->remove(0);
|
||||||
@ -859,8 +873,8 @@ void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::_
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
NodeList *temp;
|
NodeList *temp;
|
||||||
if ( (temp = list->prev) &&
|
if ((temp = list->prev) &&
|
||||||
NEED_MERGE(temp->getCount() + list->getCount(), NodeCount) )
|
NEED_MERGE(temp->getCount() + list->getCount(), NodeCount))
|
||||||
{
|
{
|
||||||
// After join upper levels of the tree remain stable because join doesn't change
|
// After join upper levels of the tree remain stable because join doesn't change
|
||||||
// key of the page. The same applies to lower case too.
|
// key of the page. The same applies to lower case too.
|
||||||
@ -870,8 +884,8 @@ void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::_
|
|||||||
_removePage(nodeLevel + 1, list);
|
_removePage(nodeLevel + 1, list);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if ( (temp = list->next) &&
|
if ((temp = list->next) &&
|
||||||
NEED_MERGE(temp->getCount() + list->getCount(), NodeCount) )
|
NEED_MERGE(temp->getCount() + list->getCount(), NodeCount))
|
||||||
{
|
{
|
||||||
list->join(*temp);
|
list->join(*temp);
|
||||||
for (size_t i = 0; i < temp->getCount(); i++)
|
for (size_t i = 0; i < temp->getCount(); i++)
|
||||||
|
Loading…
Reference in New Issue
Block a user