index.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. * Markus Metz - file-based and memory-based R*-tree
  8. *
  9. * PURPOSE: Multidimensional index
  10. *
  11. * COPYRIGHT: (C) 2010 by the GRASS Development Team
  12. *
  13. * This program is free software under the GNU General Public
  14. * License (>=v2). Read the file COPYING that comes with GRASS
  15. * for details.
  16. *****************************************************************************/
  17. #ifndef _R_TREE_INDEX_H_
  18. #define _R_TREE_INDEX_H_
  19. #include "rtree.h"
  20. /* internal definitions and functions */
  21. /* PGSIZE is normally the natural page size of the machine */
  22. #define PGSIZE 512
  23. /* R*-tree: number of branches to be force-reinserted when adding a branch */
  24. #define FORCECARD 3
  25. #define NODETYPE(l, fd) ((l) == 0 ? 0 : ((fd) < 0 ? 1 : 2))
  26. struct RTree_ListNode
  27. {
  28. struct RTree_ListNode *next;
  29. struct RTree_Node *node;
  30. };
  31. struct RTree_ListFNode
  32. {
  33. struct RTree_ListFNode *next;
  34. off_t node_pos;
  35. };
  36. struct RTree_ListBranch
  37. {
  38. struct RTree_ListBranch *next;
  39. struct RTree_Branch b;
  40. int level;
  41. };
  42. /* functions */
  43. /* index.c */
  44. struct RTree_ListNode *RTreeNewListNode(void);
  45. void RTreeFreeListNode(struct RTree_ListNode *);
  46. void RTreeReInsertNode(struct RTree_Node *, struct RTree_ListNode **);
  47. void RTreeFreeListBranch(struct RTree_ListBranch *);
  48. /* indexm.c */
  49. int RTreeSearchM(struct RTree *, struct RTree_Rect *,
  50. SearchHitCallback *, void *);
  51. int RTreeInsertRectM(struct RTree_Rect *, union RTree_Child, int, struct RTree *);
  52. int RTreeDeleteRectM(struct RTree_Rect *, union RTree_Child, struct RTree *);
  53. int RTreeValidChildM(union RTree_Child *child);
  54. /* indexf.c */
  55. int RTreeSearchF(struct RTree *, struct RTree_Rect *,
  56. SearchHitCallback *, void *);
  57. int RTreeInsertRectF(struct RTree_Rect *, union RTree_Child, int, struct RTree *);
  58. int RTreeDeleteRectF(struct RTree_Rect *, union RTree_Child, struct RTree *);
  59. int RTreeValidChildF(union RTree_Child *);
  60. /* node.c */
  61. void RTreeNodeCover(struct RTree_Node *, struct RTree_Rect *, struct RTree *);
  62. int RTreeAddBranch(struct RTree_Branch *, struct RTree_Node *, struct RTree_Node **,
  63. struct RTree_ListBranch **, struct RTree_Rect *, char *, struct RTree *);
  64. int RTreePickBranch(struct RTree_Rect *, struct RTree_Node *, struct RTree *);
  65. void RTreeDisconnectBranch(struct RTree_Node *, int, struct RTree *);
  66. void RTreePrintNode(struct RTree_Node *, int, struct RTree *);
  67. void RTreeTabIn(int);
  68. void RTreeCopyBranch(struct RTree_Branch *, struct RTree_Branch *, struct RTree *);
  69. /* rect.c */
  70. void RTreeInitRect(struct RTree_Rect *, struct RTree *);
  71. void RTreeNullRect(struct RTree_Rect *, struct RTree *);
  72. RectReal RTreeRectArea(struct RTree_Rect *, struct RTree *);
  73. RectReal RTreeRectSphericalVolume(struct RTree_Rect *, struct RTree *);
  74. RectReal RTreeRectVolume(struct RTree_Rect *, struct RTree *);
  75. RectReal RTreeRectMargin(struct RTree_Rect *, struct RTree *);
  76. void RTreeCombineRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
  77. int RTreeExpandRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
  78. int RTreeCompareRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
  79. /*-----------------------------------------------------------------------------
  80. | Copy second rectangle to first rectangle.
  81. -----------------------------------------------------------------------------*/
  82. #define RTreeCopyRect(r1, r2, t) memcpy((r1)->boundary, (r2)->boundary, (t)->rectsize)
  83. /* split.c */
  84. void RTreeSplitNode(struct RTree_Node *, struct RTree_Branch *, struct RTree_Node *, struct RTree *);
  85. /* card.c */
  86. int RTreeSetNodeMax(int, struct RTree *);
  87. int RTreeSetLeafMax(int, struct RTree *);
  88. int RTreeGetNodeMax(struct RTree *);
  89. int RTreeGetLeafMax(struct RTree *);
  90. /* io.c */
  91. struct RTree_Node *RTreeGetNode(off_t, int, struct RTree *);
  92. void RTreeNodeChanged(struct RTree_Node *, off_t , struct RTree *);
  93. size_t RTreeRewriteNode(struct RTree_Node *, off_t, struct RTree *);
  94. void RTreeAddNodePos(off_t, int, struct RTree *);
  95. #endif /* _INDEX_ */