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

CdbBdbSBtreeNode.hh

Go to the documentation of this file.
00001 #ifndef CDBBDBSHARED_BTREE_NODE_HH
00002 #define CDBBDBSHARED_BTREE_NODE_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbBdbSBtreeNode.hh,v 1.6 2004/08/06 05:54:24 bartoldu Exp $
00006 
00007 #include "BdbUtil/Bdb.hh"
00008 
00009 /// The default order of the B-tree
00010 /**
00011   * NOTE: This order can't be changed after a persistent B-tree object
00012   *       is created.
00013   */
00014 class CdbBdbSBtreeDefaultOrder {
00015 
00016 public:
00017 
00018     enum { N = 2 };
00019 };
00020 
00021 /// An embeddable node class for the persistent capable B-tree.
00022 /**
00023   * This template class implement nodes for the corresponding B-tree
00024   * data structures and related algorithms.
00025   *
00026   * The template is parametrized by mean of the following parameters:
00027   *
00028   *     K - is a type of keys. This type has to provide the following
00029   *         methods:
00030   *
00031   *             default constructor
00032   *             copy constructor
00033   *             destructor
00034   *
00035   *         and operators:
00036   *
00037   *             =
00038   *             ==
00039   *             <
00040   *             <<    (into std::ostream)
00041   *
00042   *     ORDER - is a utility class with the only usable enumeration
00043   *             specifying an order of the tree. Here is expected interface
00044   *             of this class:
00045   *
00046   *             class <name > ... {
00047   *             public:
00048   *                 enum { N = <order> };
00049   *             };
00050   *
00051   *         The reason why we're usingthis tricky way to specify the order
00052   *         instead of the non-class template parameter, like "unsigned ORDER",
00053   *         is that teh current version of the DDL compiler does not seem
00054   *         to support this kind of syntax.
00055   */
00056 template< class K,
00057           class ORDER = CdbBdbSBtreeDefaultOrder >
00058 class CdbBdbSBtreeNode {
00059 
00060 public:
00061 
00062   // The default constructor will create an empty leaf node w/o a parent,
00063   // with no values and no children. The normal constructor will setup
00064   // a parent of the node.
00065 
00066     CdbBdbSBtreeNode( )           : parent(0), isLeaf(d_True), n(0) { }
00067     CdbBdbSBtreeNode( d_ULong p ) : parent(p), isLeaf(d_True), n(0) { }
00068 
00069   // The copy constructor
00070   /**
00071     */
00072     CdbBdbSBtreeNode( const CdbBdbSBtreeNode<K,ORDER>& theNode )
00073     {
00074         copySelf( theNode );
00075     }
00076 
00077   /// The destructor
00078   /**
00079     * NOTE: The destructor is NOT virtual because this is an embedded
00080     *       class.
00081     */
00082     ~CdbBdbSBtreeNode( ) { }
00083 
00084   // The assignment operator
00085   /**
00086     */
00087     CdbBdbSBtreeNode<K,ORDER>& operator=( const CdbBdbSBtreeNode<K,ORDER>& theNode )
00088     {
00089         if( this != &theNode ) copySelf( theNode );
00090         return *this;
00091     }
00092 
00093 private:
00094 
00095   /// Set up own context from specified one
00096   /**
00097     * This helper method is used by constructors and assignment operator.
00098     */
00099     void copySelf( const CdbBdbSBtreeNode<K,ORDER>& theNode )
00100     {
00101         parent = theNode.parent;
00102         isLeaf = theNode.isLeaf;
00103         n      = theNode.n;
00104         for( unsigned int i = 0; i <= 2 * ORDER::N; ++i ) child[i] = theNode.child[i];
00105         for( unsigned int i = 0; i <  2 * ORDER::N; ++i ) key  [i] = theNode.key  [i];
00106     }
00107 
00108 public:
00109 
00110   // Back link to the parent
00111 
00112     d_ULong parent;
00113 
00114   // There are 'n+1' pointers to child nodes.
00115 
00116     d_ULong child[ 2 * ORDER::N + 1 ];
00117 
00118   // There are 'n' keys in the node. The keys are sorted.
00119 
00120     K key[ 2 * ORDER::N ];
00121 
00122   // The leaf node does not have any children.
00123 
00124     d_Boolean isLeaf;
00125 
00126   // Occupancy for "root" node:        0 .. 2 * ORDER::N
00127   //               other nodes: ORDER::N .. 2 * ORDER::N
00128 
00129     d_Octet n;
00130 };
00131 
00132 template< class ORDER,
00133           class K >
00134 std::ostream&
00135 operator<<( std::ostream&                         o,
00136             const CdbBdbSBtreeNode<K,ORDER>& theNode )
00137 {
00138     return o << theNode.parent;
00139 }
00140 
00141 #endif  // CDBBDBSHARED_BTREE_NODE_HH

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