00001 /************************************************************************************************** 00002 MiniSat -- Copyright (c) 2005, Niklas Sorensson 00003 http://www.cs.chalmers.se/Cs/Research/FormalMethods/MiniSat/ 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 00006 associated documentation files (the "Software"), to deal in the Software without restriction, 00007 including without limitation the rights to use, copy, modify, merge, publish, distribute, 00008 sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in all copies or 00012 substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 00015 NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00016 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00017 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 00018 OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00019 **************************************************************************************************/ 00020 // Modified to compile with MS Visual Studio 6.0 by Alan Mishchenko 00021 00022 #ifndef satVec_h 00023 #define satVec_h 00024 00025 #include <stdlib.h> 00026 00027 // vector of 32-bit intergers (added for 64-bit portability) 00028 struct veci_t { 00029 int size; 00030 int cap; 00031 int* ptr; 00032 }; 00033 typedef struct veci_t veci; 00034 00035 static inline void veci_new (veci* v) { 00036 v->size = 0; 00037 v->cap = 4; 00038 v->ptr = (int*)malloc(sizeof(int)*v->cap); 00039 } 00040 00041 static inline void veci_delete (veci* v) { free(v->ptr); } 00042 static inline int* veci_begin (veci* v) { return v->ptr; } 00043 static inline int veci_size (veci* v) { return v->size; } 00044 static inline void veci_resize (veci* v, int k) { v->size = k; } // only safe to shrink !! 00045 static inline void veci_push (veci* v, int e) 00046 { 00047 if (v->size == v->cap) { 00048 int newsize = v->cap * 2;//+1; 00049 v->ptr = (int*)realloc(v->ptr,sizeof(int)*newsize); 00050 v->cap = newsize; } 00051 v->ptr[v->size++] = e; 00052 } 00053 00054 00055 // vector of 32- or 64-bit pointers 00056 struct vecp_t { 00057 int size; 00058 int cap; 00059 void** ptr; 00060 }; 00061 typedef struct vecp_t vecp; 00062 00063 static inline void vecp_new (vecp* v) { 00064 v->size = 0; 00065 v->cap = 4; 00066 v->ptr = (void**)malloc(sizeof(void*)*v->cap); 00067 } 00068 00069 static inline void vecp_delete (vecp* v) { free(v->ptr); } 00070 static inline void** vecp_begin (vecp* v) { return v->ptr; } 00071 static inline int vecp_size (vecp* v) { return v->size; } 00072 static inline void vecp_resize (vecp* v, int k) { v->size = k; } // only safe to shrink !! 00073 static inline void vecp_push (vecp* v, void* e) 00074 { 00075 if (v->size == v->cap) { 00076 int newsize = v->cap * 2;//+1; 00077 v->ptr = (void**)realloc(v->ptr,sizeof(void*)*newsize); 00078 v->cap = newsize; } 00079 v->ptr[v->size++] = e; 00080 } 00081 00082 00083 #endif