Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
hit_gbtile.c
Go to the documentation of this file.
1 
10 /*
11  * <license>
12  *
13  * Hitmap v1.2
14  *
15  * This software is provided to enhance knowledge and encourage progress in the scientific
16  * community. It should be used only for research and educational purposes. Any reproduction
17  * or use for commercial purpose, public redistribution, in source or binary forms, with or
18  * without modifications, is NOT ALLOWED without the previous authorization of the copyright
19  * holder. The origin of this software must not be misrepresented; you must not claim that you
20  * wrote the original software. If you use this software for any purpose (e.g. publication),
21  * a reference to the software package and the authors must be included.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY
24  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
26  * THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Copyright (c) 2007-2015, Trasgo Group, Universidad de Valladolid.
34  * All rights reserved.
35  *
36  * More information on http://trasgo.infor.uva.es/
37  *
38  * </license>
39 */
40 
41 #include <hit_gbtile.h>
42 #include <hit_bshape.h>
43 #include <hit_allocP.h>
44 
45 
46 
47 
48 
49 void hit_gbTileDomainShapeInternal(void * newVarP, size_t baseExtent, HitShape shape, int allocOpts) {
50 
51  HitPTile newVar = (HitPTile)newVarP;
52  *newVar = HIT_TILE_NULL;
53 
54  // 1. Num of dimensions, Mark no memory status, and Null pointers.
55  newVar->shape = shape;
56  newVar->baseExtent = baseExtent;
57  newVar->memStatus = HIT_MS_NOMEM;
58  newVar->hierDepth = (char) HIT_NONHIERARCHICAL;
59  newVar->ref = NULL;
60  newVar->data = NULL;
61  newVar->memPtr = NULL;
62  newVar->type = HIT_GB_TILE;
63 
64 
65  // 2. Process Vertices and Edges cardinalities.
66  if(allocOpts & HIT_VERTICES){
67  newVar->card[0] = hit_bShapeNvertices(shape);
68  }
69 
70  if(allocOpts & HIT_EDGES){
71  newVar->card[1] = hit_bShapeNvertices(shape);
72  newVar->card[2] = hit_bShapeNvertices(shape);
73  }
74 
75 }
76 
77 
78 void hit_gbTileAllocInternal(void *newVarP, const char *name, const char *file, int numLine) {
79 
80  HitPTile newVar = (HitPTile)newVarP;
81 
82  // 0. Skip alloc when Null.
83  if ( newVar->memStatus == HIT_MS_NULL) return;
84 
85  // 1. Check variable type, cannot have already its own memory.
86  if ( newVar->memStatus == HIT_MS_OWNER ){
87  hit_errInternal(__FUNCTION__,"Trying to reallocate a Tile: ",name,file,numLine);
88  }
89 
90  // 3. Allocate memory.
91  if(newVar->card[0] != 0){
92  // @arturo Ago 2015: New allocP interface
93  // hit_malloc(newVar->memPtrVertices,(size_t)newVar->card[0] * newVar->baseExtent,void*);
94  hit_vmalloc(newVar->memPtrVertices, (size_t)newVar->card[0] * newVar->baseExtent );
95  newVar->dataVertices = newVar->memPtrVertices;
96  }
97 
98  if(newVar->card[1] != 0 && newVar->card[2] != 0){
99  // @arturo Ago 2015: New allocP interface
100  // hit_malloc(newVar->memPtr,(size_t)(newVar->card[1]*newVar->card[2]) * newVar->baseExtent,void*);
101  hit_vmalloc(newVar->memPtr, (size_t)(newVar->card[1] * newVar->card[2]) * newVar->baseExtent );
102  newVar->data = newVar->memPtr;
103  }
104 
105  // 4. Change memory status.
106  newVar->memStatus = HIT_MS_OWNER;
107 }
108 
109 
110 
111 
112 
113 inline int hit_gbTileGraphVertexAtIndex(void * varP, int vertex){
114 
115  /* 1. Get the shape of the tile */
116  HitTile *var = (HitTile *)varP;
117  HitShape shape = hit_tileShape(*var);
118 
119  return hit_bShapeVertexToLocal(shape,vertex);
120 
121 }
122 
123 
124 
125 
126 
127 
128 inline int hit_gbTileGraphEdgeAtIndex(void * varP, int pos1, int pos2){
129 
130  /* 1. Get the shape of the tile */
131  HitTile *var = (HitTile *)varP;
132  HitShape shape = hit_tileShape(*var);
133 
134  int local1 = hit_bShapeVertexToLocal(shape,pos1);
135  int local2 = hit_bShapeVertexToLocal(shape,pos2);
136 
137  int nvertices = hit_bShapeNvertices(shape);
138 
139  return local1 * nvertices + local2;
140 }
141 
142 
143 
144 
145 
146 void hit_gbTileClearVertices(void * varP){
147 
148  /* 1. Get the shape of the tile */
149  HitTile *var = (HitTile *)varP;
150  HitShape shape = hit_tileShape(*var);
151  int nvertices = hit_bShapeNvertices(shape);
152 
153  bzero(var->dataVertices, var->baseExtent * (size_t) nvertices);
154 }
155 
156 
157 
158 
159 void hit_gbTileCopyVertices(void * destP, void * srcP){
160 
161  /* 1. Get the shape of the tile */
162  HitTile *dest = (HitTile *)destP;
163  HitTile *src = (HitTile *)srcP;
164 
165  HitShape shape = hit_tileShape(*src);
166 
167  int nvertices = hit_bShapeNvertices(shape);
168 
169  memcpy(dest->dataVertices,src->dataVertices,src->baseExtent * (size_t) nvertices);
170 
171 }
int hit_gbTileGraphVertexAtIndex(void *varP, int vertex)
Definition: hit_gbtile.c:113
void hit_gbTileAllocInternal(void *newVarP, const char *name, const char *file, int numLine)
Definition: hit_gbtile.c:78
void hit_gbTileDomainShapeInternal(void *newVarP, size_t baseExtent, HitShape shape, int allocOpts)
Definition: hit_gbtile.c:49
void hit_gbTileCopyVertices(void *destP, void *srcP)
Definition: hit_gbtile.c:159
void hit_gbTileClearVertices(void *varP)
Definition: hit_gbtile.c:146
#define HIT_EDGES
Definition: hit_tile.h:214
#define hit_bShapeVertexToLocal(s, vertex)
Definition: hit_bshape.h:355
Hitmap functions to allocate memory.
int hit_gbTileGraphEdgeAtIndex(void *varP, int pos1, int pos2)
Definition: hit_gbtile.c:128
HitShape shape
#define hit_bShapeNvertices(shape)
#define hit_vmalloc(ptr, size)
Definition: hit_allocP.h:72
HitTile HIT_TILE_NULL
Definition: hit_tile.c:63
#define hit_errInternal(routine, text, extraParam, file, numLine)
Definition: hit_error.h:63
#define hit_tileShape(var)
Definition: hit_tile.h:723
#define HIT_VERTICES
Definition: hit_tile.h:208