00001
00008 #include"mempl.h"
00009 #include"blockpool.h"
00010 #include"leafpage.h"
00011 #include"indexpage.h"
00012
00013 class Btree;
00014
00019 class Iterator
00020 {
00021 Btree *btree_;
00022 RAMS::RPointer<CommonPage,PAGESIZE> akt_page;
00023 int index;
00024 public:
00025 Iterator(Btree* tree);
00026 bool done();
00027 void advance();
00028 mempl_t key();
00029 mempl_t content();
00030 };
00031
00035 class BtreeStrategy
00036 {
00037 public:
00038 virtual bool splitt_leavenode(LeafPageAccess &lpa)=0;
00039 virtual bool splitt_indexnode(IndexPageAccess &ipa)=0;
00040 };
00041
00045 class TestStrategy : public BtreeStrategy
00046 {
00047 public:
00048 bool splitt_leavenode(LeafPageAccess &lpa);
00049 bool splitt_indexnode(IndexPageAccess &ipa);
00050 } theTestStrategy;
00051
00055 class Btree
00056 {
00057 struct Managementinfo
00058 {
00059 off_t btreeroot;
00060 off_t first_page;
00061 };
00062 protected:
00063 Blockpool bpool;
00064 RAMS::RPointer<CommonPage,PAGESIZE> root;
00065 RAMS::RPointer<CommonPage,PAGESIZE> first_page;
00066 BtreeStrategy* strategy;
00067
00071 int findpage(RAMS::RPointer<CommonPage,PAGESIZE>& ret,const octet_t *key,size_t keylen);
00077 void replacelargestkey(RAMS::RPointer<CommonPage,PAGESIZE>& ret,const octet_t *key,size_t keylen);
00078
00086 void blattverkettung(off_t prev,off_t next,RAMS::RPointer<CommonPage,PAGESIZE>& pp1,RAMS::RPointer<CommonPage,PAGESIZE>& pp2);
00087
00088 public:
00089 Btree():strategy(&theTestStrategy) {}
00090 void init(const char *filename);
00091 int insert(const octet_t *key,size_t keylen,const octet_t *cont,size_t l);
00092 mempl_t find(mempl_t key);
00093 friend class LeafPageIterator;
00094 friend void kommando_dump(Btree &tree);
00095 };
00096
00100 class LeafPageIterator
00101 {
00102 RAMS::RPointer<CommonPage,PAGESIZE> akt_page;
00103 LeafPageAccess lpac;
00104 public:
00105 LeafPageIterator(Btree* tree)
00106 {
00107 akt_page=tree->first_page;
00108 lpac.setto(akt_page.ptr());
00109 }
00110 bool done() { return akt_page.offset()==0; }
00111 void advance()
00112 {
00113 lpac.next(akt_page);
00114 if(akt_page.offset()!=0)
00115 { lpac.setto(akt_page.ptr());
00116 }
00117 }
00118 LeafPageAccess& page() { return lpac; }
00119 void *pageptr() { return akt_page.ptr(); }
00120 };