36 Plus->cidx_up_to_date = 0;
47 for (i = 0; i <
Plus->n_cidx; i++) {
51 ci->field =
ci->n_cats =
ci->a_cats =
ci->n_types = 0;
59 Plus->cidx_up_to_date = 0;
75 G_debug(3,
"dig_cidx_add_cat(): field = %d cat = %d line = %d type = %d",
80 for (i = 0; i <
Plus->n_cidx; i++) {
96 ci->n_cats =
ci->a_cats = 0;
105 if (
ci->n_cats ==
ci->a_cats) {
112 ci->cat[
ci->n_cats][2] = line;
117 for (i = 0; i <
ci->n_types; i++) {
118 if (
ci->type[i][0] ==
type) {
125 ci->type[
ci->n_types][1] = 1;
133static int cmp_cat(
const void *
pa,
const void *pb)
154static int cmp_field(
const void *
pa,
const void *pb)
181 3,
"dig_cidx_add_cat_sorted(): field = %d cat = %d line = %d type = %d",
186 for (i = 0; i <
Plus->n_cidx; i++) {
202 ci->n_cats =
ci->a_cats = 0;
211 if (
ci->n_cats ==
ci->a_cats) {
217 for (position =
ci->n_cats; position > 0; position--) {
218 if (
ci->cat[position - 1][0] <
cat ||
219 (
ci->cat[position - 1][0] ==
cat &&
220 ci->cat[position - 1][1] <=
type)) {
223 ci->cat[position][0] =
ci->cat[position - 1][0];
224 ci->cat[position][1] =
ci->cat[position - 1][1];
225 ci->cat[position][2] =
ci->cat[position - 1][2];
228 G_debug(4,
"position = %d", position);
230 ci->cat[position][0] =
cat;
231 ci->cat[position][1] =
type;
232 ci->cat[position][2] = line;
237 for (i = 0; i <
ci->n_types; i++) {
238 if (
ci->type[i][0] ==
type) {
245 ci->type[
ci->n_types][1] = 1;
252 G_debug(3,
"Added new category to index");
270 G_debug(3,
"dig_cidx_del_cat(): field = %d cat = %d line = %d",
field,
cat,
275 for (i = 0; i <
Plus->n_cidx; i++) {
287 for (position = 0; position <
ci->n_cats; position++) {
288 if (
ci->cat[position][0] ==
cat &&
ci->cat[position][1] ==
type &&
289 ci->cat[position][2] == line) {
294 G_debug(4,
"position = %d", position);
296 if (position ==
ci->n_cats) {
297 G_warning(
"BUG: Category not found in category index.");
302 for (i = position; i <
ci->n_cats - 1; i++) {
303 ci->cat[i][0] =
ci->cat[i + 1][0];
304 ci->cat[i][1] =
ci->cat[i + 1][1];
305 ci->cat[i][2] =
ci->cat[i + 1][2];
310 for (i = 0; i <
ci->n_types; i++) {
311 if (
ci->type[i][0] ==
type) {
316 G_debug(3,
"Deleted from category index");
332 for (f = 0; f <
Plus->n_cidx; f++) {
338 qsort(
ci->cat,
ci->n_cats, 3 *
sizeof(
int), cmp_cat);
343 for (c = 1; c <
ci->n_cats; c++) {
344 if (
ci->cat[c][0] !=
ci->cat[c - 1][0])
void G_free(void *)
Free allocated memory.
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
int dig_cidx_init(struct Plus_head *Plus)
Initialize Plus_head structure (cidx)
void dig_cidx_free(struct Plus_head *Plus)
int dig_cidx_del_cat(struct Plus_head *Plus, int field, int cat, int line, int type)
void dig_cidx_sort(struct Plus_head *Plus)
int dig_cidx_add_cat_sorted(struct Plus_head *Plus, int field, int cat, int line, int type)
int dig_cidx_add_cat(struct Plus_head *Plus, int field, int cat, int line, int type)
int(* cat)[3]
Array of cats (cat, type, lines/area)
int field
Field (layer) number.
int type[7][2]
Number of elements for each type.
Basic topology-related info.