abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mapperVec.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mapperVec.c]
4 
5  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7  Synopsis [Generic technology mapping engine.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 2.0. Started - June 1, 2004.]
14 
15  Revision [$Id: mapperVec.c,v 1.3 2005/01/23 06:59:45 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "mapperInt.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 static int Map_NodeVecCompareLevels( Map_Node_t ** pp1, Map_Node_t ** pp2 );
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Allocates a vector with the given capacity.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
46 {
47  Map_NodeVec_t * p;
48  p = ABC_ALLOC( Map_NodeVec_t, 1 );
49  if ( nCap > 0 && nCap < 16 )
50  nCap = 16;
51  p->nSize = 0;
52  p->nCap = nCap;
53  p->pArray = p->nCap? ABC_ALLOC( Map_Node_t *, p->nCap ) : NULL;
54  return p;
55 }
56 
57 /**Function*************************************************************
58 
59  Synopsis []
60 
61  Description []
62 
63  SideEffects []
64 
65  SeeAlso []
66 
67 ***********************************************************************/
69 {
70  if ( p == NULL )
71  return;
72  ABC_FREE( p->pArray );
73  ABC_FREE( p );
74 }
75 
76 /**Function*************************************************************
77 
78  Synopsis []
79 
80  Description []
81 
82  SideEffects []
83 
84  SeeAlso []
85 
86 ***********************************************************************/
88 {
89  Map_NodeVec_t * pNew = Map_NodeVecAlloc( p->nSize );
90  memcpy( pNew->pArray, p->pArray, sizeof(int) * p->nSize );
91  pNew->nSize = p->nSize;
92  return pNew;
93 }
94 
95 /**Function*************************************************************
96 
97  Synopsis []
98 
99  Description []
100 
101  SideEffects []
102 
103  SeeAlso []
104 
105 ***********************************************************************/
107 {
108  return p->pArray;
109 }
110 
111 /**Function*************************************************************
112 
113  Synopsis []
114 
115  Description []
116 
117  SideEffects []
118 
119  SeeAlso []
120 
121 ***********************************************************************/
123 {
124  return p->nSize;
125 }
126 
127 /**Function*************************************************************
128 
129  Synopsis [Resizes the vector to the given capacity.]
130 
131  Description []
132 
133  SideEffects []
134 
135  SeeAlso []
136 
137 ***********************************************************************/
138 void Map_NodeVecGrow( Map_NodeVec_t * p, int nCapMin )
139 {
140  if ( p->nCap >= nCapMin )
141  return;
142  p->pArray = ABC_REALLOC( Map_Node_t *, p->pArray, nCapMin );
143  p->nCap = nCapMin;
144 }
145 
146 /**Function*************************************************************
147 
148  Synopsis []
149 
150  Description []
151 
152  SideEffects []
153 
154  SeeAlso []
155 
156 ***********************************************************************/
157 void Map_NodeVecShrink( Map_NodeVec_t * p, int nSizeNew )
158 {
159  assert( p->nSize >= nSizeNew );
160  p->nSize = nSizeNew;
161 }
162 
163 /**Function*************************************************************
164 
165  Synopsis []
166 
167  Description []
168 
169  SideEffects []
170 
171  SeeAlso []
172 
173 ***********************************************************************/
175 {
176  p->nSize = 0;
177 }
178 
179 /**Function*************************************************************
180 
181  Synopsis []
182 
183  Description []
184 
185  SideEffects []
186 
187  SeeAlso []
188 
189 ***********************************************************************/
191 {
192  if ( p->nSize == p->nCap )
193  {
194  if ( p->nCap < 16 )
195  Map_NodeVecGrow( p, 16 );
196  else
197  Map_NodeVecGrow( p, 2 * p->nCap );
198  }
199  p->pArray[p->nSize++] = Entry;
200 }
201 
202 /**Function*************************************************************
203 
204  Synopsis [Add the element while ensuring uniqueness.]
205 
206  Description [Returns 1 if the element was found, and 0 if it was new. ]
207 
208  SideEffects []
209 
210  SeeAlso []
211 
212 ***********************************************************************/
214 {
215  int i;
216  for ( i = 0; i < p->nSize; i++ )
217  if ( p->pArray[i] == Entry )
218  return 1;
219  Map_NodeVecPush( p, Entry );
220  return 0;
221 }
222 
223 /**Function*************************************************************
224 
225  Synopsis []
226 
227  Description []
228 
229  SideEffects []
230 
231  SeeAlso []
232 
233 ***********************************************************************/
235 {
236  return p->pArray[--p->nSize];
237 }
238 
239 /**Function*************************************************************
240 
241  Synopsis []
242 
243  Description []
244 
245  SideEffects []
246 
247  SeeAlso []
248 
249 ***********************************************************************/
251 {
252  int i;
253  for ( i = 0; i < p->nSize; i++ )
254  if ( p->pArray[i] == Entry )
255  break;
256  assert( i < p->nSize );
257  for ( i++; i < p->nSize; i++ )
258  p->pArray[i-1] = p->pArray[i];
259  p->nSize--;
260 }
261 
262 /**Function*************************************************************
263 
264  Synopsis []
265 
266  Description []
267 
268  SideEffects []
269 
270  SeeAlso []
271 
272 ***********************************************************************/
274 {
275  assert( i >= 0 && i < p->nSize );
276  p->pArray[i] = Entry;
277 }
278 
279 /**Function*************************************************************
280 
281  Synopsis []
282 
283  Description []
284 
285  SideEffects []
286 
287  SeeAlso []
288 
289 ***********************************************************************/
291 {
292  assert( i >= 0 && i < p->nSize );
293  return p->pArray[i];
294 }
295 
296 /**Function*************************************************************
297 
298  Synopsis [Sorting the entries by their integer value.]
299 
300  Description []
301 
302  SideEffects []
303 
304  SeeAlso []
305 
306 ***********************************************************************/
308 {
309  qsort( (void *)p->pArray, p->nSize, sizeof(Map_Node_t *),
310  (int (*)(const void *, const void *)) Map_NodeVecCompareLevels );
311 }
312 
313 /**Function*************************************************************
314 
315  Synopsis [Comparison procedure for two clauses.]
316 
317  Description []
318 
319  SideEffects []
320 
321  SeeAlso []
322 
323 ***********************************************************************/
325 {
326  int Level1 = Map_Regular(*pp1)->Level;
327  int Level2 = Map_Regular(*pp2)->Level;
328  if ( Level1 < Level2 )
329  return -1;
330  if ( Level1 > Level2 )
331  return 1;
332  if ( Map_Regular(*pp1)->Num < Map_Regular(*pp2)->Num )
333  return -1;
334  if ( Map_Regular(*pp1)->Num > Map_Regular(*pp2)->Num )
335  return 1;
336  return 0;
337 }
338 
339 ////////////////////////////////////////////////////////////////////////
340 /// END OF FILE ///
341 ////////////////////////////////////////////////////////////////////////
342 
344 
void Map_NodeVecClear(Map_NodeVec_t *p)
Definition: mapperVec.c:174
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Map_NodeVecGrow(Map_NodeVec_t *p, int nCapMin)
Definition: mapperVec.c:138
Map_NodeVec_t * Map_NodeVecAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: mapperVec.c:45
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
Map_Node_t ** Map_NodeVecReadArray(Map_NodeVec_t *p)
Definition: mapperVec.c:106
Map_Node_t * Map_NodeVecPop(Map_NodeVec_t *p)
Definition: mapperVec.c:234
void Map_NodeVecRemove(Map_NodeVec_t *p, Map_Node_t *Entry)
Definition: mapperVec.c:250
char * memcpy()
void Map_NodeVecFree(Map_NodeVec_t *p)
Definition: mapperVec.c:68
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Map_NodeVecWriteEntry(Map_NodeVec_t *p, int i, Map_Node_t *Entry)
Definition: mapperVec.c:273
int Map_NodeVecPushUnique(Map_NodeVec_t *p, Map_Node_t *Entry)
Definition: mapperVec.c:213
void Map_NodeVecPush(Map_NodeVec_t *p, Map_Node_t *Entry)
Definition: mapperVec.c:190
static ABC_NAMESPACE_IMPL_START int Map_NodeVecCompareLevels(Map_Node_t **pp1, Map_Node_t **pp2)
DECLARATIONS ///.
Definition: mapperVec.c:324
Map_Node_t ** pArray
Definition: mapperInt.h:301
Map_NodeVec_t * Map_NodeVecDup(Map_NodeVec_t *p)
Definition: mapperVec.c:87
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
if(last==0)
Definition: sparse_int.h:34
void Map_NodeVecShrink(Map_NodeVec_t *p, int nSizeNew)
Definition: mapperVec.c:157
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define Map_Regular(p)
Definition: mapper.h:68
#define ABC_FREE(obj)
Definition: abc_global.h:232
Map_Node_t * Map_NodeVecReadEntry(Map_NodeVec_t *p, int i)
Definition: mapperVec.c:290
#define assert(ex)
Definition: util_old.h:213
void Map_NodeVecSortByLevel(Map_NodeVec_t *p)
Definition: mapperVec.c:307
int Map_NodeVecReadSize(Map_NodeVec_t *p)
Definition: mapperVec.c:122