Main Page | Class Hierarchy | Class List | File List | Class Members

btree.h

00001 //-< BTREE.CPP >-----------------------------------------------------*--------*
00002 // GigaBASE                  Version 1.0         (c) 1999  GARRET    *     ?  *
00003 // (Post Relational Database Management System)                      *   /\|  *
00004 //                                                                   *  /  \  *
00005 //                          Created:      1-Jan-99    K.A. Knizhnik  * / [] \ *
00006 //                          Last update: 25-Oct-99    K.A. Knizhnik  * GARRET *
00007 //-------------------------------------------------------------------*--------*
00008 // B-Tree interface
00009 //-------------------------------------------------------------------*--------*
00010 
00011 #ifndef __BTREE_H__
00012 #define __BTREE_H__
00013 
00014 
00015 BEGIN_GIGABASE_NAMESPACE
00016 
00017 class dbBtreePage {
00018   public:
00019     nat4 nItems;
00020     nat4 size;
00021 
00022     struct str {
00023         oid_t oid;
00024         nat2  size;
00025         nat2  offs;
00026     };
00027 
00028     enum { dbMaxKeyLen = (dbPageSize - sizeof(str)*2) / sizeof(char_t) / 2 };
00029 
00030     struct item {
00031         oid_t oid;
00032         int   keyLen;
00033         union {
00034             int1    keyInt1;
00035             int2    keyInt2;
00036             int4    keyInt4;
00037             db_int8 keyInt8;
00038             oid_t   keyOid;
00039             real4   keyReal4;
00040             real8   keyReal8;
00041             char_t  keyChar[dbMaxKeyLen];
00042         };
00043     };
00044     enum {
00045         maxItems = (dbPageSize - 8) / sizeof(oid_t)
00046     };
00047 
00048 
00049     union {
00050         oid_t  record[maxItems];
00051         int1   keyInt1[(dbPageSize-8) / sizeof(int1)];
00052         int2   keyInt2[(dbPageSize-8) / sizeof(int2)];
00053         int4   keyInt4[(dbPageSize-8) / sizeof(int4)];
00054         db_int8   keyInt8[(dbPageSize-8) / sizeof(db_int8)];
00055         oid_t  keyOid[(dbPageSize-8)  / sizeof(oid_t)];
00056         real4  keyReal4[(dbPageSize-8) / sizeof(real4)];
00057         real8  keyReal8[(dbPageSize-8) / sizeof(real8)];
00058         char   keyChar[dbPageSize-8];
00059         str    keyStr[1];
00060     };
00061 
00062     static oid_t allocate(dbDatabase* db, oid_t root, int type, int sizeofType, item& ins);
00063 
00064     static int   insert(dbDatabase* db, oid_t pageId,
00065                         int type, int sizeofType, dbUDTComparator comparator, item& ins, int height);
00066     static int   remove(dbDatabase* db, oid_t pageId,
00067                         int type, int sizeofType, dbUDTComparator comparator, item& rem, int height);
00068 
00069     static void  purge(dbDatabase* db, oid_t pageId, int type, int height);
00070 
00071     int          insertStrKey(dbDatabase* db, int r, item& ins, int height);
00072     int          replaceStrKey(dbDatabase* db, int r, item& ins, int height);
00073     int          removeStrKey(int r);
00074     void         compactify(int m);
00075 
00076     int          handlePageUnderflow(dbDatabase* db, int r, int type, int sizeofType, item& rem,
00077                                      int height);
00078 
00079     bool         find(dbDatabase* db, dbSearchContext& sc, int type, int sizeofType,
00080                       dbUDTComparator comparator, int height);
00081 
00082     bool         traverseForward(dbDatabase* db, dbAnyCursor* cursor,
00083                                  dbExprNode* condition, int type, int height);
00084     bool         traverseBackward(dbDatabase* db, dbAnyCursor* cursor,
00085                                   dbExprNode* condition, int type, int height);
00086 };
00087 
00088 
00089 class GIGABASE_DLL_ENTRY dbBtree : public dbRecord {
00090   protected:
00091     oid_t root;
00092     int4  height;
00093     int4  type;
00094     int4  sizeofType;
00095 
00096   public:
00097     enum { 
00098         FLAGS_CASE_INSENSITIVE = 1, 
00099         FLAGS_THICK = 2
00100     };
00101     int1  flags; 
00102 
00103     bool isCaseInsensitive() { 
00104         return (flags & FLAGS_CASE_INSENSITIVE) != 0;
00105     }
00106 
00107     enum OperationEffect {
00108         done,
00109         overflow,
00110         underflow,
00111         not_found
00112     };
00113 
00114     static oid_t allocate(dbDatabase* db, int type, int sizeofType, int flags = 0);
00115     static void  find(dbDatabase* db, oid_t treeId, dbSearchContext& sc, dbUDTComparator comparator);
00116     static void  insert(dbDatabase* db, oid_t treeId, oid_t recordId, int offs, dbUDTComparator comparator);
00117     static void  insert(dbDatabase* db, oid_t treeId, dbBtreePage::item& ins, dbUDTComparator comparator);
00118     static void  remove(dbDatabase* db, oid_t treeId, oid_t recordId, int offs, dbUDTComparator comparator);
00119     static void  drop(dbDatabase* db, oid_t treeId);
00120     static void  purge(dbDatabase* db, oid_t treeId);
00121 
00122     static void  traverseForward(dbDatabase* db, oid_t treeId,
00123                                  dbAnyCursor* cursor, dbExprNode* condition);
00124     static void  traverseBackward(dbDatabase* db, oid_t treeId,
00125                                   dbAnyCursor* cursor, dbExprNode* condition);
00126     static void  traverseForward(dbDatabase* db, oid_t treeId,
00127                                  dbAnyCursor* cursor)
00128     {
00129         traverseForward(db, treeId, cursor, NULL);
00130     }
00131     static void  traverseBackward(dbDatabase* db, oid_t treeId,
00132                                   dbAnyCursor* cursor)
00133     {
00134         traverseBackward(db, treeId, cursor, NULL);
00135     }
00136 };
00137 
00138 
00139 
00140 class dbThickBtreePage {
00141   public:
00142     nat4 nItems;
00143     nat4 size;
00144 
00145     struct reference {
00146         oid_t oid;
00147         oid_t recId;
00148     };
00149 
00150     struct str : reference {
00151         nat2  size;
00152         nat2  offs;
00153     };
00154     
00155     enum { dbMaxKeyLen = (dbPageSize - sizeof(str)*2) / sizeof(char_t) / 2 };
00156 
00157     struct item : reference {
00158         int   keyLen;
00159         union {
00160             int1    keyInt1;
00161             int2    keyInt2;
00162             int4    keyInt4;
00163             db_int8 keyInt8;
00164             oid_t   keyOid;
00165             real4   keyReal4;
00166             real8   keyReal8;
00167             char_t  keyChar[dbMaxKeyLen];
00168         };
00169     };
00170     enum {
00171         maxItems = (dbPageSize - 8) / sizeof(reference)
00172     };
00173 
00174 
00175     union {
00176         reference ref[maxItems];
00177         int1   keyInt1[(dbPageSize-8) / sizeof(int1)];
00178         int2   keyInt2[(dbPageSize-8) / sizeof(int2)];
00179         int4   keyInt4[(dbPageSize-8) / sizeof(int4)];
00180         db_int8   keyInt8[(dbPageSize-8) / sizeof(db_int8)];
00181         oid_t  keyOid[(dbPageSize-8)  / sizeof(oid_t)];
00182         real4  keyReal4[(dbPageSize-8) / sizeof(real4)];
00183         real8  keyReal8[(dbPageSize-8) / sizeof(real8)];
00184         char   keyChar[dbPageSize-8];
00185         str    keyStr[1];
00186     };
00187 
00188     static oid_t allocate(dbDatabase* db, oid_t root, int type, int sizeofType, item& ins);
00189 
00190     static int   insert(dbDatabase* db, oid_t pageId,
00191                         int type, int sizeofType, dbUDTComparator comparator, item& ins, int height);
00192     static int   remove(dbDatabase* db, oid_t pageId,
00193                         int type, int sizeofType, dbUDTComparator comparator, item& rem, int height);
00194 
00195     static void  purge(dbDatabase* db, oid_t pageId, int type, int height);
00196 
00197     int          insertStrKey(dbDatabase* db, int r, item& ins, int height);
00198     int          replaceStrKey(dbDatabase* db, int r, item& ins, int height);
00199     int          removeStrKey(int r);
00200     void         compactify(int m);
00201 
00202     int          handlePageUnderflow(dbDatabase* db, int r, int type, int sizeofType, item& rem,
00203                                      int height);
00204 
00205     bool         find(dbDatabase* db, dbSearchContext& sc, int type, int sizeofType,
00206                       dbUDTComparator comparator, int height);
00207 
00208     bool         traverseForward(dbDatabase* db, dbAnyCursor* cursor,
00209                                  dbExprNode* condition, int type, int height);
00210     bool         traverseBackward(dbDatabase* db, dbAnyCursor* cursor,
00211                                   dbExprNode* condition, int type, int height);
00212 };
00213 
00214 END_GIGABASE_NAMESPACE
00215 
00216 #endif

Generated on Thu Feb 12 18:46:26 2004 for GigaBASE by doxygen 1.3.5