7 static int NCATS = 1 <<
SHIFT;
9 #define NODE struct Cell_stats_node
11 static int next_node(
struct Cell_stats *);
12 static int init_node(
NODE *,
int,
int);
38 s->node = (
NODE *) G_malloc(s->tlen *
sizeof(
NODE));
39 s->null_data_count = 0;
73 register NODE *node, *pnode;
74 register NODE *new_node;
82 if ((N = s->N) == 0) {
92 idx = -((-cat) >>
SHIFT) - 1;
93 offset = cat + ((-idx) <<
SHIFT) - 1;
97 offset = cat - (idx <<
SHIFT);
100 init_node(&node[1], idx, offset);
108 s->null_data_count++;
112 idx = -((-cat) >>
SHIFT) - 1;
113 offset = cat + ((-idx) <<
SHIFT) - 1;
117 offset = cat - (idx <<
SHIFT);
122 pnode = &node[p =
q];
123 if (pnode->idx == idx) {
124 pnode->count[offset]++;
127 if (pnode->idx > idx)
141 (
NODE *) G_realloc((
char *)node,
147 init_node(new_node = &node[N], idx, offset);
149 if (pnode->idx > idx) {
150 new_node->right = -p;
154 new_node->right = pnode->right;
164 static int init_node(
NODE * node,
int idx,
int offset)
166 register long *
count;
169 count = node->count = (
long *)G_calloc(i = NCATS,
sizeof(
long));
173 node->count[offset] = 1;
212 *count = s->null_data_count;
213 return (*count != 0);
232 idx = -((-cat) >>
SHIFT) - 1;
233 offset = cat + ((-idx) <<
SHIFT) - 1;
237 offset = cat - (idx <<
SHIFT);
242 if (s->node[q].idx == idx) {
243 *count = s->node[
q].count[offset];
244 return (*count != 0);
246 if (s->node[q].idx > idx)
249 q = s->node[
q].right;
273 while ((q = s->node[s->curp].left))
280 static int next_node(
struct Cell_stats *
s)
285 s->curp = s->node[s->curp].right;
291 s->curp = -(s->curp);
295 while ((q = s->node[s->curp].left))
357 if (s->curoffset >= NCATS) {
363 if ((*count = s->node[s->curp].count[s->curoffset])) {
364 idx = s->node[s->curp].idx;
373 *cat = -((-idx) <<
SHIFT) + s->curoffset + 1;
375 *cat = (idx <<
SHIFT) + s->curoffset;
398 *count = s->null_data_count;
417 for (i = 1; i <= s->N; i++)