[GRASS-SVN] r51671 - grass/trunk/lib/vector/rtree
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 23 08:14:07 EDT 2012
Author: mmetz
Date: 2012-05-23 05:14:06 -0700 (Wed, 23 May 2012)
New Revision: 51671
Modified:
grass/trunk/lib/vector/rtree/Makefile
grass/trunk/lib/vector/rtree/card.c
grass/trunk/lib/vector/rtree/card.h
grass/trunk/lib/vector/rtree/index.h
grass/trunk/lib/vector/rtree/rtree.h
Log:
rtreelib: clean up headers
Modified: grass/trunk/lib/vector/rtree/Makefile
===================================================================
--- grass/trunk/lib/vector/rtree/Makefile 2012-05-23 12:13:19 UTC (rev 51670)
+++ grass/trunk/lib/vector/rtree/Makefile 2012-05-23 12:14:06 UTC (rev 51671)
@@ -4,9 +4,7 @@
include $(MODULE_TOPDIR)/include/Make/Lib.make
-RTLINC = $(ARCH_INCDIR)/rtree
-HEADERS := $(RTLINC)/card.h $(RTLINC)/index.h $(RTLINC)/split.h \
- $(ARCH_INCDIR)/rtree.h
+HEADERS := $(ARCH_INCDIR)/rtree.h
default: headers
$(MAKE) lib
Modified: grass/trunk/lib/vector/rtree/card.c
===================================================================
--- grass/trunk/lib/vector/rtree/card.c 2012-05-23 12:13:19 UTC (rev 51670)
+++ grass/trunk/lib/vector/rtree/card.c 2012-05-23 12:14:06 UTC (rev 51671)
@@ -19,9 +19,6 @@
#include "index.h"
#include "card.h"
-int NODECARD = MAXCARD;
-int LEAFCARD = MAXCARD;
-
static int set_max(int *which, int new_max)
{
if (2 > new_max || new_max > MAXCARD)
Modified: grass/trunk/lib/vector/rtree/card.h
===================================================================
--- grass/trunk/lib/vector/rtree/card.h 2012-05-23 12:13:19 UTC (rev 51670)
+++ grass/trunk/lib/vector/rtree/card.h 2012-05-23 12:14:06 UTC (rev 51671)
@@ -19,9 +19,6 @@
#ifndef __CARD__
#define __CARD__
-extern int NODECARD;
-extern int LEAFCARD;
-
/* balance criteria for node splitting */
/* NOTE: can be changed if needed but
* must be >= 2 and <= (t)->[nodecard|leafcard] / 2 */
Modified: grass/trunk/lib/vector/rtree/index.h
===================================================================
--- grass/trunk/lib/vector/rtree/index.h 2012-05-23 12:13:19 UTC (rev 51670)
+++ grass/trunk/lib/vector/rtree/index.h 2012-05-23 12:14:06 UTC (rev 51671)
@@ -15,146 +15,22 @@
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
*****************************************************************************/
-#ifndef _INDEX_
-#define _INDEX_
+#ifndef _R_TREE_INDEX_H_
+#define _R_TREE_INDEX_H_
-#include <stdio.h>
-#include <sys/types.h>
-#include <grass/config.h>
+#include "rtree.h"
+/* internal definitions and functions */
+
/* PGSIZE is normally the natural page size of the machine */
#define PGSIZE 512
-#define NUMDIMS 3 /* maximum number of dimensions */
-typedef double RectReal;
-
-/*-----------------------------------------------------------------------------
-| Global definitions.
------------------------------------------------------------------------------*/
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-#define NUMSIDES 2*NUMDIMS
-
-/* max branching factor of a node */
-/* was (PGSIZE-(2 * sizeof(int))) / sizeof(struct Branch)
- * this is LFS dependent, not good
- * on 32 bit without LFS this is 9.69
- * on 32 bit with LFS and on 64 bit this is 9 */
-#define MAXCARD 9
-
/* R*-tree: number of branches to be force-reinserted when adding a branch */
#define FORCECARD 3
-/* maximum no of levels = tree depth */
-#define MAXLEVEL 20 /* 8^MAXLEVEL items are guaranteed to fit into the tree */
-
#define NODETYPE(l, fd) ((l) == 0 ? 0 : ((fd) < 0 ? 1 : 2))
-struct RTree_Rect
-{
- RectReal boundary[NUMSIDES]; /* xmin,ymin,...,xmax,ymax,... */
-};
-struct RTree_Node; /* node for spatial index */
-
-union RTree_Child
-{
- int id; /* child id */
- struct RTree_Node *ptr; /* pointer to child node */
- off_t pos; /* position of child node in file */
-};
-
-struct RTree_Branch /* branch for spatial index */
-{
- struct RTree_Rect rect;
- union RTree_Child child;
-};
-
-struct RTree_Node /* node for spatial index */
-{
- int count; /* number of branches */
- int level; /* 0 is leaf, others positive */
- struct RTree_Branch branch[MAXCARD];
-};
-
-/*
- * If passed to a tree search, this callback function will be called
- * with the ID of each data rect that overlaps the search rect
- * plus whatever user specific pointer was passed to the search.
- * It can terminate the search early by returning 0 in which case
- * the search will return the number of hits found up to that point.
- */
-typedef int SearchHitCallback(int id, struct RTree_Rect rect, void *arg);
-
-struct RTree;
-
-typedef int rt_search_fn(struct RTree *, struct RTree_Rect *,
- SearchHitCallback *, void *);
-typedef int rt_insert_fn(struct RTree_Rect *, union RTree_Child, int, struct RTree *);
-typedef int rt_delete_fn(struct RTree_Rect *, union RTree_Child, struct RTree *);
-typedef int rt_valid_child_fn(union RTree_Child *);
-
-struct RTree
-{
- /* RTree setup info */
- int fd; /* file descriptor */
- unsigned char ndims; /* number of dimensions */
- unsigned char nsides; /* number of sides = 2 * ndims */
- int nodesize; /* node size in bytes */
- int branchsize; /* branch size in bytes */
- int rectsize; /* rectangle size in bytes */
-
- /* RTree info, useful to calculate space requirements */
- int n_nodes; /* number of nodes */
- int n_leafs; /* number of data items (level 0 leafs) */
- int rootlevel; /* root level = tree depth */
-
- /* settings for RTree building */
- int nodecard; /* max number of childs in node */
- int leafcard; /* max number of childs in leaf */
- int min_node_fill; /* balance criteria for node removal */
- int min_leaf_fill; /* balance criteria for leaf removal */
- int minfill_node_split; /* balance criteria for splitting */
- int minfill_leaf_split; /* balance criteria for splitting */
-
- /* free node positions for recycling */
- struct _recycle {
- int avail; /* number of available positions */
- int alloc; /* number of allcoated positions in *pos */
- off_t *pos; /* array of available positions */
- } free_nodes;
-
- /* node buffer for file-based index, three nodes per level
- * more than three nodes per level would require too complex cache management */
- struct NodeBuffer
- {
- struct RTree_Node n; /* buffered node */
- off_t pos; /* file position of buffered node */
- char dirty; /* node in buffer was modified */
- } nb[MAXLEVEL][3];
-
- /* usage order of buffered nodes per level
- * used[level][0] = most recently used
- * used[level][2] = least recently used */
- char used[MAXLEVEL][3];
-
- /* insert, delete, search */
- rt_insert_fn *insert_rect;
- rt_delete_fn *delete_rect;
- rt_search_fn *search_rect;
- rt_valid_child_fn *valid_child;
-
- struct RTree_Node *root; /* pointer to root node */
-
- off_t rootpos; /* root node position in file */
-};
-
struct RTree_ListNode
{
struct RTree_ListNode *next;
@@ -175,67 +51,60 @@
};
/* index.c */
-extern int RTreeSearch(struct RTree *, struct RTree_Rect *, SearchHitCallback *,
- void *);
-extern int RTreeInsertRect(struct RTree_Rect *, int, struct RTree *);
-extern int RTreeDeleteRect(struct RTree_Rect *, int, struct RTree *);
-extern struct RTree *RTreeNewIndex(int, off_t, int);
-extern void RTreeFreeIndex(struct RTree *);
-extern struct RTree_ListNode *RTreeNewListNode(void);
-extern void RTreeFreeListNode(struct RTree_ListNode *);
-extern void RTreeReInsertNode(struct RTree_Node *, struct RTree_ListNode **);
-extern void RTreeFreeListBranch(struct RTree_ListBranch *);
+struct RTree_ListNode *RTreeNewListNode(void);
+void RTreeFreeListNode(struct RTree_ListNode *);
+void RTreeReInsertNode(struct RTree_Node *, struct RTree_ListNode **);
+void RTreeFreeListBranch(struct RTree_ListBranch *);
+
/* indexm.c */
-extern int RTreeSearchM(struct RTree *, struct RTree_Rect *, SearchHitCallback *,
+int RTreeSearchM(struct RTree *, struct RTree_Rect *, SearchHitCallback *,
void *);
-extern int RTreeInsertRectM(struct RTree_Rect *, union RTree_Child, int, struct RTree *);
-extern int RTreeDeleteRectM(struct RTree_Rect *, union RTree_Child, struct RTree *);
-extern int RTreeValidChildM(union RTree_Child *child);
+int RTreeInsertRectM(struct RTree_Rect *, union RTree_Child, int, struct RTree *);
+int RTreeDeleteRectM(struct RTree_Rect *, union RTree_Child, struct RTree *);
+int RTreeValidChildM(union RTree_Child *child);
+
/* indexf.c */
-extern int RTreeSearchF(struct RTree *, struct RTree_Rect *, SearchHitCallback *,
+int RTreeSearchF(struct RTree *, struct RTree_Rect *, SearchHitCallback *,
void *);
-extern int RTreeInsertRectF(struct RTree_Rect *, union RTree_Child, int, struct RTree *);
-extern int RTreeDeleteRectF(struct RTree_Rect *, union RTree_Child, struct RTree *);
-extern int RTreeValidChildF(union RTree_Child *child);
+int RTreeInsertRectF(struct RTree_Rect *, union RTree_Child, int, struct RTree *);
+int RTreeDeleteRectF(struct RTree_Rect *, union RTree_Child, struct RTree *);
+int RTreeValidChildF(union RTree_Child *child);
+
/* node.c */
-extern struct RTree_Node *RTreeNewNode(struct RTree *, int);
-extern void RTreeInitNode(struct RTree_Node *, int);
-extern void RTreeFreeNode(struct RTree_Node *);
-extern void RTreeDestroyNode(struct RTree_Node *, int);
-extern struct RTree_Rect RTreeNodeCover(struct RTree_Node *, struct RTree *);
-extern int RTreeAddBranch(struct RTree_Branch *, struct RTree_Node *, struct RTree_Node **,
+struct RTree_Rect RTreeNodeCover(struct RTree_Node *, struct RTree *);
+int RTreeAddBranch(struct RTree_Branch *, struct RTree_Node *, struct RTree_Node **,
struct RTree_ListBranch **, struct RTree_Rect *, int *, struct RTree *);
-extern int RTreePickBranch(struct RTree_Rect *, struct RTree_Node *, struct RTree *);
-extern void RTreeDisconnectBranch(struct RTree_Node *, int, struct RTree *);
-extern void RTreePrintNode(struct RTree_Node *, int, struct RTree *);
-extern void RTreeTabIn(int);
+int RTreePickBranch(struct RTree_Rect *, struct RTree_Node *, struct RTree *);
+void RTreeDisconnectBranch(struct RTree_Node *, int, struct RTree *);
+void RTreePrintNode(struct RTree_Node *, int, struct RTree *);
+void RTreeTabIn(int);
+
/* rect.c */
-extern void RTreeInitRect(struct RTree_Rect *);
-extern struct RTree_Rect RTreeNullRect(void);
-extern RectReal RTreeRectArea(struct RTree_Rect *, struct RTree *);
-extern RectReal RTreeRectSphericalVolume(struct RTree_Rect *, struct RTree *);
-extern RectReal RTreeRectVolume(struct RTree_Rect *, struct RTree *);
-extern RectReal RTreeRectMargin(struct RTree_Rect *, struct RTree *);
-extern struct RTree_Rect RTreeCombineRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
-extern int RTreeCompareRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
-extern int RTreeOverlap(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
-extern void RTreePrintRect(struct RTree_Rect *, int);
+void RTreeInitRect(struct RTree_Rect *);
+struct RTree_Rect RTreeNullRect(void);
+RectReal RTreeRectArea(struct RTree_Rect *, struct RTree *);
+RectReal RTreeRectSphericalVolume(struct RTree_Rect *, struct RTree *);
+RectReal RTreeRectVolume(struct RTree_Rect *, struct RTree *);
+RectReal RTreeRectMargin(struct RTree_Rect *, struct RTree *);
+struct RTree_Rect RTreeCombineRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
+int RTreeCompareRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
+int RTreeOverlap(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
+void RTreePrintRect(struct RTree_Rect *, int);
+
/* split.c */
-extern void RTreeSplitNode(struct RTree_Node *, struct RTree_Branch *, struct RTree_Node *, struct RTree *);
+void RTreeSplitNode(struct RTree_Node *, struct RTree_Branch *, struct RTree_Node *, struct RTree *);
+
/* card.c */
-extern int RTreeSetNodeMax(int, struct RTree *);
-extern int RTreeSetLeafMax(int, struct RTree *);
-extern int RTreeGetNodeMax(struct RTree *);
-extern int RTreeGetLeafMax(struct RTree *);
+int RTreeSetNodeMax(int, struct RTree *);
+int RTreeSetLeafMax(int, struct RTree *);
+int RTreeGetNodeMax(struct RTree *);
+int RTreeGetLeafMax(struct RTree *);
+
/* fileio.c */
-extern void RTreeGetNode(struct RTree_Node *, off_t, int, struct RTree *);
-extern size_t RTreeReadNode(struct RTree_Node *, off_t, struct RTree *);
-extern void RTreePutNode(struct RTree_Node *, off_t, struct RTree *);
-extern size_t RTreeWriteNode(struct RTree_Node *, struct RTree *);
-extern size_t RTreeRewriteNode(struct RTree_Node *, off_t, struct RTree *);
-extern void RTreeUpdateRect(struct RTree_Rect *, struct RTree_Node *, off_t, int, struct RTree *);
-extern void RTreeAddNodePos(off_t, int, struct RTree *);
-extern off_t RTreeGetNodePos(struct RTree *);
-extern void RTreeFlushBuffer(struct RTree *);
+void RTreeGetNode(struct RTree_Node *, off_t, int, struct RTree *);
+void RTreePutNode(struct RTree_Node *, off_t, struct RTree *);
+size_t RTreeRewriteNode(struct RTree_Node *, off_t, struct RTree *);
+void RTreeUpdateRect(struct RTree_Rect *, struct RTree_Node *, off_t, int, struct RTree *);
+void RTreeAddNodePos(off_t, int, struct RTree *);
#endif /* _INDEX_ */
Modified: grass/trunk/lib/vector/rtree/rtree.h
===================================================================
--- grass/trunk/lib/vector/rtree/rtree.h 2012-05-23 12:13:19 UTC (rev 51670)
+++ grass/trunk/lib/vector/rtree/rtree.h 2012-05-23 12:14:06 UTC (rev 51671)
@@ -9,13 +9,167 @@
*
* PURPOSE: Multidimensional index
*
-* COPYRIGHT: (C) 2010 by the GRASS Development Team
+* COPYRIGHT: (C) 2010-2012 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
*****************************************************************************/
+#ifndef _R_TREE_H_
+#define _R_TREE_H_
-#include <grass/rtree/card.h>
-#include <grass/rtree/index.h>
-#include <grass/rtree/split.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <grass/config.h> /* needed for LFS */
+
+
+#define NUMDIMS 3 /* maximum number of dimensions */
+
+typedef double RectReal;
+
+/*-----------------------------------------------------------------------------
+| Global definitions.
+-----------------------------------------------------------------------------*/
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#define NUMSIDES 2*NUMDIMS
+
+/* max branching factor of a node */
+/* was (PGSIZE-(2 * sizeof(int))) / sizeof(struct Branch)
+ * this is LFS dependent, not good
+ * on 32 bit without LFS this is 9.69
+ * on 32 bit with LFS and on 64 bit this is 9 */
+#define MAXCARD 9
+#define NODECARD MAXCARD
+#define LEAFCARD MAXCARD
+
+
+/* maximum no of levels = tree depth */
+#define MAXLEVEL 20 /* 8^MAXLEVEL items are guaranteed to fit into the tree */
+
+struct RTree_Rect
+{
+ RectReal boundary[NUMSIDES]; /* xmin,ymin,...,xmax,ymax,... */
+};
+
+struct RTree_Node; /* node for spatial index */
+
+union RTree_Child
+{
+ int id; /* child id */
+ struct RTree_Node *ptr; /* pointer to child node */
+ off_t pos; /* position of child node in file */
+};
+
+struct RTree_Branch /* branch for spatial index */
+{
+ struct RTree_Rect rect;
+ union RTree_Child child;
+};
+
+struct RTree_Node /* node for spatial index */
+{
+ int count; /* number of branches */
+ int level; /* 0 is leaf, others positive */
+ struct RTree_Branch branch[MAXCARD];
+};
+
+/*
+ * If passed to a tree search, this callback function will be called
+ * with the ID of each data rect that overlaps the search rect
+ * plus whatever user specific pointer was passed to the search.
+ * It can terminate the search early by returning 0 in which case
+ * the search will return the number of hits found up to that point.
+ */
+typedef int SearchHitCallback(int id, struct RTree_Rect rect, void *arg);
+
+struct RTree;
+
+typedef int rt_search_fn(struct RTree *, struct RTree_Rect *,
+ SearchHitCallback *, void *);
+typedef int rt_insert_fn(struct RTree_Rect *, union RTree_Child, int, struct RTree *);
+typedef int rt_delete_fn(struct RTree_Rect *, union RTree_Child, struct RTree *);
+typedef int rt_valid_child_fn(union RTree_Child *);
+
+struct RTree
+{
+ /* RTree setup info */
+ int fd; /* file descriptor */
+ unsigned char ndims; /* number of dimensions */
+ unsigned char nsides; /* number of sides = 2 * ndims */
+ int nodesize; /* node size in bytes */
+ int branchsize; /* branch size in bytes */
+ int rectsize; /* rectangle size in bytes */
+
+ /* RTree info, useful to calculate space requirements */
+ int n_nodes; /* number of nodes */
+ int n_leafs; /* number of data items (level 0 leafs) */
+ int rootlevel; /* root level = tree depth */
+
+ /* settings for RTree building */
+ int nodecard; /* max number of childs in node */
+ int leafcard; /* max number of childs in leaf */
+ int min_node_fill; /* balance criteria for node removal */
+ int min_leaf_fill; /* balance criteria for leaf removal */
+ int minfill_node_split; /* balance criteria for splitting */
+ int minfill_leaf_split; /* balance criteria for splitting */
+
+ /* free node positions for recycling */
+ struct _recycle {
+ int avail; /* number of available positions */
+ int alloc; /* number of allcoated positions in *pos */
+ off_t *pos; /* array of available positions */
+ } free_nodes;
+
+ /* node buffer for file-based index, three nodes per level
+ * more than three nodes per level would require too complex cache management */
+ struct NodeBuffer
+ {
+ struct RTree_Node n; /* buffered node */
+ off_t pos; /* file position of buffered node */
+ char dirty; /* node in buffer was modified */
+ } nb[MAXLEVEL][3];
+
+ /* usage order of buffered nodes per level
+ * used[level][0] = most recently used
+ * used[level][2] = least recently used */
+ char used[MAXLEVEL][3];
+
+ /* insert, delete, search */
+ rt_insert_fn *insert_rect;
+ rt_delete_fn *delete_rect;
+ rt_search_fn *search_rect;
+ rt_valid_child_fn *valid_child;
+
+ struct RTree_Node *root; /* pointer to root node */
+
+ off_t rootpos; /* root node position in file */
+};
+
+/* RTree main functions */
+int RTreeSearch(struct RTree *, struct RTree_Rect *, SearchHitCallback *,
+ void *);
+int RTreeInsertRect(struct RTree_Rect *, int, struct RTree *);
+int RTreeDeleteRect(struct RTree_Rect *, int, struct RTree *);
+struct RTree *RTreeNewIndex(int, off_t, int);
+void RTreeFreeIndex(struct RTree *);
+
+/* RTree node management */
+struct RTree_Node *RTreeNewNode(struct RTree *, int);
+void RTreeInitNode(struct RTree_Node *, int);
+void RTreeFreeNode(struct RTree_Node *);
+void RTreeDestroyNode(struct RTree_Node *, int);
+
+/* RTree IO */
+size_t RTreeReadNode(struct RTree_Node *, off_t, struct RTree *);
+size_t RTreeWriteNode(struct RTree_Node *, struct RTree *);
+off_t RTreeGetNodePos(struct RTree *);
+void RTreeFlushBuffer(struct RTree *);
+
+#endif
More information about the grass-commit
mailing list