Rtree 报告
这周的数据库实现课的作业是了解Rtree的概念,并尝试去=使用这样一个数据结构,然后我从一个开源网站
/sources/sources.htm#C%20&%20C++%20Code上找了一份c/c++版本的RTree代码,并对代码进行了一些实验,了解了RTree的一些基本情况与使用方法。
RTree作为一种空间索引主要具有以下一些特性:
diantai(1)R-Tree是n 叉树,n称为R-Tree的扇(fan)。
(2)每个结点对应一个矩形。
(3)叶子结点上包含了小于等于n 的对象,其对应的矩为所有对象的外包矩形。
(4)非叶结点的矩形为所有子结点矩形的外包矩形。
R-Tree的定义很宽泛,同一套数据构造R-Tree,不同方可以得到差别很大的结构。因此具有两标准:
(1)位置上相邻的结点尽量在树中聚集为一个父结点。
(2)同一层中各兄弟结点相交部分比例尽量小。
R树是一种用于处理多维数据的数据结构,用来访问二维或者更高维区域对象组成的空间数据.R树是一棵平衡树。树上有两类结点:叶子结点和非叶子结点。每一个结点由若干个索引项构成。
R-Tree算法描述
算法描述如下:
对象数为n,扇区大小定为fan。
(1)估计叶结点数k=n/fan。
(2)将所有几何对象按照其矩形外框中心点的x值排序。
(3)将排序后的对象分组,每组大小为 *fan,最后一组可能不满员。
(4)上述每一分组内按照几何对象矩形外框中心点的y值排序。
(5)排序后每一分组内再分组,每组大小为fan。
(6)每一小组成为叶结点,叶子结点数为nn。
(7)N=nn,返回1。
R-Tree的实现
在这里R-Tree的实现主要包括这样一些操作:
/// \class RTree
/// Implementation of RTree, a multidimensional bounding rectangle tree.
/// Example usage: For a 3-dimensional tree u RTree<Object*, float, 3> myTree;
///
/// This modified, templated C++ version by Greg Douglas at Auran ()
///
/// DATATYPE Referenced data, should be int, void*, obj* etc. no larger than sizeof<void*> and simple type
/
// ELEMTYPE Type of element such as int or float
/// NUMDIMS Number of dimensions such as 2 or 3
/// ELEMTYPEREAL Type of element that allows fractional and large values such as float or double, for u in volume calcs
///
/// NOTES: Inrting and removing data requires the knowledge of its constant Minimal Bounding Rectangle.
/// This version us new/delete for nodes, I recommend using a fixed size allocator for efficiency.
/// Instead of using a callback function for returned results, I recommend and efficient pre-sized, grow-only memory
/// array similar to MFC CArray or STL Vector for returning arch query result.
///
template<class DATATYPE, class注册会计师资格证 ELEMTYPE, int NUMDIMS,
class ELEMTYPEREAL = ELEMTYPE, int TMAXNODES = 8, int TMINNODES = TMAXNODES / 2>
class RTree
{
protected:
struct Node; // Fwd decl. Ud by other internal structs and iterator
public:
// The constant must be declared after Branch and before Node struct
// Stuck up here for MSVC 6 compiler. NSVC 2003 is much happier.
enum
{
MAXNODES = TMAXNODES, ///< Max elements in node
MINNODES = TMINNODES, ///< Min elements in node
};
public:
沪江听力酷 RTree();
virtual ~RTree();
/// Inrt entry
/// \param a_min Min of bounding rect
/// \param a_max Max of bounding rect
/// \param a_dataId Positive Id of data. Maybe zero, but negative numbers not allowed.
void Inrt(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], const DATATYPE& a_dataId);
小考分数查询
/// Remove entry
/// \param a_min Min of bounding rect
/// \param a_max Max of bounding rect
/// \param a_dataId Positive Id of data. Maybe zero, but negative numbers not allowed.
void Remove(const ELEMTYPE a_min[深圳翻译公司NUMDIMS], const ELEMTYPE a_max[NUMDIMS], const DATATYPE& a_dataId);
/// Find all within arch rectangle英语四级万能作文
/// \param a_min Min of arch bounding rect
儿童口才watermelon的意思 /// \param a_max Max of arch bounding rect
bls /// \param a_archResult Search result array. Caller should t grow size. Function will ret, not append to array.
/// \param a_resultCallback Callback function to return result. Callback should return 'true' to continue arching
/// \param a_context Ur context to pass as parameter to a_resultCallback
/// \return Returns the number of entries found
int Search(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], bool __cdecl a_resultCallback(DATATYPE a_data, void* a_context), void* a_context);
/// Remove all entries from tree
void RemoveAll();
/// Count the data elements in this container. This is slow as no internal counter is maintained.
int Count();领先教育
/// Load tree contents from file
bool Load(const char* a_fileName);
/// Load tree contents from stream
bool Load(RTFileStream& a_stream);
/// Save tree contents to file
bool Save(const char* a_fileName);
/// Save tree contents to stream
bool Save(RTFileStream& a_stream);
/// Iterator is not remove safe.
class Iterator
{
private:
enum { MAX_STACK = 32 }; // Max stack size. Allows almost n^32 where n is number of branches in node
struct StackElement