~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to lib/raster3d/cachehash.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <sys/types.h>
 
4
#include <unistd.h>
 
5
#include <grass/raster3d.h>
 
6
#include "raster3d_intern.h"
 
7
 
 
8
/*---------------------------------------------------------------------------*/
 
9
#ifndef GRASS_RASTER3D_H
 
10
typedef struct
 
11
{
 
12
 
 
13
    int nofNames;
 
14
    int *index;
 
15
    char *active;
 
16
    int lastName;
 
17
    int lastIndex;
 
18
    int lastIndexActive;
 
19
 
 
20
} Rast3d_cache_hash;
 
21
#endif
 
22
 
 
23
/*---------------------------------------------------------------------------*/
 
24
 
 
25
void Rast3d_cache_hash_reset(Rast3d_cache_hash * h)
 
26
{
 
27
    int i;
 
28
 
 
29
    for (i = 0; i < h->nofNames; i++)
 
30
        h->active[i] = 0;
 
31
 
 
32
    h->lastIndexActive = 0;
 
33
}
 
34
 
 
35
/*---------------------------------------------------------------------------*/
 
36
 
 
37
void Rast3d_cache_hash_dispose(Rast3d_cache_hash * h)
 
38
{
 
39
    if (h == NULL)
 
40
        return;
 
41
 
 
42
    if (h->index != NULL)
 
43
        Rast3d_free(h->index);
 
44
    if (h->active != NULL)
 
45
        Rast3d_free(h->active);
 
46
    Rast3d_free(h);
 
47
}
 
48
 
 
49
/*---------------------------------------------------------------------------*/
 
50
 
 
51
void *Rast3d_cache_hash_new(int nofNames)
 
52
{
 
53
    Rast3d_cache_hash *tmp;
 
54
 
 
55
    tmp = (Rast3d_cache_hash *)Rast3d_malloc(sizeof(Rast3d_cache_hash));
 
56
    if (tmp == NULL) {
 
57
        Rast3d_error("Rast3d_cache_hash_new: error in Rast3d_malloc");
 
58
        return (void *)NULL;
 
59
    }
 
60
    
 
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");
 
67
        return (void *)NULL;
 
68
    }
 
69
 
 
70
    Rast3d_cache_hash_reset(tmp);
 
71
 
 
72
    return tmp;
 
73
}
 
74
 
 
75
/*---------------------------------------------------------------------------*/
 
76
 
 
77
void Rast3d_cache_hash_remove_name(Rast3d_cache_hash * h, int name)
 
78
{
 
79
    if (name >= h->nofNames)
 
80
        Rast3d_fatal_error("Rast3d_cache_hash_remove_name: name %i out of range", name);
 
81
 
 
82
    if (h->active[name] == 0)
 
83
        Rast3d_fatal_error("Rast3d_cache_hash_remove_name: name %i not in hashtable", name);
 
84
 
 
85
    h->active[name] = 0;
 
86
    if (name == h->lastName)
 
87
        h->lastIndexActive = 0;
 
88
}
 
89
 
 
90
/*---------------------------------------------------------------------------*/
 
91
 
 
92
void Rast3d_cache_hash_load_name(Rast3d_cache_hash * h, int name, int index)
 
93
{
 
94
    if (name >= h->nofNames)
 
95
        Rast3d_fatal_error("Rast3d_cache_hash_load_name: name out of range");
 
96
 
 
97
    if (h->active[name] != 0)
 
98
        Rast3d_fatal_error("Rast3d_cache_hash_load_name: name already in hashtable");
 
99
 
 
100
    h->index[name] = index;
 
101
    h->active[name] = 1;
 
102
}
 
103
 
 
104
/*---------------------------------------------------------------------------*/
 
105
 
 
106
int Rast3d_cache_hash_name2index(Rast3d_cache_hash * h, int name)
 
107
{
 
108
    int index;
 
109
 
 
110
    if (h->lastIndexActive)
 
111
        if (h->lastName == name)
 
112
            return h->lastIndex;
 
113
 
 
114
    if (!h->active[name])
 
115
        return -1;
 
116
 
 
117
    index = h->index[name];
 
118
 
 
119
    h->lastName = name;
 
120
    h->lastIndex = index;
 
121
    h->lastIndexActive = 1;
 
122
 
 
123
    return index;
 
124
}