tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vector.h
Go to the documentation of this file.
1 /* =============================================================================
2  *
3  * vector.h
4  *
5  * =============================================================================
6  *
7  * Copyright (C) Stanford University, 2006. All Rights Reserved.
8  * Author: Chi Cao Minh
9  *
10  * =============================================================================
11  *
12  * For the license of bayes/sort.h and bayes/sort.c, please see the header
13  * of the files.
14  *
15  * ------------------------------------------------------------------------
16  *
17  * For the license of kmeans, please see kmeans/LICENSE.kmeans
18  *
19  * ------------------------------------------------------------------------
20  *
21  * For the license of ssca2, please see ssca2/COPYRIGHT
22  *
23  * ------------------------------------------------------------------------
24  *
25  * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
26  * header of the files.
27  *
28  * ------------------------------------------------------------------------
29  *
30  * For the license of lib/rbtree.h and lib/rbtree.c, please see
31  * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
32  *
33  * ------------------------------------------------------------------------
34  *
35  * Unless otherwise noted, the following license applies to STAMP files:
36  *
37  * Copyright (c) 2007, Stanford University
38  * All rights reserved.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions are
42  * met:
43  *
44  * * Redistributions of source code must retain the above copyright
45  * notice, this list of conditions and the following disclaimer.
46  *
47  * * Redistributions in binary form must reproduce the above copyright
48  * notice, this list of conditions and the following disclaimer in
49  * the documentation and/or other materials provided with the
50  * distribution.
51  *
52  * * Neither the name of Stanford University nor the names of its
53  * contributors may be used to endorse or promote products derived
54  * from this software without specific prior written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
57  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
60  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
66  * THE POSSIBILITY OF SUCH DAMAGE.
67  *
68  * =============================================================================
69  */
70 
71 
72 #ifndef VECTOR_H
73 #define VECTOR_H 1
74 
75 
76 #include "tm.h"
77 #include "types.h"
78 
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
84 
85 typedef struct vector {
86  long size;
87  long capacity;
88  void** elements;
89 } vector_t;
90 
91 
92 /* =============================================================================
93  * vector_alloc
94  * -- Returns NULL if failed
95  * =============================================================================
96  */
97 vector_t*
98 vector_alloc (long initCapacity);
99 
100 
101 /* =============================================================================
102  * Pvector_alloc
103  * -- Returns NULL if failed
104  * =============================================================================
105  */
106 vector_t*
107 Pvector_alloc (long initCapacity);
108 
109 
110 /* =============================================================================
111  * vector_free
112  * =============================================================================
113  */
114 void
115 vector_free (vector_t* vectorPtr);
116 
117 
118 /* =============================================================================
119  * Pvector_free
120  * =============================================================================
121  */
122 void
123 Pvector_free (vector_t* vectorPtr);
124 
125 
126 /* =============================================================================
127  * vector_at
128  * -- Returns NULL if failed
129  * =============================================================================
130  */
131 void*
132 vector_at (vector_t* vectorPtr, long i);
133 
134 
135 /* =============================================================================
136  * vector_pushBack
137  * -- Returns FALSE if fail, else TRUE
138  * =============================================================================
139  */
140 bool_t
141 vector_pushBack (vector_t* vectorPtr, void* dataPtr);
142 
143 
144 /* =============================================================================
145  * Pvector_pushBack
146  * -- Returns FALSE if fail, else TRUE
147  * =============================================================================
148  */
149 bool_t
150 Pvector_pushBack (vector_t* vectorPtr, void* dataPtr);
151 
152 
153 /* =============================================================================
154  * vector_popBack
155  * -- Returns NULL if fail, else returns last element
156  * =============================================================================
157  */
158 void*
159 vector_popBack (vector_t* vectorPtr);
160 
161 
162 /* =============================================================================
163  * vector_getSize
164  * =============================================================================
165  */
166 long
167 vector_getSize (vector_t* vectorPtr);
168 
169 
170 /* =============================================================================
171  * vector_clear
172  * =============================================================================
173  */
174 void
175 vector_clear (vector_t* vectorPtr);
176 
177 
178 /* =============================================================================
179  * vector_sort
180  * =============================================================================
181  */
182 void
183 vector_sort (vector_t* vectorPtr, int (*compare) (const void*, const void*));
184 
185 
186 /* =============================================================================
187  * vector_copy
188  * =============================================================================
189  */
190 bool_t
191 vector_copy (vector_t* dstVectorPtr, vector_t* srcVectorPtr);
192 
193 
194 /* =============================================================================
195  * Pvector_copy
196  * =============================================================================
197  */
198 bool_t
199 Pvector_copy (vector_t* dstVectorPtr, vector_t* srcVectorPtr);
200 
201 
202 #define PVECTOR_ALLOC(n) Pvector_alloc(n)
203 #define PVECTOR_FREE(v) Pvector_free(v)
204 #define PVECTOR_PUSHBACK(v, data) Pvector_pushBack(v, data)
205 #define PVECTOR_POPBACK(v) vector_popBack(v)
206 #define PVECTOR_AT(v, i) vector_at(v, i)
207 #define PVECTOR_GETSIZE(v) vector_getSize(v)
208 #define PVECTOR_CLEAR(v) vector_clear(v)
209 #define PVECTOR_SORT(v, cmp) vector_sort(v, cmp)
210 #define PVECTOR_COPY(dst, src) Pvector_copy(dst, src)
211 
212 
213 #ifdef __cplusplus
214 }
215 #endif
216 
217 
218 #endif /* VECTOR_H */
219 
220 
221 /* =============================================================================
222  *
223  * End of vector.h
224  *
225  * =============================================================================
226  */
Definition: vector.h:85
void vector_free(vector_t *vectorPtr)
Definition: vector.c:137
vector_t * Pvector_alloc(long initCapacity)
Definition: vector.c:112
vector_t * vector_alloc(long initCapacity)
Definition: vector.c:86
struct vector vector_t
int bool_t
Definition: portable_defns.h:32
void ** elements
Definition: vector.h:88
long size
Definition: vector.h:86
void vector_sort(vector_t *vectorPtr, int(*compare)(const void *, const void *))
Definition: vector.c:276
void Pvector_free(vector_t *vectorPtr)
Definition: vector.c:149
void * vector_at(vector_t *vectorPtr, long i)
Definition: vector.c:162
bool_t vector_copy(vector_t *dstVectorPtr, vector_t *srcVectorPtr)
Definition: vector.c:288
long vector_getSize(vector_t *vectorPtr)
Definition: vector.c:251
void vector_clear(vector_t *vectorPtr)
Definition: vector.c:262
void * vector_popBack(vector_t *vectorPtr)
Definition: vector.c:236
bool_t vector_pushBack(vector_t *vectorPtr, void *dataPtr)
Definition: vector.c:178
long capacity
Definition: vector.h:87
bool_t Pvector_pushBack(vector_t *vectorPtr, void *dataPtr)
Definition: vector.c:207
bool_t Pvector_copy(vector_t *dstVectorPtr, vector_t *srcVectorPtr)
Definition: vector.c:317