@@ -111,19 +111,19 @@ template <typename Value, typename Key = Value, typename Allocator = MallocAlloc
111111 typename Cmp = DefaultComparator<Key> >
112112class BePlusTree
113113{
114- static const FB_SIZE_T LeafCount = LEAF_PAGE_SIZE / sizeof (Value);
115- static const FB_SIZE_T NodeCount = NODE_PAGE_SIZE / sizeof (void *);
114+ static const FB_SIZE_T LEAF_COUNT = LEAF_PAGE_SIZE / sizeof (Value);
115+ static const FB_SIZE_T NODE_COUNT = NODE_PAGE_SIZE / sizeof (void *);
116116public:
117117 explicit BePlusTree (Allocator *_pool)
118- : pool(_pool), level(0 ), root(NULL ), defaultAccessor(this )
118+ : pool(_pool), level(0 ), root(nullptr ), defaultAccessor(this )
119119 { }
120120
121121 explicit BePlusTree (Allocator& _pool)
122- : pool(&_pool), level(0 ), root(NULL ), defaultAccessor(this )
122+ : pool(&_pool), level(0 ), root(nullptr ), defaultAccessor(this )
123123 { }
124124
125125 BePlusTree (Allocator *_pool, const BePlusTree& from)
126- : pool(_pool), level(0 ), root(NULL ), defaultAccessor(this )
126+ : pool(_pool), level(0 ), root(nullptr ), defaultAccessor(this )
127127 {
128128 append (from);
129129 }
@@ -137,7 +137,7 @@ class BePlusTree
137137
138138 void clear ()
139139 {
140- defaultAccessor.curr = NULL ;
140+ defaultAccessor.curr = nullptr ;
141141
142142 // Do not deallocate root page if tree is shallow
143143 if (level == 0 )
@@ -179,7 +179,7 @@ class BePlusTree
179179 }
180180
181181 // Initialize fields to make tree usable again
182- root = NULL ;
182+ root = nullptr ;
183183 level = 0 ;
184184 }
185185
@@ -256,9 +256,9 @@ class BePlusTree
256256 // factor range for the tree on each level for current NEED_MERGE routine
257257 // is [0.375, 1]. We take 3/5 = 0.6 as most probable case and
258258 // play from there.
259- size_t items_per_node = LeafCount * 3 / 5 ;
259+ size_t items_per_node = LEAF_COUNT * 3 / 5 ;
260260 for (int i = 1 ; i < level; i++)
261- items_per_node *= NodeCount * 3 / 5 ;
261+ items_per_node *= NODE_COUNT * 3 / 5 ;
262262
263263 fb_assert (items_per_node);
264264 return root.nodes ->getCount () * items_per_node;
@@ -278,7 +278,7 @@ class BePlusTree
278278 // is the same as in approxCount() routine above
279279 size_t bytes_per_node = sizeof (ItemList);
280280 for (int i = 1 ; i < level; i++)
281- bytes_per_node *= NodeCount * 3 / 5 ;
281+ bytes_per_node *= NODE_COUNT * 3 / 5 ;
282282
283283 fb_assert (bytes_per_node);
284284 return root.nodes ->getCount () * bytes_per_node;
@@ -303,7 +303,7 @@ class BePlusTree
303303
304304 class NodeList ;
305305
306- class ItemList : public SortedVector <Value, LeafCount , Key, KeyOfValue, Cmp>
306+ class ItemList : public SortedVector <Value, LEAF_COUNT , Key, KeyOfValue, Cmp>
307307 {
308308 public:
309309 NodeList* parent;
@@ -312,15 +312,15 @@ class BePlusTree
312312
313313 // Adds newly created item to doubly-linked list
314314 ItemList (ItemList* items)
315- : parent(NULL )
315+ : parent(nullptr )
316316 {
317317 if ((next = items->next ))
318318 next->prev = this ;
319319 prev = items;
320320 items->next = this ;
321321 }
322322 // Create first item in the linked list
323- ItemList () : parent(NULL ), next(NULL ), prev(NULL ) {}
323+ ItemList () : parent(nullptr ), next(nullptr ), prev(nullptr ) {}
324324
325325 friend class BePlusTree ;
326326#ifndef _MSC_VER
@@ -342,20 +342,20 @@ class BePlusTree
342342 void * pointer;
343343 };
344344
345- class NodeList : public SortedVector <NodePtr, NodeCount , Key, NodeList, Cmp>
345+ class NodeList : public SortedVector <NodePtr, NODE_COUNT , Key, NodeList, Cmp>
346346 {
347347 public:
348348 // Adds newly created item to the doubly-linked list
349349 NodeList (NodeList* items)
350- : parent(NULL )
350+ : parent(nullptr )
351351 {
352352 if ((next = items->next ))
353353 next->prev = this ;
354354 prev = items;
355355 items->next = this ;
356356 }
357357 // Create first item in the linked list
358- NodeList () : parent(NULL ), next(NULL ), prev(NULL ) {}
358+ NodeList () : parent(nullptr ), next(nullptr ), prev(nullptr ) {}
359359
360360 int level;
361361 NodeList *parent;
@@ -394,7 +394,7 @@ class BePlusTree
394394 {
395395 public:
396396 explicit ConstAccessor (const BePlusTree* in_tree) :
397- curr(NULL ), curPos(0 ), tree(in_tree)
397+ curr(nullptr ), curPos(0 ), tree(in_tree)
398398 {}
399399
400400 bool locate (const Key& key)
@@ -580,7 +580,7 @@ class BePlusTree
580580 // invalidate current position of defaultAccessor
581581 // if i'm not a defaultAccessor
582582 if (this != &tree->defaultAccessor )
583- tree->defaultAccessor .curr = NULL ;
583+ tree->defaultAccessor .curr = nullptr ;
584584
585585 if (!tree->level )
586586 {
@@ -593,14 +593,14 @@ class BePlusTree
593593 // because is would invalidate our tree structure
594594 fb_assert (this ->curPos == 0 );
595595 ItemList* temp;
596- if ((temp = this ->curr ->prev ) && NEED_MERGE (temp->getCount (), LeafCount ))
596+ if ((temp = this ->curr ->prev ) && NEED_MERGE (temp->getCount (), LEAF_COUNT ))
597597 {
598598 temp = this ->curr ->next ;
599599 tree->_removePage (0 , this ->curr );
600600 this ->curr = temp;
601601 return this ->curr ;
602602 }
603- if ((temp = this ->curr ->next ) && NEED_MERGE (temp->getCount (), LeafCount ))
603+ if ((temp = this ->curr ->next ) && NEED_MERGE (temp->getCount (), LEAF_COUNT ))
604604 {
605605 tree->_removePage (0 , this ->curr );
606606 this ->curr = temp;
@@ -626,7 +626,7 @@ class BePlusTree
626626 this ->curr ->remove (this ->curPos );
627627 ItemList *temp;
628628 if ((temp = this ->curr ->prev ) &&
629- NEED_MERGE (temp->getCount () + this ->curr ->getCount (), LeafCount ))
629+ NEED_MERGE (temp->getCount () + this ->curr ->getCount (), LEAF_COUNT ))
630630 {
631631 // After join upper levels of the tree remain stable because join doesn't change
632632 // key of the page. The same applies to lower case too.
@@ -639,7 +639,7 @@ class BePlusTree
639639 else
640640 {
641641 if ((temp = this ->curr ->next ) &&
642- NEED_MERGE (temp->getCount () + this ->curr ->getCount (), LeafCount ))
642+ NEED_MERGE (temp->getCount () + this ->curr ->getCount (), LEAF_COUNT ))
643643 {
644644 this ->curr ->join (*temp);
645645 tree->_removePage (0 , temp);
@@ -688,7 +688,7 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
688688
689689 // Find leaf page for our item
690690 NodePtr vList = this ->root ;
691- const Key& key = KeyOfValue::generate (NULL , item);
691+ const Key& key = KeyOfValue::generate (nullptr , item);
692692 for (int lev = this ->level ; lev > 0 ; lev--)
693693 {
694694 FB_SIZE_T pos;
@@ -713,7 +713,7 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
713713 return false ;
714714 }
715715
716- if (leaf->getCount () < LeafCount )
716+ if (leaf->getCount () < LEAF_COUNT )
717717 {
718718 leaf->insert (pos, item);
719719 return true ;
@@ -723,10 +723,10 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
723723 ItemList *temp;
724724 // Adding items to the next page is cheaper in most cases that
725725 // is why it is checked first
726- if ((temp = leaf->next ) && temp->getCount () < LeafCount )
726+ if ((temp = leaf->next ) && temp->getCount () < LEAF_COUNT )
727727 {
728728 // Found space on the next page
729- if (pos == LeafCount )
729+ if (pos == LEAF_COUNT )
730730 {
731731 // This would be ok if items were unique: temp->insert(0, item);
732732 // The same applies to all simular cases below
@@ -738,14 +738,14 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
738738 // It should do it in case of random size items.
739739 // It would make things slower in case of sequental items addition.
740740 // Let's leave it as is now.
741- temp->insert (0 , (*leaf)[LeafCount - 1 ]);
742- leaf->shrink (LeafCount - 1 );
741+ temp->insert (0 , (*leaf)[LEAF_COUNT - 1 ]);
742+ leaf->shrink (LEAF_COUNT - 1 );
743743 leaf->insert (pos, item);
744744 }
745745 return true ;
746746 }
747747
748- if ((temp = leaf->prev ) && temp->getCount () < LeafCount )
748+ if ((temp = leaf->prev ) && temp->getCount () < LEAF_COUNT )
749749 {
750750 // Found space on the previous page
751751 if (pos == 0 ) {
@@ -775,14 +775,14 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
775775 FB_SIZE_T recovery_map[MAX_TREE_LEVEL];
776776 const FB_SIZE_T MAP_NEW_PAGE = ~((FB_SIZE_T) 0 );
777777
778- if (pos == LeafCount )
778+ if (pos == LEAF_COUNT )
779779 {
780780 newLeaf->insert (0 , item);
781781 recovery_map[0 ] = MAP_NEW_PAGE;
782782 }
783783 else
784784 {
785- newLeaf->insert (0 , (*leaf)[LeafCount - 1 ]);
785+ newLeaf->insert (0 , (*leaf)[LEAF_COUNT - 1 ]);
786786 leaf->shrink (leaf->getCount () - 1 );
787787 leaf->insert (pos, item);
788788 recovery_map[0 ] = pos;
@@ -795,7 +795,7 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
795795 while (nodeList)
796796 {
797797 // Easy case. We've got some space on the node page
798- if (nodeList->getCount () < NodeCount )
798+ if (nodeList->getCount () < NODE_COUNT )
799799 {
800800 NodeList::setNodeParentAndLevel (newNode, curLevel, nodeList);
801801 nodeList->add (newNode);
@@ -806,27 +806,27 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
806806 nodeList->find (NodeList::generate (nodeList, newNode), pos);
807807 NodeList *list;
808808
809- if ((list = nodeList->next ) && list->getCount () < NodeCount )
809+ if ((list = nodeList->next ) && list->getCount () < NODE_COUNT )
810810 {
811811 // Found space on the next page
812- if (pos == NodeCount )
812+ if (pos == NODE_COUNT )
813813 {
814814 NodeList::setNodeParentAndLevel (newNode, curLevel, list);
815815 list->insert (0 , newNode);
816816 }
817817 else
818818 {
819- NodePtr t = (*nodeList)[NodeCount - 1 ];
819+ NodePtr t = (*nodeList)[NODE_COUNT - 1 ];
820820 NodeList::setNodeParent (t, curLevel, list);
821821 list->insert (0 , t);
822- nodeList->shrink (NodeCount - 1 );
822+ nodeList->shrink (NODE_COUNT - 1 );
823823 NodeList::setNodeParentAndLevel (newNode, curLevel, nodeList);
824824 nodeList->insert (pos, newNode);
825825 }
826826 return true ;
827827 }
828828
829- if ((list = nodeList->prev ) && list->getCount () < NodeCount )
829+ if ((list = nodeList->prev ) && list->getCount () < NODE_COUNT )
830830 {
831831 // Found space on the previous page
832832 if (pos == 0 )
@@ -853,18 +853,18 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
853853 // are cleaned up lower
854854 NodeList *newList = new (this ->pool ->allocate (sizeof (NodeList) ALLOC_ARGS)) NodeList (nodeList);
855855
856- if (pos == NodeCount )
856+ if (pos == NODE_COUNT )
857857 {
858858 NodeList::setNodeParentAndLevel (newNode, curLevel, newList);
859859 newList->insert (0 , newNode);
860860 recovery_map[curLevel + 1 ] = MAP_NEW_PAGE;
861861 }
862862 else
863863 {
864- NodePtr t = (*nodeList)[NodeCount - 1 ];
864+ NodePtr t = (*nodeList)[NODE_COUNT - 1 ];
865865 NodeList::setNodeParent (t, curLevel, newList);
866866 newList->insert (0 , t);
867- nodeList->shrink (NodeCount - 1 );
867+ nodeList->shrink (NODE_COUNT - 1 );
868868 NodeList::setNodeParentAndLevel (newNode, curLevel, nodeList);
869869 nodeList->insert (pos, newNode);
870870 recovery_map[curLevel + 1 ] = pos;
@@ -949,11 +949,11 @@ void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::_removePage(const int n
949949 // Only one node left in the list. We cannot remove it directly
950950 // because is would invalidate our tree structure
951951 NodeList *temp;
952- if ((temp = list->prev ) && NEED_MERGE (temp->getCount (), NodeCount )) {
952+ if ((temp = list->prev ) && NEED_MERGE (temp->getCount (), NODE_COUNT )) {
953953 _removePage (nodeLevel + 1 , list);
954954 }
955955 else
956- if ((temp = list->next ) && NEED_MERGE (temp->getCount (), NodeCount )) {
956+ if ((temp = list->next ) && NEED_MERGE (temp->getCount (), NODE_COUNT )) {
957957 _removePage (nodeLevel + 1 , list);
958958 }
959959 else
@@ -992,14 +992,14 @@ void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::_removePage(const int n
992992 // Reduce the level of the tree
993993 root = (*list)[0 ];
994994 level--;
995- NodeList::setNodeParent (root, level, NULL );
995+ NodeList::setNodeParent (root, level, nullptr );
996996 list->~NodeList ();
997997 pool->deallocate (list);
998998 }
999999 else
10001000 {
10011001 NodeList *temp;
1002- if ((temp = list->prev ) && NEED_MERGE (temp->getCount () + list->getCount (), NodeCount ))
1002+ if ((temp = list->prev ) && NEED_MERGE (temp->getCount () + list->getCount (), NODE_COUNT ))
10031003 {
10041004 // After join upper levels of the tree remain stable because join doesn't change
10051005 // key of the page. The same applies to lower case too.
@@ -1009,7 +1009,7 @@ void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::_removePage(const int n
10091009 _removePage (nodeLevel + 1 , list);
10101010 }
10111011 else
1012- if ((temp = list->next ) && NEED_MERGE (temp->getCount () + list->getCount (), NodeCount ))
1012+ if ((temp = list->next ) && NEED_MERGE (temp->getCount () + list->getCount (), NODE_COUNT ))
10131013 {
10141014 list->join (*temp);
10151015 for (FB_SIZE_T i = 0 ; i < temp->getCount (); i++)
0 commit comments