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