|
|
|
@ -73,39 +73,28 @@ struct map_hash *map_hash_geti (int ilon, int ilat, int loadflags) {
|
|
|
|
struct map_hash *res = NULL;
|
|
|
|
struct map_hash *res = NULL;
|
|
|
|
int hi;
|
|
|
|
int hi;
|
|
|
|
|
|
|
|
|
|
|
|
hi = mhash_pos;
|
|
|
|
for (hi = 0; hi < mhash_max; hi++)
|
|
|
|
if (mhash[hi] && mhash[hi]->pos.ilon == ilon && mhash[hi]->pos.ilat == ilat) res = mhash[hi];
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
hi = mhash_pos+1;
|
|
|
|
|
|
|
|
if (hi >= mhash_max) hi = 0;
|
|
|
|
|
|
|
|
while (hi != mhash_pos) {
|
|
|
|
|
|
|
|
if (mhash[hi] && mhash[hi]->pos.ilon == ilon && mhash[hi]->pos.ilat == ilat) {
|
|
|
|
if (mhash[hi] && mhash[hi]->pos.ilon == ilon && mhash[hi]->pos.ilat == ilat) {
|
|
|
|
res = mhash[hi];
|
|
|
|
res = mhash[hi];
|
|
|
|
break;
|
|
|
|
for (; hi > 0; hi--) mhash[hi] = mhash[hi-1];
|
|
|
|
|
|
|
|
mhash[0] = res;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (++hi >= mhash_max) hi = 0;
|
|
|
|
if (loadflags & MHLOAD_RELOAD) {
|
|
|
|
|
|
|
|
if (mhash[mhash_max-1]) {
|
|
|
|
|
|
|
|
map_hash_free (mhash[mhash_max-1], 1);
|
|
|
|
|
|
|
|
mhash[mhash_max-1] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memmove (&mhash[1], &mhash[0], sizeof (struct map_hash*)*mhash_max-1);
|
|
|
|
|
|
|
|
mhash[0] = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (res == NULL && loadflags & MHLOAD_RELOAD) {
|
|
|
|
|
|
|
|
res = map_load_hash (ilon, ilat);
|
|
|
|
res = map_load_hash (ilon, ilat);
|
|
|
|
if (res) {
|
|
|
|
if (res) {
|
|
|
|
if ((--mhash_pos) < 0) mhash_pos = mhash_max-1;
|
|
|
|
mhash[0] = res;
|
|
|
|
|
|
|
|
|
|
|
|
/* add on the givin place, delete old entry */
|
|
|
|
|
|
|
|
if (mhash[mhash_pos]) {
|
|
|
|
|
|
|
|
map_hash_free (mhash[mhash_pos], 1);
|
|
|
|
|
|
|
|
mhash[mhash_pos] = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* add or update */
|
|
|
|
|
|
|
|
if (mhash[mhash_pos] != NULL) d_printf ("%s:%d map_hash_add: memory leak: not free spot", __FILE__, __LINE__);
|
|
|
|
|
|
|
|
mhash[mhash_pos] = res;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DELFLAG (res->status, MS_changed);
|
|
|
|
DELFLAG (res->status, MS_changed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@ -116,18 +105,22 @@ struct map_hash *map_hash_geti (int ilon, int ilat, int loadflags) {
|
|
|
|
* if it already excist exchange it and free the old hash data from the memory
|
|
|
|
* if it already excist exchange it and free the old hash data from the memory
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int map_hash_add (struct map_hash *mh) {
|
|
|
|
int map_hash_add (struct map_hash *mh) {
|
|
|
|
int i;
|
|
|
|
int i, fi = -1; /* fi: free hash position */
|
|
|
|
struct map_hash *mhold = NULL;
|
|
|
|
struct map_hash *mhold = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (mh == NULL) return 0;
|
|
|
|
if (mh == NULL) return 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* check if we need to "UPDATE" or to add the hash data */
|
|
|
|
/* check if we need to "UPDATE" or to add the hash data */
|
|
|
|
for (mhold = NULL, i = 0; i < mhash_max; i++) if (mhash[i]) {
|
|
|
|
for (mhold = NULL, i = 0; i < mhash_max; i++) {
|
|
|
|
|
|
|
|
if (mhash[i]) {
|
|
|
|
if (mhash[i]->pos.ilon == mh->pos.ilon && mhash[i]->pos.ilat == mh->pos.ilat) {
|
|
|
|
if (mhash[i]->pos.ilon == mh->pos.ilon && mhash[i]->pos.ilat == mh->pos.ilat) {
|
|
|
|
mhold = mhash[i];
|
|
|
|
mhold = mhash[i];
|
|
|
|
|
|
|
|
fi = i;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (fi == -1) fi = i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mhold != NULL) { /* update !! NOSAVEING !! */
|
|
|
|
if (mhold != NULL) { /* update !! NOSAVEING !! */
|
|
|
|
mhash[i] = NULL;
|
|
|
|
mhash[i] = NULL;
|
|
|
|
@ -135,18 +128,18 @@ int map_hash_add (struct map_hash *mh) {
|
|
|
|
mhold = NULL;
|
|
|
|
mhold = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((--mhash_pos) < 0) mhash_pos = mhash_max-1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* add on the givin place, delete old entry */
|
|
|
|
/* add on the givin place, delete old entry */
|
|
|
|
mhold = NULL;
|
|
|
|
if (fi == -1) {
|
|
|
|
if (mhash[mhash_pos]) {
|
|
|
|
if (mhash[mhash_max-1]) {
|
|
|
|
map_hash_free (mhash[mhash_pos], 1);
|
|
|
|
map_hash_free (mhash[mhash_max-1], 1);
|
|
|
|
mhash[mhash_pos] = NULL;
|
|
|
|
mhash[mhash_max-1] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memmove (&mhash[0], &mhash[1], sizeof (struct map_hash*)*mhash_max-1);
|
|
|
|
/* add or update */
|
|
|
|
mhash[0] = NULL;
|
|
|
|
if (mhash[mhash_pos] != NULL) d_printf ("%s:%d map_hash_add: memory leak: not free spot", __FILE__, __LINE__);
|
|
|
|
mhash[0] = mh;
|
|
|
|
mhash[mhash_pos] = mh;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
mhash[fi] = mh;
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@ -177,7 +170,8 @@ struct map_hash *map_hash_realloc (struct map_hash *mhorg, int memsize) {
|
|
|
|
struct map_hash *res;
|
|
|
|
struct map_hash *res;
|
|
|
|
int i = memsize;
|
|
|
|
int i = memsize;
|
|
|
|
|
|
|
|
|
|
|
|
if (i < mhorg->datasize) i = mhorg->datasize;
|
|
|
|
if (i < mhorg->datasize) return res;
|
|
|
|
|
|
|
|
|
|
|
|
res = map_hash_alloc (i);
|
|
|
|
res = map_hash_alloc (i);
|
|
|
|
map_hash_copy (res, mhorg);
|
|
|
|
map_hash_copy (res, mhorg);
|
|
|
|
|
|
|
|
|
|
|
|
|