Lines Matching defs:vector

27 #include "include/vector.h"
30 struct vector *vector,
35 vector->container = NULL;
43 vector->container = kcalloc(capacity, struct_size, GFP_KERNEL);
44 if (vector->container == NULL)
46 vector->capacity = capacity;
47 vector->struct_size = struct_size;
48 vector->count = 0;
49 vector->ctx = ctx;
53 static bool dal_vector_presized_costruct(struct vector *vector,
61 vector->container = NULL;
69 vector->container = kcalloc(count, struct_size, GFP_KERNEL);
71 if (vector->container == NULL)
80 vector->container + i * struct_size,
85 vector->capacity = count;
86 vector->struct_size = struct_size;
87 vector->count = count;
91 struct vector *dal_vector_presized_create(
97 struct vector *vector = kzalloc(sizeof(struct vector), GFP_KERNEL);
99 if (vector == NULL)
103 vector, ctx, size, initial_value, struct_size))
104 return vector;
107 kfree(vector);
111 struct vector *dal_vector_create(
116 struct vector *vector = kzalloc(sizeof(struct vector), GFP_KERNEL);
118 if (vector == NULL)
121 if (dal_vector_construct(vector, ctx, capacity, struct_size))
122 return vector;
125 kfree(vector);
130 struct vector *vector)
132 kfree(vector->container);
133 vector->count = 0;
134 vector->capacity = 0;
138 struct vector **vector)
140 if (vector == NULL || *vector == NULL)
142 dal_vector_destruct(*vector);
143 kfree(*vector);
144 *vector = NULL;
148 const struct vector *vector)
150 return vector->count;
154 const struct vector *vector,
157 if (vector->container == NULL || index >= vector->count)
159 return vector->container + (index * vector->struct_size);
163 struct vector *vector,
166 if (index >= vector->count)
169 if (index != vector->count - 1)
171 vector->container + (index * vector->struct_size),
172 vector->container + ((index + 1) * vector->struct_size),
173 (vector->count - index - 1) * vector->struct_size);
174 vector->count -= 1;
180 const struct vector *vector,
184 void *where = dal_vector_at_index(vector, index);
193 vector->struct_size);
203 struct vector *vector,
209 if (vector->count == vector->capacity) {
211 vector,
212 calc_increased_capacity(vector->capacity)))
216 insert_address = vector->container + (vector->struct_size * position);
218 if (vector->count && position < vector->count)
220 insert_address + vector->struct_size,
222 vector->struct_size * (vector->count - position));
227 vector->struct_size);
229 vector->count++;
235 struct vector *vector,
238 return dal_vector_insert_at(vector, item, vector->count);
241 struct vector *dal_vector_clone(
242 const struct vector *vector)
244 struct vector *vec_cloned;
247 /* create new vector */
248 count = dal_vector_get_count(vector);
251 /* when count is 0 we still want to create clone of the vector
254 vector->ctx,
255 vector->capacity,
256 vector->struct_size);
259 * original vector was created.
260 * The owner of original vector must know how to treat the new
261 * vector - as "presized" or as "regular".
262 * But from vector point of view it doesn't matter. */
263 vec_cloned = dal_vector_presized_create(vector->ctx, count,
265 vector->struct_size);
272 /* copy vector's data */
273 memmove(vec_cloned->container, vector->container,
279 uint32_t dal_vector_capacity(const struct vector *vector)
281 return vector->capacity;
284 bool dal_vector_reserve(struct vector *vector, uint32_t capacity)
288 if (capacity <= vector->capacity)
291 new_container = krealloc(vector->container,
292 capacity * vector->struct_size, GFP_KERNEL);
295 vector->container = new_container;
296 vector->capacity = capacity;
303 void dal_vector_clear(struct vector *vector)
305 vector->count = 0;