00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __RTREE_H__
00012 #define __RTREE_H__
00013
00014 BEGIN_GIGABASE_NAMESPACE
00015
00016 class dbRtreePage {
00017 public:
00018 struct branch {
00019 rectangle rect;
00020 oid_t p;
00021 };
00022
00023 enum {
00024 card = (dbPageSize - 4) / sizeof(branch),
00025 min_fill = card/2
00026 };
00027
00028 struct reinsert_list {
00029 oid_t chain;
00030 int level;
00031 reinsert_list() { chain = 0; }
00032 };
00033
00034 bool find(dbDatabase* db, dbSearchContext& sc, int level) const;
00035 static bool find(dbDatabase* db, oid_t rootId, dbSearchContext& sc, int level);
00036
00037 oid_t insert(dbDatabase* db, rectangle const& r, oid_t recordId, int level);
00038 static oid_t insert(dbDatabase* db, rectangle const& r, oid_t pageId, oid_t recordId, int level);
00039
00040 bool remove(dbDatabase* db, rectangle const& r, oid_t recordId, int level,
00041 reinsert_list& rlist);
00042 static bool remove(dbDatabase* db, rectangle const& r, oid_t pageId, oid_t recordId,
00043 int level, reinsert_list& rlist);
00044
00045 void cover(rectangle& r) const;
00046 static void cover(dbDatabase* db, oid_t pageId, rectangle& r);
00047
00048 oid_t split_page(dbDatabase* db, branch const& br);
00049
00050 oid_t add_branch(dbDatabase* db, branch const& br) {
00051 if (n < card) {
00052 b[n++] = br;
00053 return 0;
00054 } else {
00055 return split_page(db, br);
00056 }
00057 }
00058 void remove_branch(int i);
00059
00060 static void purge(dbDatabase* db, oid_t pageId, int level);
00061
00062 oid_t next_reinsert_page() const {
00063 return b[card-1].p;
00064 }
00065
00066 static oid_t allocate(dbDatabase* db, oid_t recordId, rectangle const& r);
00067 static oid_t allocate(dbDatabase* db, oid_t rootId, oid_t p);
00068
00069 int4 n;
00070 branch b[card];
00071 };
00072
00073 class GIGABASE_DLL_ENTRY dbRtree : public dbRecord {
00074 public:
00075 enum searchOp {
00076 EQUAL,
00077 OVERLAPS,
00078 SUPERSET,
00079 PROPER_SUPERSET,
00080 SUBSET,
00081 PROPER_SUBSET
00082 };
00083
00084 static oid_t allocate(dbDatabase* db);
00085 static bool find(dbDatabase* db, oid_t treeId, dbSearchContext& sc);
00086 static void insert(dbDatabase* db, oid_t treeId, oid_t recordId, int offs);
00087 static void insert(dbDatabase* db, oid_t treeId, oid_t recordId, rectangle const& r);
00088 static void remove(dbDatabase* db, oid_t treeId, oid_t recordId, int offs);
00089 static void purge(dbDatabase* db, oid_t treeId);
00090 static void drop(dbDatabase* db, oid_t treeId);
00091
00092 protected:
00093 int4 height;
00094 oid_t root;
00095 };
00096
00097 END_GIGABASE_NAMESPACE
00098
00099 #endif