| 1 |
/************************************************************************* |
| 2 |
* Copyright (c) 2011 AT&T Intellectual Property |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* https://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: Details at https://graphviz.org |
| 9 |
*************************************************************************/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#ifdef __cplusplus |
| 14 |
extern "C" { |
| 15 |
#endif |
| 16 |
|
| 17 |
/* |
| 18 |
* this library is derived from an archived home directory of Antonin Guttman |
| 19 |
* that implemented the ideas described in |
| 20 |
* "R-trees: a dynamic index structure for spatial searching" |
| 21 |
* Antonin Guttman, University of California, Berkeley |
| 22 |
* SIGMOD '84 Proceedings of the 1984 ACM SIGMOD international conference on Management of data |
| 23 |
* ISBN:0-89791-128-8 |
| 24 |
* http://dx.doi.org/10.1145/602259.602266 |
| 25 |
* this copy of the code was retrieved from |
| 26 |
* http://web.archive.org/web/20030210112132/http://www.es.ucsc.edu/~tonig/rtrees/ |
| 27 |
* we are using the quadratic node splitter only |
| 28 |
* we made a few cosmetic changes to fit our needs |
| 29 |
* per Antonin there is no copyright |
| 30 |
*/ |
| 31 |
|
| 32 |
/*----------------------------------------------------------------------------- |
| 33 |
| Global definitions. |
| 34 |
-----------------------------------------------------------------------------*/ |
| 35 |
|
| 36 |
#ifndef NUMDIMS |
| 37 |
#define NUMDIMS 2 |
| 38 |
#endif /*NUMDIMS*/ |
| 39 |
/* #define NDEBUG */ |
| 40 |
#define NUMSIDES 2*NUMDIMS |
| 41 |
/* branching factor of a node */ |
| 42 |
/* #define NODECARD (int)((PGSIZE-(2*sizeof(int)))/sizeof(struct Branch))*/ |
| 43 |
#define NODECARD 64 |
| 44 |
typedef struct RTree RTree_t; |
| 45 |
|
| 46 |
#include <label/rectangle.h> |
| 47 |
#include <label/node.h> |
| 48 |
#include <label/split.q.h> |
| 49 |
|
| 50 |
#define CX(i) (i) |
| 51 |
#define NX(i) (i+NUMDIMS) |
| 52 |
#define CY(i) (i+1) |
| 53 |
#define NY(i) (i+1+NUMDIMS) |
| 54 |
|
| 55 |
typedef struct Leaf { |
| 56 |
Rect_t rect; |
| 57 |
void *data; |
| 58 |
} Leaf_t; |
| 59 |
|
| 60 |
typedef struct LeafList { |
| 61 |
struct LeafList *next; |
| 62 |
Leaf_t *leaf; |
| 63 |
} LeafList_t; |
| 64 |
|
| 65 |
struct RTree { |
| 66 |
Node_t *root; |
| 67 |
|
| 68 |
SplitQ_t split; |
| 69 |
}; |
| 70 |
|
| 71 |
RTree_t *RTreeOpen(void); |
| 72 |
void RTreeClose(RTree_t *rtp); |
| 73 |
Node_t *RTreeNewIndex(void); |
| 74 |
LeafList_t *RTreeSearch(RTree_t *, Node_t *, Rect_t); |
| 75 |
int RTreeInsert(RTree_t *, Rect_t, void *, Node_t **); |
| 76 |
|
| 77 |
void RTreeLeafListFree(LeafList_t * llp); |
| 78 |
|
| 79 |
#ifdef RTDEBUG |
| 80 |
void PrintNode(Node_t *); |
| 81 |
#endif |
| 82 |
|
| 83 |
#ifdef __cplusplus |
| 84 |
} |
| 85 |
#endif |