21 #include <sys/types.h>
35 if (
t->free_nodes.avail >=
t->free_nodes.alloc) {
38 t->free_nodes.alloc += 100;
39 size =
t->free_nodes.alloc *
sizeof(off_t);
40 t->free_nodes.pos = (off_t *)realloc((
void *)
t->free_nodes.pos, size);
43 t->free_nodes.pos[
t->free_nodes.avail++] = pos;
52 which =
t->used[level][i];
53 t->nb[level][which].pos = -1;
54 t->nb[level][which].dirty = 0;
61 t->nb[level][
t->used[level][i + 1]].pos != -1) {
62 t->used[level][i] =
t->used[level][i + 1];
66 t->used[level][i] = which;
73 if (
t->free_nodes.avail > 0) {
74 t->free_nodes.avail--;
75 return lseek(
t->fd,
t->free_nodes.pos[
t->free_nodes.avail], SEEK_SET);
78 return lseek(
t->fd, 0, SEEK_END);
87 size += read(
t->fd,
b->rect.boundary,
t->rectsize);
99 lseek(
t->fd, nodepos, SEEK_SET);
100 size += read(
t->fd, &(n->
count),
sizeof(
int));
101 size += read(
t->fd, &(n->
level),
sizeof(
int));
103 for (i = 0; i <
MAXCARD; i++) {
116 while (
t->nb[
level][
t->used[
level][i]].pos != nodepos &&
120 which =
t->used[
level][i];
122 if (
t->nb[
level][which].pos != nodepos) {
124 if (
t->nb[
level][which].dirty) {
127 t->nb[
level][which].dirty = 0;
130 t->nb[
level][which].pos = nodepos;
136 t->used[
level][0] = which;
142 t->used[
level][0] = which;
148 return &(
t->nb[
level][which].n);
156 if (write(
t->fd,
b->rect.boundary,
t->rectsize) !=
t->rectsize)
176 if (write(
t->fd, &(n->
count),
sizeof(
int)) !=
sizeof(
int))
180 if (write(
t->fd, &(n->
level),
sizeof(
int)) !=
sizeof(int))
185 for (i = 0; i <
MAXCARD; i++) {
195 lseek(
t->fd, nodepos, SEEK_SET);
206 while (
t->nb[n->
level][
t->used[n->
level][i]].pos != nodepos &&
213 which =
t->used[n->
level][i];
215 t->nb[n->
level][which].dirty = 1;
221 t->used[n->
level][0] = which;
227 t->used[n->
level][0] = which;
237 for (i = 0; i <=
t->rootlevel; i++) {
239 if (
t->nb[i][j].dirty) {
241 t->nb[i][j].dirty = 0;
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
off_t RTreeGetNodePos(struct RTree *t)
void RTreeNodeChanged(struct RTree_Node *n, off_t nodepos, struct RTree *t)
size_t RTreeWriteBranch(struct RTree_Branch *b, struct RTree *t)
size_t RTreeReadNode(struct RTree_Node *n, off_t nodepos, struct RTree *t)
void RTreeFlushBuffer(struct RTree *t)
size_t RTreeWriteNode(struct RTree_Node *n, struct RTree *t)
size_t RTreeRewriteNode(struct RTree_Node *n, off_t nodepos, struct RTree *t)
void RTreeAddNodePos(off_t pos, int level, struct RTree *t)
struct RTree_Node * RTreeGetNode(off_t nodepos, int level, struct RTree *t)
size_t RTreeReadBranch(struct RTree_Branch *b, struct RTree *t)
#define assert(condition)
struct RTree_Branch * branch