Main Page   Class Hierarchy   Compound List   File List   Compound Members  

rtree.h

00001 //-< RTREE.H >-------------------------------------------------------*--------*
00002 // FastDB                    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 #include "rectangle.h"
00015 
00016 BEGIN_FASTDB_NAMESPACE
00017 
00018 #define MAX_RTREE_HEIGHT 8
00019 
00020 class dbAnyCursor;
00021 
00022 class dbRtreePage { 
00023   public:
00024     struct branch { 
00025         rectangle rect;
00026         oid_t     p;
00027     };
00028     
00029     enum { 
00030         card = (dbPageSize - 4) / sizeof(branch), // maximal number of branches at page
00031         min_fill = card/2        // minimal number of branches at non-root page
00032     };
00033 
00034     struct reinsert_list { 
00035         oid_t     chain;
00036         int       level;
00037         reinsert_list() { chain = 0; }
00038     };
00039 
00040     bool find(dbDatabase* db, dbSearchContext& sc, int level) const;
00041     static bool find(dbDatabase* db, oid_t rootId, dbSearchContext& sc, int level);
00042 
00043     static oid_t insert(dbDatabase* db, rectangle const& r, oid_t pageId, oid_t recordId, int level);
00044 
00045     static bool remove(dbDatabase* db, rectangle const& r, oid_t pageId, oid_t recordId, 
00046                        int level, reinsert_list& rlist);
00047 
00048     void cover(rectangle& r) const;
00049     static void cover(dbDatabase* db, oid_t pageId, rectangle& r);
00050 
00051     static oid_t add_branch(dbDatabase* db, oid_t pageId, branch const& br);
00052 
00053     void remove_branch(int i);
00054 
00055     static void purge(dbDatabase* db, oid_t pageId, int level);
00056 
00057     oid_t next_reinsert_page() const { 
00058         return b[card-1].p; 
00059     }
00060 
00061     static oid_t allocate(dbDatabase* db, oid_t recordId, rectangle const& r);
00062     static oid_t allocate(dbDatabase* db, oid_t rootId, oid_t p);
00063 
00064     int4   n; // number of branches at page
00065     branch b[card];
00066     };
00067 
00068 class FASTDB_DLL_ENTRY dbRtree {
00069   public: 
00070     enum searchOp { 
00071         EQUAL, 
00072         OVERLAPS, 
00073         SUPERSET,
00074         PROPER_SUPERSET, 
00075         SUBSET, 
00076         PROPER_SUBSET
00077     };
00078 
00079     static oid_t allocate(dbDatabase* db);
00080     static bool  find(dbDatabase* db, oid_t treeId, dbSearchContext& sc);
00081     static void  insert(dbDatabase* db, oid_t treeId, oid_t recordId, int offs);
00082     static void  insert(dbDatabase* db, oid_t treeId, oid_t recordId, rectangle const& r);
00083     static void  remove(dbDatabase* db, oid_t treeId, oid_t recordId, int offs);
00084     static void  purge(dbDatabase* db, oid_t treeId);
00085     static void  drop(dbDatabase* db, oid_t treeId);
00086 
00087   protected:
00088     int4   height;
00089     oid_t  root;
00090 };
00091 
00092 END_FASTDB_NAMESPACE
00093 
00094 #endif

Generated on Mon Oct 23 13:23:58 2006 for FastDB by doxygen1.2.18