BIdxBTree.h

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Authors: Stuart Pook
00022             Eric Viara <viara@sysra.com>
00023 */
00024 
00025 #include        <assert.h>
00026 
00027 namespace eyedbsm {
00028 
00029   static inline unsigned int
00030   degree2MaxChildren(int degree)
00031   {
00032     return 2 * degree - 1;
00033   }
00034 
00035   static const int BIDX_IMPL_HINTS_CNT = 4;
00036 
00037   struct BIdx::BTree
00038   {
00039     unsigned int idxtype;
00040     unsigned int count;
00041     short dspid;
00042     unsigned int version;
00043     unsigned int degree;
00044     unsigned int maxchildren;
00045     unsigned int dataSize;
00046     unsigned int keySize;
00047     unsigned int impl_hints[BIDX_IMPL_HINTS_CNT]; // 24/12/01 for future use
00048     Oid root;
00049     Oid type;
00050   };
00051 
00052   struct BIdx::Node
00053   {
00054     int leaf;
00055     unsigned int n;
00056     Oid keys;
00057     Oid data;
00058     Oid c[1];
00059 
00060     static unsigned int nodeSize(const BIdx *idx);
00061     static unsigned int nodeSize(unsigned int);
00062     static Node *allocNode(BIdx *idx);
00063     static Node *allocNode(unsigned int degree);
00064     static Node *copyNode(BIdx *idx, Node *from);
00065     static void freeNode(Node *);
00066   };
00067 
00068   class BIdx::InCore
00069   {
00070 #ifdef USE_CACHE
00071     void * keys_b, * data_b;
00072     Node * node_b;
00073 #endif
00074     void * keys;
00075     void * data;
00076   public:
00077     BIdx * const idx;
00078     Oid oid;
00079     Node *node;
00080         
00081     InCore(BIdx *);                             // constructor: create InCore
00082     InCore(InCore const &);                     // copy constructor
00083     InCore& operator=(InCore const &);          // assignment: cleanup and copy
00084     ~InCore();                                  // destructor: cleanup
00085 
00086     Status create();
00087     Status destroy();
00088     Status write();
00089     Status read(Oid const *);
00090     void * k(unsigned i) { assert(i < node->n); return (char *)keys + i * idx->keySize;}
00091     void * d(unsigned i) { assert(i < node->n); return (char *)data + i * idx->dataSize;}
00092     void const * k(unsigned i) const { assert(i < node->n); return (char const *)keys + i * idx->keySize;}
00093     void const * d(unsigned i) const { assert(i < node->n); return (char const *)data + i * idx->dataSize;}
00094     void kdCopy(void * kOut, void * dOut, int xp, unsigned cnt = 1) const {
00095       idx->kdCopy(kOut, dOut, k(xp), d(xp), cnt);
00096     }
00097     void kdCopy(int xp, void const * kIn, void const * dIn, unsigned cnt = 1) {
00098       idx->kdCopy(k(xp), d(xp), kIn, dIn, cnt);
00099     }
00100     void kdCopy(int xp, InCore const * y, int yp, unsigned cnt = 1) {
00101       kdCopy(xp, y->k(yp), y->d(yp), cnt);
00102     }
00103     int cmp(unsigned i, void const * k, void const * d, unsigned char bswap) const;
00104     int cmp(unsigned i, void const * key, unsigned char bswap) const { return idx->cmp(k(i), key, bswap); }
00105   };
00106 
00107   Status objectRead(DbHandle const *dbh, size_t size, void * object, Oid const *const oid);
00108   Status objectWrite(DbHandle const *dbh, size_t size, void * object, Oid const *const oid);
00109   Status objectDelete(DbHandle const *dbh, size_t size, Oid const *const oid);
00110 
00111   void x2h_btree(BIdx::BTree &btree);
00112   void h2x_btree(BIdx::BTree &xbtree, const BIdx::BTree &hbtree);
00113 
00114   void x2h_keytype(Idx::KeyType *keytype, unsigned int nkeys);
00115   void h2x_keytype(Idx::KeyType *xkeytype,
00116                    const Idx::KeyType *hkeytype, unsigned int nkeys);
00117 
00118   void x2h_node(BIdx::Node &node, unsigned int maxchildren);
00119   void h2x_node(BIdx::Node &xnode, const BIdx::Node &hnode,
00120                 unsigned int maxchildren, Boolean complete);
00121 }

Generated on Mon Dec 22 18:15:50 2008 for eyedb by  doxygen 1.5.3