5
#include <grass/raster3d.h>
6
#include "raster3d_intern.h"
8
/*---------------------------------------------------------------------------*/
9
#ifndef GRASS_RASTER3D_H
23
/*---------------------------------------------------------------------------*/
25
void Rast3d_cache_hash_reset(Rast3d_cache_hash * h)
29
for (i = 0; i < h->nofNames; i++)
32
h->lastIndexActive = 0;
35
/*---------------------------------------------------------------------------*/
37
void Rast3d_cache_hash_dispose(Rast3d_cache_hash * h)
43
Rast3d_free(h->index);
44
if (h->active != NULL)
45
Rast3d_free(h->active);
49
/*---------------------------------------------------------------------------*/
51
void *Rast3d_cache_hash_new(int nofNames)
53
Rast3d_cache_hash *tmp;
55
tmp = (Rast3d_cache_hash *)Rast3d_malloc(sizeof(Rast3d_cache_hash));
57
Rast3d_error("Rast3d_cache_hash_new: error in Rast3d_malloc");
61
tmp->nofNames = nofNames;
62
tmp->index = (int*) Rast3d_malloc(tmp->nofNames * sizeof(int));
63
tmp->active = (char*) Rast3d_malloc(tmp->nofNames * sizeof(char));
64
if ((tmp->index == NULL) || (tmp->active == NULL)) {
65
Rast3d_cache_hash_dispose(tmp);
66
Rast3d_error("Rast3d_cache_hash_new: error in Rast3d_malloc");
70
Rast3d_cache_hash_reset(tmp);
75
/*---------------------------------------------------------------------------*/
77
void Rast3d_cache_hash_remove_name(Rast3d_cache_hash * h, int name)
79
if (name >= h->nofNames)
80
Rast3d_fatal_error("Rast3d_cache_hash_remove_name: name %i out of range", name);
82
if (h->active[name] == 0)
83
Rast3d_fatal_error("Rast3d_cache_hash_remove_name: name %i not in hashtable", name);
86
if (name == h->lastName)
87
h->lastIndexActive = 0;
90
/*---------------------------------------------------------------------------*/
92
void Rast3d_cache_hash_load_name(Rast3d_cache_hash * h, int name, int index)
94
if (name >= h->nofNames)
95
Rast3d_fatal_error("Rast3d_cache_hash_load_name: name out of range");
97
if (h->active[name] != 0)
98
Rast3d_fatal_error("Rast3d_cache_hash_load_name: name already in hashtable");
100
h->index[name] = index;
104
/*---------------------------------------------------------------------------*/
106
int Rast3d_cache_hash_name2index(Rast3d_cache_hash * h, int name)
110
if (h->lastIndexActive)
111
if (h->lastName == name)
114
if (!h->active[name])
117
index = h->index[name];
120
h->lastIndex = index;
121
h->lastIndexActive = 1;