Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 89 lines (79 sloc) 3.727 kb
91b4e62 Michael Truog Make the NIF more robust. Guard non-reentrant ZeroMQ sockets. Provide ...
okeuday authored
1 /* -*- coding: utf-8; Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
2 * ex: set softtabstop=4 tabstop=4 shiftwidth=4 expandtab fileencoding=utf-8:
3 *
4 * BSD LICENSE
5 *
6 * Copyright (c) 2011, Michael Truog <mjtruog at gmail dot com>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * * All advertising materials mentioning features or use of this
19 * software must display the following acknowledgment:
20 * This product includes software developed by Michael Truog
21 * * The name of the author may not be used to endorse or promote
22 * products derived from this software without specific prior
23 * written permission
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
26 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
27 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38 * DAMAGE.
39 */
40 #ifndef VECTOR_H
41 #define VECTOR_H
42
a2b0693 Evax Software Use proper size_t definition
evax authored
43 #include <stddef.h>
91b4e62 Michael Truog Make the NIF more robust. Guard non-reentrant ZeroMQ sockets. Provide ...
okeuday authored
44
45 typedef struct {
46
47 size_t allocation_increment;
48 size_t allocation_size;
49 size_t allocation_size_max;
50 void * p;
51
52 size_t element_size;
53 size_t count;
54
55 } vector_t;
56
57 #define vector_initialize_linear(TYPE, V, COUNT_INCR, COUNT, COUNT_MAX) \
58 vector_initialize(V, COUNT_INCR * sizeof(TYPE), COUNT * sizeof(TYPE), \
59 COUNT_MAX * sizeof(TYPE), sizeof(TYPE))
60 #define vector_initialize_pow2(TYPE, V, COUNT, COUNT_MAX) \
61 vector_initialize(V, 0, COUNT * sizeof(TYPE), \
62 COUNT_MAX * sizeof(TYPE), sizeof(TYPE))
63 int vector_initialize(vector_t * v,
64 size_t allocation_increment,
65 size_t allocation_size,
66 size_t allocation_size_max,
67 size_t element_size);
68 void vector_destroy(vector_t * v);
69 int vector_reserve(vector_t * v, size_t count);
70 #define vector_copy_all(DST, SRC) vector_copy(DST, SRC, 0, 0, 0)
71 int vector_copy(vector_t * v_dst, vector_t * v_src,
72 size_t i_src, size_t count_src, size_t i_dst);
73 int vector_move(vector_t * v, size_t i_dst, size_t i_src, size_t count_src);
74 #define vector_append(TYPE, V, OBJ) \
75 vector_append_element(V, OBJ, sizeof(TYPE))
76 int vector_append_element(vector_t * v, void * p, size_t size);
77 int vector_remove(vector_t * v, size_t i);
78 #define vector_has(V, I) ((I) < (V)->count)
79 #define vector_p(TYPE, V) ((TYPE *) ((V)->p))
80 #define vector_get(TYPE, V, I) (&(vector_p(TYPE, V)[I]))
81 #define vector_count(V) ((V)->count)
82 #define vector_size(V) ((V)->allocation_size)
83
84 #define VECTOR_FAILURE -1
85 #define VECTOR_SUCCESS 0
86
87 #endif /* VECTOR_H */
88
Something went wrong with that request. Please try again.