1/* 2 * Copyright 2016, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(D61_BSD) 11 */ 12 13#ifndef _CVECTOR_H_ 14#define _CVECTOR_H_ 15 16#define CVECTOR_INIT_SIZE 4 17#define CVECTOR_RESIZE_CHECK_FREQ 16 18 19#ifndef kmalloc 20 #include <stdlib.h> 21 #include <stdint.h> 22 #define kmalloc malloc 23 #define krealloc realloc 24 #define kfree free 25#endif 26 27typedef void* cvector_item_t; 28 29typedef struct cvector_s { 30 cvector_item_t* data; 31 size_t size; 32 size_t count; 33 int32_t nextResize; 34} cvector_t; 35 36void cvector_init(cvector_t *v); 37 38int cvector_add(cvector_t *v, cvector_item_t e); 39 40static inline size_t cvector_count(cvector_t *v) { 41 return v->count; 42} 43 44void cvector_set(cvector_t *v, uint32_t index, cvector_item_t e); 45 46cvector_item_t cvector_get(cvector_t *v, int index); 47 48void cvector_delete(cvector_t *v, int index); 49 50void cvector_free(cvector_t *v); 51 52void cvector_reset(cvector_t *v); 53 54#endif /* _CVECTOR_H_ */ 55