index.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /****************************************************************************
  2. * MODULE: R-Tree library
  3. *
  4. * AUTHOR(S): Antonin Guttman - original code
  5. * Daniel Green (green@superliminal.com) - major clean-up
  6. * and implementation of bounding spheres
  7. *
  8. * PURPOSE: Multidimensional index
  9. *
  10. * COPYRIGHT: (C) 2001 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *****************************************************************************/
  16. #ifndef _INDEX_
  17. #define _INDEX_
  18. /* PGSIZE is normally the natural page size of the machine */
  19. #define PGSIZE 512
  20. #define NUMDIMS 3 /* number of dimensions */
  21. /* typedef float RectReal; */
  22. typedef double RectReal;
  23. /*-----------------------------------------------------------------------------
  24. | Global definitions.
  25. -----------------------------------------------------------------------------*/
  26. #ifndef TRUE
  27. #define TRUE 1
  28. #endif
  29. #ifndef FALSE
  30. #define FALSE 0
  31. #endif
  32. #define NUMSIDES 2*NUMDIMS
  33. struct Rect
  34. {
  35. RectReal boundary[NUMSIDES]; /* xmin,ymin,...,xmax,ymax,... */
  36. };
  37. struct Node;
  38. struct Branch
  39. {
  40. struct Rect rect;
  41. struct Node *child;
  42. };
  43. /* max branching factor of a node */
  44. #define MAXCARD (int)((PGSIZE-(2*sizeof(int))) / sizeof(struct Branch))
  45. struct Node
  46. {
  47. int count;
  48. int level; /* 0 is leaf, others positive */
  49. struct Branch branch[MAXCARD];
  50. };
  51. struct ListNode
  52. {
  53. struct ListNode *next;
  54. struct Node *node;
  55. };
  56. /*
  57. * If passed to a tree search, this callback function will be called
  58. * with the ID of each data rect that overlaps the search rect
  59. * plus whatever user specific pointer was passed to the search.
  60. * It can terminate the search early by returning 0 in which case
  61. * the search will return the number of hits found up to that point.
  62. */
  63. typedef int (*SearchHitCallback) (int id, void *arg);
  64. extern int RTreeSearch(struct Node *, struct Rect *, SearchHitCallback,
  65. void *);
  66. extern int RTreeInsertRect(struct Rect *, int, struct Node **, int depth);
  67. extern int RTreeInsertRect1(struct Rect *, struct Node *, struct Node **, int depth);
  68. extern int RTreeDeleteRect(struct Rect *, int, struct Node **);
  69. extern int RTreeDeleteRect1(struct Rect *, struct Node *, struct Node **);
  70. extern struct Node *RTreeNewIndex(void);
  71. extern struct Node *RTreeNewNode(void);
  72. extern void RTreeInitNode(struct Node *);
  73. extern void RTreeFreeNode(struct Node *);
  74. extern void RTreeDestroyNode(struct Node *);
  75. extern void RTreePrintNode(struct Node *, int);
  76. extern void RTreeTabIn(int);
  77. extern struct Rect RTreeNodeCover(struct Node *);
  78. extern void RTreeInitRect(struct Rect *);
  79. extern struct Rect RTreeNullRect(void);
  80. extern RectReal RTreeRectArea(struct Rect *);
  81. extern RectReal RTreeRectSphericalVolume(struct Rect *R);
  82. extern RectReal RTreeRectVolume(struct Rect *R);
  83. extern struct Rect RTreeCombineRect(struct Rect *, struct Rect *);
  84. extern int RTreeOverlap(struct Rect *, struct Rect *);
  85. extern void RTreePrintRect(struct Rect *, int);
  86. extern int RTreeAddBranch(struct Branch *, struct Node *, struct Node **);
  87. extern int RTreePickBranch(struct Rect *, struct Node *);
  88. extern void RTreeDisconnectBranch(struct Node *, int);
  89. extern void RTreeSplitNode(struct Node *, struct Branch *, struct Node **);
  90. extern int RTreeSetNodeMax(int);
  91. extern int RTreeSetLeafMax(int);
  92. extern int RTreeGetNodeMax(void);
  93. extern int RTreeGetLeafMax(void);
  94. #endif /* _INDEX_ */