BIdx.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 
00026 #ifndef _eyedbsm_BIdx_
00027 #define _eyedbsm_BIdx_
00028 
00029 #include <string.h>
00030 
00031 #include <eyedbsm/Idx.h>
00032 
00033 namespace eyedbsm {
00034 
00040   enum {
00041     BIDX_DEF_DEGREE = 128
00042   };
00043 
00047   class BIdx : public Idx {
00048   public:
00049     class BTree;
00050     class Node;
00051     class Space;
00052     class InCore;
00053 
00054   private:
00055 
00056     friend class InCore;
00057     friend class Node;
00058     friend class Space;
00059     friend class BIdxCursor;
00060     Space * free;
00061     Space * occupied;
00062 
00063     eyedbsm::DbHandle * const dbh;
00064     eyedbsm::Oid treeOid;
00065     KeyType * _keyType;
00066     unsigned _nkeys;
00067     unsigned keySize;
00068     unsigned dataSize;
00069     short dspid;
00070     unsigned int degree;
00071     unsigned int maxchildren;
00072     unsigned int count;
00073     eyedbsm::Status stat;
00074     BIdx(BIdx const &);                 // prevent copying
00075     BIdx & operator=(BIdx const &);     // prevent copying
00076     eyedbsm::Status fatal();
00077     eyedbsm::Status fatal(eyedbsm::Status);
00078     void kdCopy(void * kO, void * dO, void const * k, void const * d,
00079                 unsigned int cnt = 1) const;
00080     eyedbsm::Status create(unsigned int degree, unsigned dataSize, KeyType const types[], unsigned ntypes, short dspid);
00081     eyedbsm::Status count_manage(int inc);
00082     eyedbsm::Status copy_realize(Idx *idx) const;
00083     eyedbsm::Status readBTree(BTree &) const;
00084     eyedbsm::Status writeBTree(const BTree &) const;
00085     eyedbsm::Status readKeyType(KeyType *&, unsigned int nkeys, const eyedbsm::Oid &) const;
00086     eyedbsm::Status createKeyType(const KeyType *, unsigned int nkeys, eyedbsm::Oid *) const;
00087     eyedbsm::Status readNode(Node *, const eyedbsm::Oid &) const;
00088     eyedbsm::Status writeNode(const Node *, const eyedbsm::Oid &) const;
00089     eyedbsm::Status createNode(const Node *, eyedbsm::Oid *) const;
00090     eyedbsm::Status searchPerform(const void *key, unsigned int *found_cnt, Boolean found_any, void * data);
00091     Node *tmpnode;
00092 
00093   public:
00101     int cmp(void const *key, void const *d, unsigned char bswap);
00102 
00112     BIdx(eyedbsm::DbHandle * vh, unsigned dataSize, KeyType const types[],
00113          short dspid,
00114          unsigned int degree = BIDX_DEF_DEGREE,
00115          unsigned ntypes = 1);
00116 
00125     BIdx(eyedbsm::DbHandle * vh, Type type, unsigned dataSize,
00126          short dspid,
00127          unsigned int degree = BIDX_DEF_DEGREE);
00128 
00135     BIdx(eyedbsm::DbHandle * vh, 
00136          eyedbsm::Oid const &idx,
00137          eyedbsm::Boolean (*precmp)(void const * p, void const * q, KeyType const * type, int & r) = 0);
00138 
00143     void open(eyedbsm::Boolean (*precmp)(void const * p, void const * q,
00144                                          KeyType const * type, int & r) = 0);
00145 
00150     virtual BIdx *asBIdx() {return this;}
00151 
00157     Status move(short dspid, eyedbsm::Oid &newoid);
00158 
00172     eyedbsm::Status reimplementToHash(eyedbsm::Oid &newoid, int key_count, int mag_order = 0,
00173                                       short dspid = eyedbsm::DefaultDspid,
00174                                       const int *impl_hints = 0,
00175                                       unsigned int impl_hints_cnt = 0,
00176                                       hash_key_t hash_key = 0,
00177                                       void *hash_data = 0,
00178                                       KeyType *ktype = 0);
00179 
00187     eyedbsm::Status reimplementToBTree(eyedbsm::Oid &newoid, int degree = 0,
00188                                        short dspid = eyedbsm::DefaultDspid);
00189 
00190     // stats methods not implemented
00191     struct Stats {
00192       const BIdx *idx;
00193       /*
00194         unsigned int degree;
00195         unsigned int dataSize;
00196         unsigned int keySize;
00197       */
00198       unsigned int keyOffset;
00199       unsigned int keyType;
00200 
00201       unsigned int total_object_count;
00202       unsigned int total_btree_object_count;
00203       unsigned int btree_node_size;
00204       unsigned int total_btree_node_count;
00205       unsigned int btree_key_object_size;
00206       unsigned int btree_data_object_size;
00207       unsigned long long total_btree_object_size;
00208 
00209       void trace(FILE * = stdout) const;
00210       std::string toString() const;
00211     };
00212 
00213     eyedbsm::Status getStats(std::string& stats) const;
00214     eyedbsm::Status getStats(BIdx::Stats &stats) const;
00215 
00220     unsigned getKeySize() const {return keySize;}
00221 
00226     unsigned getDataSize() const {return dataSize;}
00227 
00233     const Idx::KeyType *getKeyTypes(unsigned int &nkeys) const {
00234       nkeys = _nkeys;
00235       return _keyType;
00236     }
00237 
00242     short getDspid() const {return dspid;}
00243 
00248     unsigned int getDegree() const {return degree;}
00249 
00254     unsigned int getMaxChildren() const {return maxchildren;}
00255 
00260     unsigned int getCount() const;
00261 
00266     short getDefaultDspid() const;
00267 
00273     void setDefaultDspid(short dspid);
00274 
00281     eyedbsm::Status getObjects(eyedbsm::Oid *&oids, unsigned int &cnt) const;
00282 
00288     static unsigned int getMagOrder(unsigned int degree);
00289 
00295     static unsigned int getDegree(unsigned int magorder);
00296 
00297     ~BIdx();
00298 
00305     eyedbsm::Status insert(void const * key, void const * data);
00306 
00314     Status insert(const void *key, const void *data, unsigned int datasz);
00315 
00323     eyedbsm::Status remove(void const * key, void const * data, eyedbsm::Boolean * found = 0);
00324 
00333     Status remove(const void *key, const void *data, unsigned int datasz, Boolean *found = 0);
00334 
00342     Status search(const void *key, unsigned int *found_cnt);
00343 
00351     eyedbsm::Status searchAny(void const * key, eyedbsm::Boolean * found, void * data = 0);
00352 
00357     eyedbsm::Status destroy();
00358 
00359     //  eyedbsm::Status check(unsigned long * = 0);
00360 
00365     eyedbsm::Oid const & oid() const { return treeOid; }
00366 
00371     eyedbsm::Status status() const { return stat; }
00372   };
00373 
00374   class BIdxChain;
00375 
00379   class BIdxCursor : public IdxCursor {
00380     BIdx * idx;
00381     void * sKey;
00382     eyedbsm::Boolean sExclusive;
00383     void * eKey;
00384     eyedbsm::Boolean eExclusive;
00385     BIdxChain * chain;
00386     BIdxChain * chainFirst;
00387     static char const defaultSKey[];
00388     BIdxCursor(BIdxCursor const &);
00389     BIdxCursor & operator=(BIdxCursor const &);
00390     eyedbsm::Boolean (*user_cmp)(const void *key, void *cmp_arg);
00391     void *cmp_arg;
00392 
00393   public:
00404     BIdxCursor(BIdx *idx,
00405                void const * sKey = 0,
00406                void const * eKey = defaultSKey,
00407                eyedbsm::Boolean sExclusive = eyedbsm::False,
00408                eyedbsm::Boolean eExclusive = eyedbsm::False,
00409                eyedbsm::Boolean (*user_cmp)(const void *key, void *cmp_arg) = 0,
00410                void *cmp_arg = 0);
00411 
00419     Status next(eyedbsm::Boolean * found, void * data = 0, Idx::Key * key = 0);
00420 
00428     Status next(Boolean *found, DataBuffer &data, Idx::Key *key = 0);
00429 
00436     Status next(unsigned int *found_cnt, Idx::Key *key = 0);
00437 
00438     ~BIdxCursor();
00439   };
00440 
00444 }
00445 
00446 #endif

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