39 Plus->cidx_up_to_date = 0;
50 for (i = 0; i <
Plus->n_cidx; i++) {
54 ci->field =
ci->n_cats =
ci->a_cats =
ci->n_types = 0;
62 Plus->cidx_up_to_date = 0;
78 G_debug(3,
"dig_cidx_add_cat(): field = %d cat = %d line = %d type = %d",
83 for (i = 0; i <
Plus->n_cidx; i++) {
99 ci->n_cats =
ci->a_cats = 0;
108 if (
ci->n_cats ==
ci->a_cats) {
115 ci->cat[
ci->n_cats][2] = line;
120 for (i = 0; i <
ci->n_types; i++) {
121 if (
ci->type[i][0] ==
type) {
128 ci->type[
ci->n_types][1] = 1;
136static int cmp_cat(
const void *
pa,
const void *pb)
157static int cmp_field(
const void *
pa,
const void *pb)
184 3,
"dig_cidx_add_cat_sorted(): field = %d cat = %d line = %d type = %d",
189 for (i = 0; i <
Plus->n_cidx; i++) {
205 ci->n_cats =
ci->a_cats = 0;
214 if (
ci->n_cats ==
ci->a_cats) {
220 for (position =
ci->n_cats; position > 0; position--) {
221 if (
ci->cat[position - 1][0] <
cat ||
222 (
ci->cat[position - 1][0] ==
cat &&
223 ci->cat[position - 1][1] <=
type)) {
226 ci->cat[position][0] =
ci->cat[position - 1][0];
227 ci->cat[position][1] =
ci->cat[position - 1][1];
228 ci->cat[position][2] =
ci->cat[position - 1][2];
231 G_debug(4,
"position = %d", position);
233 ci->cat[position][0] =
cat;
234 ci->cat[position][1] =
type;
235 ci->cat[position][2] = line;
240 for (i = 0; i <
ci->n_types; i++) {
241 if (
ci->type[i][0] ==
type) {
248 ci->type[
ci->n_types][1] = 1;
255 G_debug(3,
"Added new category to index");
273 G_debug(3,
"dig_cidx_del_cat(): field = %d cat = %d line = %d",
field,
cat,
278 for (i = 0; i <
Plus->n_cidx; i++) {
290 for (position = 0; position <
ci->n_cats; position++) {
291 if (
ci->cat[position][0] ==
cat &&
ci->cat[position][1] ==
type &&
292 ci->cat[position][2] == line) {
297 G_debug(4,
"position = %d", position);
299 if (position ==
ci->n_cats) {
300 G_warning(
"BUG: Category not found in category index.");
305 for (i = position; i <
ci->n_cats - 1; i++) {
306 ci->cat[i][0] =
ci->cat[i + 1][0];
307 ci->cat[i][1] =
ci->cat[i + 1][1];
308 ci->cat[i][2] =
ci->cat[i + 1][2];
313 for (i = 0; i <
ci->n_types; i++) {
314 if (
ci->type[i][0] ==
type) {
319 G_debug(3,
"Deleted from category index");
335 for (f = 0; f <
Plus->n_cidx; f++) {
341 qsort(
ci->cat,
ci->n_cats, 3 *
sizeof(
int), cmp_cat);
346 for (c = 1; c <
ci->n_cats; c++) {
347 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.