Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
hit_mbtile.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_mbtile.h>
34 #include <hit_bshape.h>
35 #include <hit_allocP.h>
36 
37 
38 void hit_mbTileDomainShapeInternal(void * newVarP, size_t baseExtent, HitShape shape) {
39 
40  HitPTile newVar = (HitPTile)newVarP;
41  *newVar = HIT_TILE_NULL;
42 
43  // 1. Num of dimensions, Mark no memory status, and Null pointers.
44  newVar->shape = shape;
45  newVar->baseExtent = baseExtent;
46  newVar->memStatus = HIT_MS_NOMEM;
47  newVar->hierDepth = (char) HIT_NONHIERARCHICAL;
48  newVar->ref = NULL;
49  newVar->data = NULL;
50  newVar->memPtr = NULL;
51  newVar->type = HIT_MB_TILE;
52 
53  // 2. Process Vertices and Edges cardinalities.
54  newVar->card[1] = hit_bShapeCard(shape,0);
55  newVar->card[2] = hit_bShapeCard(shape,1);
56 
57 
58 }
59 
60 
61 void hit_mbTileAllocInternal(void *newVarP, const char *name, const char *file, int numLine) {
62 
63  HitPTile newVar = (HitPTile)newVarP;
64 
65  // 0. Skip alloc when Null.
66  if ( newVar->memStatus == HIT_MS_NULL) return;
67 
68  // 1. Check variable type, cannot have already its own memory.
69  if ( newVar->memStatus == HIT_MS_OWNER ){
70  hit_errInternal(__FUNCTION__,"Trying to reallocate a Tile: ",name,file,numLine);
71  }
72 
73  // 3. Allocate memory.
74  if(newVar->card[1] != 0 && newVar->card[2] != 0){
75  // @arturo Ago 2015: New allocP interface
76  // hit_malloc(newVar->memPtr,(size_t)(newVar->card[1]*newVar->card[2]) * newVar->baseExtent,void*);
77  hit_vmalloc(newVar->memPtr, (size_t)(newVar->card[1] * newVar->card[2]) * newVar->baseExtent);
78  newVar->data = newVar->memPtr;
79  }
80 
81  // 4. Change memory status.
82  newVar->memStatus = HIT_MS_OWNER;
83 }
84 
85 
86 int hit_mcTileElemAtIndex(void * varP, int row, int column){
87 
88  /* 1. Get the shape of the tile */
89  HitTile *var = (HitTile *)varP;
91 
92  //int card1 = hit_bShapeCard(shape,0);
93  int card2 = hit_bShapeCard(shape,1);
94 
95  return row * card2 + column;
96 }
97 
98 
99 int hit_mcTileGraphElemAtIndex(void * varP, int pos1, int pos2){
100 
101  /* 1. Get the shape of the tile */
102  HitTile *var = (HitTile *)varP;
103  HitShape shape = hit_tileShape(*var);
104 
105  int row = hit_bShapeCoordToLocal(shape,0,pos1);
106  int column = hit_bShapeCoordToLocal(shape,1,pos2);
107 
108  //int card1 = hit_bShapeCard(shape,0);
109  int card2 = hit_bShapeCard(shape,1);
110 
111  return row * card2 + column;
112 }
113 
114 
115 
116 /* @arturo to @javier: TODO: Check this function, potential bugs */
117 void hit_mbTileClear(void * tileP){
118 
119  /* 1. Get the shape of the tile */
120  HitTile *tile = (HitTile *)tileP;
121  //HitShape shape = hit_tileShape(*tile);
122 
123  int card1 = tile->card[1];
124  int card2 = tile->card[1];
125 
126  bzero(tile->data, tile->baseExtent * (size_t) (card1 * card2) );
127 }
128 
129 
130 
131 
132 
#define hit_bShapeCard(shape, dim)
Definition: hit_bshape.h:144
#define hit_bShapeCoordToLocal(s, dim, elem)
Definition: hit_bshape.h:201
void hit_mbTileDomainShapeInternal(void *newVarP, size_t baseExtent, HitShape shape)
Definition: hit_mbtile.c:38
void hit_mbTileAllocInternal(void *newVarP, const char *name, const char *file, int numLine)
Definition: hit_mbtile.c:61
Hitmap functions to allocate memory.
int hit_mcTileGraphElemAtIndex(void *varP, int pos1, int pos2)
Definition: hit_mbtile.c:99
HitShape shape
int hit_mcTileElemAtIndex(void *varP, int local1, int local2)
Definition: hit_mbtile.c:86
void hit_mbTileClear(void *tileP)
Definition: hit_mbtile.c:117
#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