00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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:
00221 static const int UNKNOWN_IMPL_TYPE;
00222 static const int NOINDEX_IMPL_TYPE;
00223 static Status decode(Database *, Data, Offset &,
00224 IndexImpl *&, int *rimpl_type = 0);
00225 static Status code(Data &, Offset &, Size &,
00226 const IndexImpl *, int impl_type = UNKNOWN_IMPL_TYPE);
00227 void setHashMethod(BEMethod_C *);
00228 void setDataspace(const Dataspace *_d) {dataspace = _d;}
00229 };
00230
00231 class HashIndexStats;
00232 class BTreeIndexStats;
00233
00234 class IndexStats {
00235
00236 public:
00237 IndexStats();
00238 virtual std::string toString(Bool dspImpl, Bool full, const char *indent = "") = 0;
00239 virtual HashIndexStats *asHashIndexStats() {return 0;}
00240 virtual BTreeIndexStats *asBTreeIndexStats() {return 0;}
00241 virtual ~IndexStats() = 0;
00242
00243 IndexImpl *idximpl;
00244 };
00245
00246 class HashIndexStats : public IndexStats {
00247
00248 public:
00249 HashIndexStats();
00250 HashIndexStats *asHashIndexStats() {return this;}
00251 ~HashIndexStats();
00252
00253 std::string toString(Bool dspImpl, Bool full, const char *indent = "");
00254
00255 Status printEntries(const char *fmt, FILE *fd = stdout);
00256
00257 unsigned int min_objects_per_entry;
00258 unsigned int max_objects_per_entry;
00259 unsigned int total_object_count;
00260 unsigned int total_hash_object_count;
00261 unsigned int total_hash_object_size;
00262 unsigned int total_hash_object_busy_size;
00263 unsigned int busy_key_count;
00264 unsigned int free_key_count;
00265
00266 unsigned int key_count;
00267 struct Entry {
00268 unsigned int object_count;
00269 unsigned int hash_object_count;
00270 unsigned int hash_object_size;
00271 unsigned int hash_object_busy_size;
00272 } *entries;
00273
00274 static const char fmt_help[];
00275 };
00276
00277 class BTreeIndexStats : public IndexStats {
00278
00279 public:
00280 BTreeIndexStats();
00281 ~BTreeIndexStats();
00282 std::string toString(Bool dspImpl, Bool full, const char *indent = "");
00283 virtual BTreeIndexStats *asBTreeIndexStats() {return this;}
00284
00285 unsigned int degree;
00286 unsigned int dataSize;
00287 unsigned int keySize;
00288 unsigned int keyOffset;
00289 unsigned int keyType;
00290
00291 unsigned int total_object_count;
00292 unsigned int total_btree_object_count;
00293 unsigned int btree_node_size;
00294 unsigned int total_btree_node_count;
00295 unsigned int btree_key_object_size;
00296 unsigned int btree_data_object_size;
00297 unsigned long long total_btree_object_size;
00298 };
00299
00304 }
00305
00306 #endif