IndexImpl.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    Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 
00025 #ifndef _EYEDB_INDEX_IMPL_H
00026 #define _EYEDB_INDEX_IMPL_H
00027 
00028 namespace eyedb {
00029 
00035   class BEMethod_C;
00036   class Dataspace;
00037 
00038   class IndexImpl : public gbxObject {
00039   
00040   public:
00041     enum Type {
00042       Hash = 1,
00043       BTree
00044     };
00045 
00055     IndexImpl(Type type, const Dataspace *dataspace = 0,
00056               unsigned int keycount_or_degree = 0,
00057               BEMethod_C *mth = 0,
00058               const int impl_hints[] = 0,
00059               unsigned int impl_hints_cnt = 0);
00060 
00069     static Status make(Type type, const char *hints,
00070                        IndexImpl *&idximpl, Bool is_string = False) {
00071       return make(0, type, hints, idximpl, is_string);
00072     }
00073 
00074     // database is needed if hints contains a hash method
00084     static Status make(Database *db, Type type, const char *hints,
00085                        IndexImpl *&idximpl, Bool is_string = False);
00086 
00091     Type getType() const {return type;}
00092 
00097     const char *getStringType() const {return type == Hash ? "hash" : "btree";}
00098 
00103     IndexImpl *clone() const;
00104 
00109     const Dataspace *getDataspace() const {return dataspace;}
00110 
00116     Bool compare(const IndexImpl *idximpl) const;
00117 
00122     unsigned int getKeycount() const {return u.hash.keycount;}
00123 
00128     BEMethod_C *getHashMethod() const {return u.hash.mth;}
00129 
00134     std::string getHintsString() const;
00135 
00141     std::string toString(const char *indent = "") const;
00142 
00147     unsigned int getDegree() const {return u.degree;}
00148 
00154     const int *getImplHints(unsigned int &_impl_hints_cnt) const {
00155       _impl_hints_cnt = impl_hints_cnt;
00156       return impl_hints;
00157     }
00158 
00159     ~IndexImpl();
00160 
00166     unsigned int getMagorder(unsigned int def_magorder) const;
00167 
00173     static unsigned int estimateHashKeycount(unsigned int magorder);
00174 
00180     static unsigned int estimateBTreeDegree(unsigned int magorder);
00181 
00188     static const char *hashHintToStr(unsigned int hints, Bool cap = False);
00189 
00195     static bool isHashHintImplemented(unsigned int hints);
00196 
00197   private:
00198     Type type;
00199     union {
00200       struct {
00201         unsigned int keycount;
00202         BEMethod_C *mth;
00203       } hash;
00204       unsigned int degree;
00205     } u;
00206 
00207     const Dataspace *dataspace;
00208     int *impl_hints;
00209     unsigned int impl_hints_cnt;
00210 
00211     static Status makeHash(Database *db, const char *hints,
00212                            IndexImpl *&idximpl, Bool is_string);
00213     static Status makeBTree(Database *db, const char *hints,
00214                             IndexImpl *&idximpl, Bool is_string);
00215     void garbage();
00216 
00217     IndexImpl(const IndexImpl &);
00218     IndexImpl& operator=(const IndexImpl &);
00219 
00220   public: // restricted access
00221     static Status decode(Database *, Data, Offset &,
00222                          IndexImpl *&);
00223     static Status code(Data &, Offset &, Size &,
00224                        const IndexImpl &);
00225     void setHashMethod(BEMethod_C *);
00226     void setDataspace(const Dataspace *_d) {dataspace = _d;}
00227   };
00228 
00229   class HashIndexStats;
00230   class BTreeIndexStats;
00231 
00232   class IndexStats {
00233 
00234   public:
00235     IndexStats();
00236     virtual std::string toString(Bool dspImpl, Bool full, const char *indent = "") = 0;
00237     virtual HashIndexStats *asHashIndexStats() {return 0;}
00238     virtual BTreeIndexStats *asBTreeIndexStats() {return 0;}
00239     virtual ~IndexStats() = 0;
00240 
00241     IndexImpl *idximpl;
00242   };
00243 
00244   class HashIndexStats : public IndexStats {
00245 
00246   public:
00247     HashIndexStats();
00248     HashIndexStats *asHashIndexStats() {return this;}
00249     ~HashIndexStats();
00250 
00251     std::string toString(Bool dspImpl, Bool full, const char *indent = "");
00252 
00253     Status printEntries(const char *fmt, FILE *fd = stdout);
00254 
00255     unsigned int min_objects_per_entry;
00256     unsigned int max_objects_per_entry;
00257     unsigned int total_object_count;
00258     unsigned int total_hash_object_count;
00259     unsigned int total_hash_object_size;
00260     unsigned int total_hash_object_busy_size;
00261     unsigned int busy_key_count;
00262     unsigned int free_key_count;
00263 
00264     unsigned int key_count;
00265     struct Entry {
00266       unsigned int object_count;
00267       unsigned int hash_object_count;
00268       unsigned int hash_object_size;
00269       unsigned int hash_object_busy_size;
00270     } *entries;
00271 
00272     static const char fmt_help[];
00273   };
00274 
00275   class BTreeIndexStats : public IndexStats {
00276 
00277   public:
00278     BTreeIndexStats();
00279     ~BTreeIndexStats();
00280     std::string toString(Bool dspImpl, Bool full, const char *indent = "");
00281     virtual BTreeIndexStats *asBTreeIndexStats() {return this;}
00282 
00283     unsigned int degree;
00284     unsigned int dataSize;
00285     unsigned int keySize;
00286     unsigned int keyOffset;
00287     unsigned int keyType;
00288 
00289     unsigned int total_object_count;
00290     unsigned int total_btree_object_count;
00291     unsigned int btree_node_size;
00292     unsigned int total_btree_node_count;
00293     unsigned int btree_key_object_size;
00294     unsigned int btree_data_object_size;
00295     unsigned long long total_btree_object_size;
00296   };
00297 
00302 }
00303 
00304 #endif

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