import project 3 files; added blending
[chaz/rasterize] / array.c
1
2 /*
3 * CS5600 University of Utah
4 * Charles McGarvey
5 * mcgarvey@eng.utah.edu
6 */
7
8 #include "array.h"
9
10
11 array_t* array_alloc2(size_t size, size_t capacity)
12 {
13 array_t* v = mem_alloc(sizeof(array_t));
14 capacity = MAX(capacity, ARRAY_CAPACITY_MIN);
15 v->arr = mem_alloc(size * capacity);
16 v->cap = capacity;
17 v->len = 0;
18 v->siz = size;
19 return v;
20 }
21
22
23 void array_reserve(array_t* v, size_t s)
24 {
25 assert(v && v->arr);
26 if (v->cap < s) {
27 size_t cap = MAX(s + ARRAY_CAPACITY_DEFAULT, ARRAY_CAPACITY_MIN);
28 void* arr = mem_realloc(v->arr, v->siz * cap);
29 v->arr = arr;
30 v->cap = cap;
31 }
32 }
33
34 void array_done(array_t* v)
35 {
36 assert(v && v->arr);
37 if (v->len < v->cap) {
38 size_t cap = MAX(v->len, ARRAY_CAPACITY_MIN);
39 void* arr = mem_realloc(v->arr, v->siz * cap);
40 v->arr = arr;
41 v->cap = cap;
42 }
43 }
44
45
46 void array_call(const array_t* v, array_call_fn_t fn)
47 {
48 array_it_t it = array_begin(v);
49 void* e;
50 while (e = array_it_next(&it)) fn(it.pos - 1, e);
51 }
52
This page took 0.039091 seconds and 4 git commands to generate.