Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbBdbSBtreeP.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbBdbSBtreeP.cc,v 1.5 2004/06/20 23:23:09 gapon Exp $
00003 
00004 /// Implementation file for the CdbBdbSBtreeP class
00005 /**
00006   * @see CdbBdbSBtreeP
00007   */
00008 
00009 #include "BaBar/BaBar.hh"
00010 
00011 #if !defined(OO_DDL_TRANSLATION)
00012 #include "CdbBdbShared/CdbBdbSBtreeP.hh"
00013 #endif // OO_DDL_TRANSLATION
00014 
00015 template< class K,
00016           class FCP,
00017           class ORDER >
00018 CdbBdbSBtreeP<K,FCP,ORDER>::CdbBdbSBtreeP( )
00019 {
00020     _bufRef = new( ooThis( )) PagedVarrayOfNodeP( 2 );
00021 
00022   // Initialize the root node.
00023 
00024     _root = 1;
00025 
00026     init_node( _root, 0 );
00027 
00028   // Initialize a list of free elements as the empty one.
00029   // The elements will be added as required.
00030 
00031     _free = 0;
00032 }
00033 
00034 template< class K,
00035           class FCP,
00036           class ORDER >
00037 CdbBdbSBtreeP<K,FCP,ORDER>::~CdbBdbSBtreeP( ) 
00038 {
00039     BdbDelete( _bufRef );
00040 }
00041 
00042 template< class K,
00043           class FCP,
00044           class ORDER >
00045 d_ULong
00046 CdbBdbSBtreeP<K,FCP,ORDER>::allocate( d_ULong parent )
00047 {
00048     ooUpdate( );
00049     if( _free == 0 ) extend_free_list( );
00050 
00051     d_ULong result = _free;
00052     {
00053         _free = readNode( result ).child[0];
00054 
00055         init_node( result, parent );
00056     }
00057     return result;
00058 }
00059 
00060 template< class K,
00061           class FCP,
00062           class ORDER >
00063 void
00064 CdbBdbSBtreeP<K,FCP,ORDER>::release( d_ULong node )
00065 {
00066     ooUpdate( );
00067     if( node ) {
00068 
00069         CdbBdbSBtreeNode<K,ORDER> nodeValue = readNode( node );
00070         { nodeValue.child[0] = _free; }
00071         updateNode( node, nodeValue );
00072 
00073         _free = node;
00074     }
00075 }
00076 
00077 template< class K,
00078           class FCP,
00079           class ORDER >
00080 d_ULong
00081 CdbBdbSBtreeP<K,FCP,ORDER>::root( ) const
00082 {
00083     return _root;
00084 }
00085 
00086 template< class K,
00087           class FCP,
00088           class ORDER >
00089 void
00090 CdbBdbSBtreeP<K,FCP,ORDER>::set_root( d_ULong node )
00091 {
00092     ooUpdate( );
00093     _root = node;
00094 }
00095 
00096 template< class K,
00097           class FCP,
00098           class ORDER >
00099 CdbBdbSBtreeNode<K,ORDER>
00100 CdbBdbSBtreeP<K,FCP,ORDER>::readNode( d_ULong node ) const
00101 {
00102     return _bufRef->elementAt( node );
00103 }
00104 
00105 template< class K,
00106           class FCP,
00107           class ORDER >
00108 void
00109 CdbBdbSBtreeP<K,FCP,ORDER>::updateNode( d_ULong                          node,
00110                                         const CdbBdbSBtreeNode<K,ORDER>& value )
00111 {
00112     _bufRef->setElementAt( node,
00113                            value );
00114 }
00115 
00116 template< class K,
00117           class FCP,
00118           class ORDER >
00119 void
00120 CdbBdbSBtreeP<K,FCP,ORDER>::init_node( d_ULong node,
00121                                        d_ULong parent )
00122 {
00123     CdbBdbSBtreeNode<K,ORDER> nodeValue = readNode( node );
00124     {
00125         nodeValue.isLeaf = d_True;
00126         nodeValue.n      = 0;
00127         nodeValue.parent = parent;
00128     }
00129     updateNode( node, nodeValue );
00130 }
00131 
00132 template< class K,
00133           class FCP,
00134           class ORDER >
00135 void
00136 CdbBdbSBtreeP<K,FCP,ORDER>::extend_free_list( )
00137 {
00138     if( _free == 0 ) {
00139 
00140         _free = _bufRef->size( );
00141 
00142       // Double the number of elements before the number of elements reaches 1000. Then plainly
00143       // add a fixed number of elements.
00144       //
00145       // NOTES: (1) This policy may change in the future
00146       //        (2) The policy allows to avoid inefficient use of the persistent space for small B-trees.
00147 
00148         d_ULong sizeIncrement = 1000;
00149         if(( 0 < _free ) && ( _free < sizeIncrement )) sizeIncrement = _free;
00150 
00151         _bufRef->resize( _free + sizeIncrement );
00152 
00153         for( d_ULong node = _free + 1; node < _free + sizeIncrement; ++node ) {
00154 
00155           // End Of the List
00156 
00157             CdbBdbSBtreeNode<K,ORDER> nodeValue = readNode( node );
00158             { nodeValue.child[0] = 0; }
00159             updateNode( node, nodeValue );
00160 
00161           // Previous node points to the current one
00162 
00163             CdbBdbSBtreeNode<K,ORDER> previousNodeValue = readNode( node-1 );
00164             { previousNodeValue.child[0] = node; }
00165             updateNode( node-1, previousNodeValue );
00166         }
00167     }
00168 }
00169 
00170 /////////////////
00171 // End Of File //
00172 /////////////////

Generated on Mon Dec 5 18:22:00 2005 for CDB by doxygen1.3-rc3