#include <stdlib.h>
#include <string.h>
#include "nvim/memory.h"
#include "nvim/os/os_defs.h"
Go to the source code of this file.
|
#define | kv_roundup32(x) |
|
#define | KV_INITIAL_VALUE { .size = 0, .capacity = 0, .items = NULL } |
|
#define | kvec_t(type) |
|
#define | kv_init(v) ((v).size = (v).capacity = 0, (v).items = 0) |
|
#define | kv_destroy(v) |
|
#define | kv_A(v, i) ((v).items[(i)]) |
|
#define | kv_pop(v) ((v).items[--(v).size]) |
|
#define | kv_size(v) ((v).size) |
|
#define | kv_max(v) ((v).capacity) |
|
#define | kv_Z(v, i) kv_A(v, kv_size(v) - (i) - 1) |
|
#define | kv_last(v) kv_Z(v, 0) |
|
#define | kv_drop(v, n) ((v).size -= (n)) |
|
#define | kv_resize(v, s) |
|
#define | kv_resize_full(v) kv_resize(v, (v).capacity ? (v).capacity << 1 : 8) |
|
#define | kv_copy(v1, v0) |
|
#define | kv_ensure_space(v, len) |
| fit at least "len" more items More...
|
|
#define | kv_concat_len(v, data, len) |
|
#define | kv_concat(v, str) kv_concat_len(v, str, STRLEN(str)) |
|
#define | kv_splice(v1, v0) kv_concat_len(v1, (v0).items, (v0).size) |
|
#define | kv_pushp(v) |
|
#define | kv_push(v, x) (*kv_pushp(v) = (x)) |
|
#define | kv_a(v, i) |
|
#define | kv_printf(v, ...) kv_do_printf(&(v), __VA_ARGS__) |
|
#define | kvec_withinit_t(type, INIT_SIZE) |
|
#define | kvi_init(v) |
|
#define | kvi_resize(v, s) |
|
#define | kvi_resize_full(v) |
|
#define | kvi_pushp(v) |
|
#define | kvi_push(v, x) (*kvi_pushp(v) = (x)) |
|
#define | kvi_destroy(v) |
|
◆ kv_A
◆ kv_a
Value: (*(((
v).capacity <= (
size_t)(
i) \
? ((
v).capacity = (
v).
size = (
i) + 1, \
kv_roundup32((
v).capacity), \
kv_resize((
v), (
v).capacity), 0UL) \
: ((
v).size <= (size_t)(
i) \
: 0UL)), \
◆ kv_concat
◆ kv_concat_len
#define kv_concat_len |
( |
|
v, |
|
|
|
data, |
|
|
|
len |
|
) |
| |
Value: do { \
kv_ensure_space(
v,
len); \
} while (0)
◆ kv_copy
#define kv_copy |
( |
|
v1, |
|
|
|
v0 |
|
) |
| |
Value: do { \
if ((v1).capacity < (v0).
size) { \
kv_resize(v1, (v0).
size); \
} \
} while (0)
◆ kv_destroy
◆ kv_drop
#define kv_drop |
( |
|
v, |
|
|
|
n |
|
) |
| ((v).size -= (n)) |
Drop last n items from kvec without resizing
Previously spelled as (void)kv_pop(v)
, repeated n times.
- Parameters
-
[out] | v | Kvec to drop items from. |
[in] | n | Number of elements to drop. |
◆ kv_ensure_space
#define kv_ensure_space |
( |
|
v, |
|
|
|
len |
|
) |
| |
Value: do { \
(
v).capacity = (
v).size +
len; \
kv_roundup32((
v).capacity); \
kv_resize((
v), (
v).capacity); \
} \
} while (0)
fit at least "len" more items
◆ kv_init
#define kv_init |
( |
|
v | ) |
((v).size = (v).capacity = 0, (v).items = 0) |
◆ KV_INITIAL_VALUE
#define KV_INITIAL_VALUE { .size = 0, .capacity = 0, .items = NULL } |
◆ kv_last
#define kv_last |
( |
|
v | ) |
kv_Z(v, 0) |
◆ kv_max
#define kv_max |
( |
|
v | ) |
((v).capacity) |
◆ kv_pop
◆ kv_printf
◆ kv_push
◆ kv_pushp
◆ kv_resize
#define kv_resize |
( |
|
v, |
|
|
|
s |
|
) |
| |
◆ kv_resize_full
#define kv_resize_full |
( |
|
v | ) |
kv_resize(v, (v).capacity ? (v).capacity << 1 : 8) |
◆ kv_roundup32
#define kv_roundup32 |
( |
|
x | ) |
|
Value: ((--(x)), \
((x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16), \
(++(x)))
◆ kv_size
#define kv_size |
( |
|
v | ) |
((v).size) |
◆ kv_splice
◆ kv_Z
◆ kvec_t
Value: struct { \
size_t capacity; \
}
◆ kvec_withinit_t
#define kvec_withinit_t |
( |
|
type, |
|
|
|
INIT_SIZE |
|
) |
| |
Value: struct { \
size_t capacity; \
type init_array[INIT_SIZE]; \
}
Type of a vector with a few first members allocated on stack
Is compatible with kv_A, kv_pop, kv_size, kv_max, kv_last. Is not compatible with kv_resize, kv_resize_full, kv_copy, kv_push, kv_pushp, kv_a, kv_destroy.
- Parameters
-
[in] | type | Type of vector elements. |
[in] | init_size | Number of the elements in the initial array. |
◆ kvi_destroy
Value: do { \
if ((
v).
items != (
v).init_array) { \
} \
} while (0)
Free array of elements of a vector with preallocated array if needed
- Parameters
-
◆ kvi_init
Value:Initialize vector with preallocated array
- Parameters
-
[out] | v | Vector to initialize. |
◆ kvi_push
Push value to a vector with preallocated array
- Parameters
-
[out] | v | Vector to push to. |
[in] | x | Value to push. |
◆ kvi_pushp
Value:Get location where to store new element to a vector with preallocated array
- Parameters
-
[in,out] | v | Vector to push to. |
- Returns
- Pointer to the place where new value should be stored.
◆ kvi_resize
#define kvi_resize |
( |
|
v, |
|
|
|
s |
|
) |
| |
Value:
: _memcpy_free((
v).init_array, (
v).
items, \
(
v).size *
sizeof((
v).
items[0]))) \
(
v).capacity *
sizeof((
v).
items[0])))))
Resize vector with preallocated array
- Note
- May not resize to an array smaller then init_array: if requested, init_array will be used.
- Parameters
-
[out] | v | Vector to resize. |
[in] | s | New size. |
◆ kvi_resize_full
#define kvi_resize_full |
( |
|
v | ) |
|
Value: \
\
\
\
\
\
kvi_resize(
v, (
v).capacity << 1)
Resize vector with preallocated array when it is full
- Parameters
-