nxt_vector.h (0:a63ceefd6ab0) nxt_vector.h (98:4077decf847b)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#ifndef _NXT_VECTOR_H_INCLUDED_
8#define _NXT_VECTOR_H_INCLUDED_
9
10
11typedef enum {
12 NXT_VECTOR_INITED = 0,
13 NXT_VECTOR_DESCRETE,
14 NXT_VECTOR_EMBEDDED,
15} nxt_vector_type_t;
16
17
18typedef struct {
19 void *start;
20 /*
21 * A vector can hold no more than 65536 items.
22 * The item size is no more than 64K.
23 */
24 uint16_t items;
25 uint16_t avalaible;
26 uint16_t item_size;
27 nxt_vector_type_t type:8;
28} nxt_vector_t;
29
30
31NXT_EXPORT nxt_vector_t *nxt_vector_create(nxt_uint_t items, size_t item_size,
32 const nxt_mem_proto_t *proto, void *pool);
33NXT_EXPORT void *nxt_vector_init(nxt_vector_t *vector, nxt_uint_t items,
34 size_t item_size, const nxt_mem_proto_t *proto, void *pool);
35NXT_EXPORT void nxt_vector_destroy(nxt_vector_t *vector,
36 const nxt_mem_proto_t *proto, void *pool);
37NXT_EXPORT void *nxt_vector_add(nxt_vector_t *vector,
38 const nxt_mem_proto_t *proto, void *pool);
39NXT_EXPORT void *nxt_vector_zero_add(nxt_vector_t *vector,
40 const nxt_mem_proto_t *proto, void *pool);
41NXT_EXPORT void nxt_vector_remove(nxt_vector_t *vector, void *item);
42
43
44#define \
45nxt_vector_last(vector) \
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#ifndef _NXT_VECTOR_H_INCLUDED_
8#define _NXT_VECTOR_H_INCLUDED_
9
10
11typedef enum {
12 NXT_VECTOR_INITED = 0,
13 NXT_VECTOR_DESCRETE,
14 NXT_VECTOR_EMBEDDED,
15} nxt_vector_type_t;
16
17
18typedef struct {
19 void *start;
20 /*
21 * A vector can hold no more than 65536 items.
22 * The item size is no more than 64K.
23 */
24 uint16_t items;
25 uint16_t avalaible;
26 uint16_t item_size;
27 nxt_vector_type_t type:8;
28} nxt_vector_t;
29
30
31NXT_EXPORT nxt_vector_t *nxt_vector_create(nxt_uint_t items, size_t item_size,
32 const nxt_mem_proto_t *proto, void *pool);
33NXT_EXPORT void *nxt_vector_init(nxt_vector_t *vector, nxt_uint_t items,
34 size_t item_size, const nxt_mem_proto_t *proto, void *pool);
35NXT_EXPORT void nxt_vector_destroy(nxt_vector_t *vector,
36 const nxt_mem_proto_t *proto, void *pool);
37NXT_EXPORT void *nxt_vector_add(nxt_vector_t *vector,
38 const nxt_mem_proto_t *proto, void *pool);
39NXT_EXPORT void *nxt_vector_zero_add(nxt_vector_t *vector,
40 const nxt_mem_proto_t *proto, void *pool);
41NXT_EXPORT void nxt_vector_remove(nxt_vector_t *vector, void *item);
42
43
44#define \
45nxt_vector_last(vector) \
46 ((void *) \
47 ((char *) (vector)->start \
48 + (vector)->item_size * ((vector)->items - 1)))
46 nxt_pointer_to((vector)->start, \
47 (vector)->item_size * ((vector)->items - 1))
49
50
51#define \
52nxt_vector_reset(vector) \
53 (vector)->items = 0;
54
55
56#define \
57nxt_vector_is_empty(vector) \
58 ((vector)->items == 0)
59
60
61nxt_inline void *
62nxt_vector_remove_last(nxt_vector_t *vector)
63{
64 vector->items--;
48
49
50#define \
51nxt_vector_reset(vector) \
52 (vector)->items = 0;
53
54
55#define \
56nxt_vector_is_empty(vector) \
57 ((vector)->items == 0)
58
59
60nxt_inline void *
61nxt_vector_remove_last(nxt_vector_t *vector)
62{
63 vector->items--;
65 return (char *) vector->start + vector->item_size * vector->items;
64 return nxt_pointer_to(vector->start, vector->item_size * vector->items);
66}
67
68
69#endif /* _NXT_VECTOR_H_INCLUDED_ */
65}
66
67
68#endif /* _NXT_VECTOR_H_INCLUDED_ */