50 for (i = 0; i < Plus->
n_cidx; i++) {
51 ci = &(Plus->
cidx[i]);
79 G_debug(3,
"dig_cidx_add_cat(): field = %d cat = %d line = %d type = %d",
80 field, cat, line, type);
84 for (i = 0; i < Plus->
n_cidx; i++) {
85 if (Plus->
cidx[i].field == field) {
100 ci = &(Plus->
cidx[si]);
110 ci = &(Plus->
cidx[si]);
123 for (i = 0; i < ci->
n_types; i++) {
124 if (ci->
type[i][0] == type) {
139 static int cmp_cat(
const void *pa,
const void *pb)
160 static int cmp_field(
const void *pa,
const void *pb)
183 int i, si, found, position;
187 "dig_cidx_add_cat_sorted(): field = %d cat = %d line = %d type = %d",
188 field, cat, line, type);
192 for (i = 0; i < Plus->
n_cidx; i++) {
193 if (Plus->
cidx[i].field == field) {
208 ci = &(Plus->
cidx[si]);
218 ci = &(Plus->
cidx[si]);
225 for (position = ci->
n_cats; position > 0; position--) {
226 if (ci->
cat[position - 1][0] < cat ||
227 (ci->
cat[position - 1][0] == cat && ci->
cat[position - 1][1] <= type)) {
230 ci->
cat[position][0] = ci->
cat[position - 1][0];
231 ci->
cat[position][1] = ci->
cat[position - 1][1];
232 ci->
cat[position][2] = ci->
cat[position - 1][2];
235 G_debug(4,
"position = %d", position);
237 ci->
cat[position][0] =
cat;
239 ci->
cat[position][2] = line;
244 for (i = 0; i < ci->
n_types; i++) {
245 if (ci->
type[i][0] == type) {
259 G_debug(3,
"Added new category to index");
278 G_debug(3,
"dig_cidx_del_cat(): field = %d cat = %d line = %d", field,
283 for (i = 0; i < Plus->
n_cidx; i++) {
284 if (Plus->
cidx[i].field == field) {
285 ci = &(Plus->
cidx[i]);
289 G_warning(
"BUG: Category index not found for field %d.", field);
295 for (position = 0; position < ci->
n_cats; position++) {
296 if (ci->
cat[position][0] == cat && ci->
cat[position][1] == type &&
297 ci->
cat[position][2] == line) {
302 G_debug(4,
"position = %d", position);
304 if (position == ci->
n_cats) {
305 G_warning(
"BUG: Category not found in category index.");
310 for (i = position; i < ci->
n_cats - 1; i++) {
311 ci->
cat[i][0] = ci->
cat[i + 1][0];
312 ci->
cat[i][1] = ci->
cat[i + 1][1];
313 ci->
cat[i][2] = ci->
cat[i + 1][2];
318 for (i = 0; i < ci->
n_types; i++) {
319 if (ci->
type[i][0] == type) {
324 G_debug(3,
"Deleted from category index");
340 for (f = 0; f < Plus->
n_cidx; f++) {
343 ci = &(Plus->
cidx[f]);
346 qsort(ci->
cat, ci->
n_cats, 3 *
sizeof(
int), cmp_cat);
351 for (c = 1; c < ci->
n_cats; c++) {
352 if (ci->
cat[c][0] != ci->
cat[c - 1][0])
int a_cidx
Allocated space for category indexes.
struct Version_info cidx
Version info for category index file.
int n_types
Number of types in type.
int dig_cidx_add_cat_sorted(struct Plus_head *Plus, int field, int cat, int line, int type)
off_t offset
Offset of the beginning of this index in cidx file.
void G_free(void *)
Free allocated memory.
int field
Field (layer) number.
int n_ucats
Number of unique cats (not updated)
int cidx_up_to_date
Category index to be updated.
Basic topology-related info.
int dig_cidx_add_cat(struct Plus_head *Plus, int field, int cat, int line, int type)
int n_cats
Number of items in cat array.
void dig_cidx_sort(struct Plus_head *Plus)
int(* cat)[3]
Array of cats (cat, type, lines/area)
void dig_cidx_free(struct Plus_head *Plus)
int dig_cidx_init(struct Plus_head *Plus)
Initialize Plus_head structure (cidx)
int type[7][2]
Number of elements for each type.
int a_cats
Allocated space in cat array.
void G_warning(const char *,...) __attribute__((format(printf
int dig_cidx_del_cat(struct Plus_head *Plus, int field, int cat, int line, int type)
int G_debug(int, const char *,...) __attribute__((format(printf
int n_cidx
Number of category indexes (one for each field/layer)