36 for (
size_t i = 0; i <
NODECARD; i++)
55 fprintf(stderr,
"node");
57 fprintf(stderr,
" LEAF");
58 else if (n->
level > 0)
59 fprintf(stderr,
" NONLEAF");
61 fprintf(stderr,
" TYPE=?");
62 fprintf(stderr,
" level=%d count=%d child address=%p\n",
65 for (
size_t i = 0; i <
NODECARD; i++) {
73 fprintf(stderr,
" child[%d] X%X\n", i, (
unsigned int) b->
child);
74 PrintRect(&(b->
rect));
88 for (
size_t i = 0; i <
NODECARD; i++)
107 uint64_t bestIncr = 0;
108 uint64_t bestArea = 0;
110 bool bestSet =
false;
113 for (
int i = 0; i <
NODECARD; i++) {
118 uint64_t increase =
RectArea(&rect) - area;
119 if (!bestSet || increase < bestIncr) {
124 }
else if (increase == bestIncr && area < bestArea) {
131 "i=%d area before=%" PRIu64
" area after=%" PRIu64
" increase=%" PRIu64
132 "\n", i, area, area + increase, increase);
137 fprintf(stderr,
"\tpicked %d\n", best);
174 assert(n && i >= 0 && i <
NODECARD);
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
Node_t * RTreeNewNode(void)
int AddBranch(RTree_t *rtp, Branch_t *b, Node_t *n, Node_t **new)
Rect_t NodeCover(Node_t *n)
int PickBranch(Rect_t *r, Node_t *n)
void InitBranch(Branch_t *b)
void DisconBranch(Node_t *n, int i)
void PrintBranch(int, Branch_t *)
Rect_t CombineRect(const Rect_t *r, const Rect_t *rr)
uint64_t RectArea(const Rect_t *r)
void SplitNode(RTree_t *rtp, Node_t *n, Branch_t *b, Node_t **nn)
struct Branch branch[NODECARD]