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 #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];
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 *);
00082 InCore(InCore const &);
00083 InCore& operator=(InCore const &);
00084 ~InCore();
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 }