00001 #ifndef CDBROOREADONLY_BTREE_R_RDL 00002 #define CDBROOREADONLY_BTREE_R_RDL 00003 00004 // File and Version Information: 00005 // $Id: CdbRooRoBtreeR.rdl,v 1.1 2004/11/09 20:33:04 gapon Exp $ 00006 00007 #include "CdbRooReadonly/CdbRooRoAbsBtreeR.hh" 00008 00009 #include <vector> 00010 00011 /// This is a persistent implementation for of a B-tree. 00012 /** 00013 * This implementation requires that the whole contents of the B-tree were 00014 * stored in memory as a vector. 00015 * 00016 * NOTE: This model may not be efficient for operations with trees having 00017 * many nodes (how many is as subject of a separate investigation 00018 * for a specific values of template parameters). 00019 */ 00020 template< class K, 00021 class FCP = CdbRooRoBtreeDefaultFCPR<K>, 00022 UInt_t ORDER = 4 > 00023 class CdbRooRoBtreeR : public CdbRooRoAbsBtreeR<K,FCP,ORDER> { 00024 00025 public: 00026 00027 // Constructors 00028 00029 CdbRooRoBtreeR( ); 00030 00031 // Destructor 00032 00033 virtual ~CdbRooRoBtreeR( ) { } 00034 00035 protected: 00036 00037 /// Get a root node of the B-tree 00038 /** 00039 * Implements the corresponding method of the base class. 00040 * 00041 * @see CdbRooRoAbsBtreeR::root() 00042 */ 00043 virtual UInt_t root( ) const { return _root; } 00044 00045 /// Set new root node of the B-tree 00046 /** 00047 * Implements the corresponding method of the base class. 00048 * 00049 * @see CdbRooRoAbsBtreeR::root() 00050 */ 00051 virtual void set_root( UInt_t node ) { _root = node; } 00052 00053 /// Get a copy of specified node 00054 /** 00055 * Implements the corresponding method of the base class. 00056 * 00057 * @see CdbRooRoAbsBtreeR::readNode() 00058 */ 00059 virtual CdbRooRoBtreeNodeR<K,ORDER> readNode( UInt_t node ) const { return _nodes[node]; } 00060 00061 /// Save back the value of specified node 00062 /** 00063 * Implements the corresponding method of the base class. 00064 * 00065 * @see CdbRooRoAbsBtreeR::updateNode() 00066 */ 00067 virtual void updateNode( UInt_t node, 00068 const CdbRooRoBtreeNodeR<K,ORDER>& value ) { _nodes[node] = value; } 00069 00070 /// Allocator 00071 /** 00072 * Implements the corresponding method of the base class. 00073 * 00074 * @see CdbRooRoAbsBtreeR::root() 00075 */ 00076 virtual UInt_t allocate( UInt_t parent = 0 ); 00077 00078 /// Disposer 00079 /** 00080 * Implements the corresponding method of the base class. 00081 * 00082 * @see CdbRooRoAbsBtreeR::root() 00083 */ 00084 virtual void release( UInt_t node ); 00085 00086 private: 00087 00088 /// This is in fact a normal/default constructor for specified node. 00089 /** 00090 * By default the node does not have a parent. 00091 */ 00092 void init_node( UInt_t node, 00093 UInt_t parent ); 00094 00095 /// Extend a list of free nodes 00096 /** 00097 * This list is only extended if it's empty. 00098 */ 00099 void extend_free_list( ); 00100 00101 private: 00102 00103 /// The actual storage. 00104 /** 00105 * The first element of the array (index = 0) is not used, because 00106 * this number is meant to simulate "null pointer". 00107 * 00108 * The second element (index = 1) is used as a default root node. 00109 * This will change as the tree will expand. 00110 * 00111 * Initially spare elements begin from the index = 2. 00112 * This will also change as the tree will expand. 00113 */ 00114 std::vector< CdbRooRoBtreeNodeR<K,ORDER> > _nodes; 00115 00116 /// An index of the root node 00117 00118 UInt_t _root; 00119 00120 /// An index of the first spare node 00121 /** 00122 * These nodes form a linked list. So the first spare node is actually 00123 * the head of the list. 00124 */ 00125 UInt_t _free; 00126 00127 // This typedef is needed to avoid problems with the ClassDef macro used below. 00128 00129 typedef CdbRooRoBtreeR<K,FCP,ORDER> MyType; 00130 00131 ClassDef(MyType,1); 00132 }; 00133 00134 // Template class implementation 00135 00136 #ifndef __CINT__ 00137 #include "CdbRooReadonly/CdbRooRoBtreeR.cc" 00138 #endif 00139 #endif /* CDBROOREADONLY_BTREE_R_RDL */
1.3-rc3