Main Page | Class Hierarchy | Class List | File List | Class Members

rtree.h

00001 //-< RTREE.H >-------------------------------------------------------*--------*
00002 // GigaBASE                  Version 1.0         (c) 1999  GARRET    *     ?  *
00003 // (Post Relational Database Management System)                      *   /\|  *
00004 //                                                                   *  /  \  *
00005 //                          Created:     22-Nov-2001  K.A. Knizhnik  * / [] \ *
00006 //                          Last update: 22-Nov-2001  K.A. Knizhnik  * GARRET *
00007 //-------------------------------------------------------------------*--------*
00008 // R-tree: spatial index
00009 //-------------------------------------------------------------------*--------*
00010 
00011 #ifndef __RTREE_H__
00012 #define __RTREE_H__
00013 
00014 BEGIN_GIGABASE_NAMESPACE
00015 
00016 #define MAX_RTREE_HEIGHT 8
00017 
00018 class dbAnyCursor;
00019 
00020 class dbRtreePage { 
00021   public:
00022     struct branch { 
00023         rectangle rect;
00024         oid_t     p;
00025     };
00026     
00027     enum { 
00028         card = (dbPageSize - 4) / sizeof(branch), // maximal number of branches at page
00029         min_fill = card/2        // minimal number of branches at non-root page
00030     };
00031 
00032     struct reinsert_list { 
00033         oid_t     chain;
00034         int       level;
00035         reinsert_list() { chain = 0; }
00036     };
00037 
00038     bool find(dbDatabase* db, dbSearchContext& sc, int level) const;
00039     static bool find(dbDatabase* db, oid_t rootId, dbSearchContext& sc, int level);
00040 
00041     oid_t insert(dbDatabase* db, rectangle const& r, oid_t recordId, int level);
00042     static oid_t insert(dbDatabase* db, rectangle const& r, oid_t pageId, oid_t recordId, int level);
00043 
00044     bool remove(dbDatabase* db, rectangle const& r, oid_t recordId, int level,
00045                 reinsert_list& rlist);
00046     static bool remove(dbDatabase* db, rectangle const& r,  oid_t pageId, oid_t recordId, 
00047                        int level, reinsert_list& rlist);
00048 
00049     void cover(rectangle& r) const;
00050     static void cover(dbDatabase* db, oid_t pageId, rectangle& r);
00051 
00052     oid_t split_page(dbDatabase* db, branch const& br);
00053 
00054     oid_t add_branch(dbDatabase* db, branch const& br) { 
00055         if (n < card) { 
00056             b[n++] = br;
00057             return 0;
00058         } else { 
00059             return split_page(db, br);
00060         }
00061     }
00062     void remove_branch(int i);
00063 
00064     static void purge(dbDatabase* db, oid_t pageId, int level);
00065 
00066     oid_t next_reinsert_page() const { 
00067         return b[card-1].p; 
00068     }
00069 
00070     static oid_t allocate(dbDatabase* db, oid_t recordId, rectangle const& r);
00071     static oid_t allocate(dbDatabase* db, oid_t rootId, oid_t p);
00072 
00073     int4   n; // number of branches at page
00074     branch b[card];
00075 };
00076 
00077 class GIGABASE_DLL_ENTRY dbRtree :  public dbRecord {
00078     friend class dbRtreeIterator;
00079   public: 
00080     enum searchOp { 
00081         EQUAL, 
00082         OVERLAPS, 
00083         SUPERSET,
00084         PROPER_SUPERSET, 
00085         SUBSET, 
00086         PROPER_SUBSET
00087     };
00088 
00089     static oid_t allocate(dbDatabase* db);
00090     static bool  find(dbDatabase* db, oid_t treeId, dbSearchContext& sc);
00091     static void  insert(dbDatabase* db, oid_t treeId, oid_t recordId, int offs);
00092     static void  insert(dbDatabase* db, oid_t treeId, oid_t recordId, rectangle const& r);
00093     static void  remove(dbDatabase* db, oid_t treeId, oid_t recordId, int offs);
00094     static void  purge(dbDatabase* db, oid_t treeId);
00095     static void  drop(dbDatabase* db, oid_t treeId);
00096 
00097   protected:
00098     int4   height;
00099     oid_t  root;
00100 };
00101 
00102 class GIGABASE_DLL_ENTRY dbRtreeIterator : public dbAbstractIterator { 
00103   public:
00104     void init(dbDatabase* db, oid_t treeId, dbSearchContext& sc);
00105     
00106     oid_t next();
00107     oid_t prev();
00108     oid_t first();
00109     oid_t last();
00110     
00111   private:
00112     oid_t gotoLastItem(int sp, oid_t pageId);
00113     oid_t gotoFirstItem(int sp, oid_t pageId);
00114     
00115     dbDatabase*     db;
00116     rectangle       r;
00117     int             height;
00118     oid_t           treeId;
00119     dbSearchContext sc;
00120     oid_t           pageStack[MAX_RTREE_HEIGHT];
00121     int             posStack[MAX_RTREE_HEIGHT];
00122 };
00123 
00124 END_GIGABASE_NAMESPACE
00125 
00126 #endif

Generated on Thu Nov 24 23:14:30 2005 for GigaBASE by doxygen 1.3.5