libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
vector.h
Go to the documentation of this file.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license in the file COPYING
10 * or http://www.opensource.org/licenses/CDDL-1.0.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file COPYING.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2024 Saso Kiselkov. All rights reserved.
24 */
50#ifndef _ACF_UTILS_VECTOR_H_
51#define _ACF_UTILS_VECTOR_H_
52
53#include <acfutils/optional.h>
54#include <acfutils/sysmacros.h>
55
56#include "vector_impl.h"
57
58#ifdef __cplusplus
59extern "C" {
60#endif
61
81void vector_create_cap(vector_t REQ_PTR(v), size_t cap_hint);
98size_t vector_len(const vector_t REQ_PTR(v));
106void *vector_get(const vector_t REQ_PTR(v), size_t index);
130opt_size_t vector_find(const vector_t REQ_PTR(v), const void *item);
141void vector_insert(vector_t REQ_PTR(v), void *elem, size_t index);
159void *vector_replace(vector_t REQ_PTR(v), void *new_elem, size_t index);
172void *vector_remove(vector_t REQ_PTR(v), size_t index);
231size_t vector_cap(const vector_t REQ_PTR(v));
255 int (*sort_func)(const void *a, const void *b));
270 int (*sort_func)(const void *a, const void *b, void *userinfo),
271 void *userinfo);
272
273#ifdef __cplusplus
274}
275#endif
276
277#endif /* _ACF_UTILS_VECTOR_H_ */
An optional type for wrapping a uint64_t value.
Definition optional.h:741
#define REQ_PTR(x)
Definition sysmacros.h:334
void vector_move_all(vector_t REQ_PTR(src), vector_t REQ_PTR(dest))
Moves all elements from the src vector to the dest vector.
size_t vector_len(const vector_t REQ_PTR(v))
Returns the current number of elements contained inside the vector.
void vector_create(vector_t REQ_PTR(v))
Initializes a new vector_t to a blank state, with zero starting capacity.
void * vector_remove_tail(vector_t REQ_PTR(v))
Removes and returns the last element in a vector, if any.
void * vector_remove(vector_t REQ_PTR(v), size_t index)
Removes an element from the vector at a given index.
void vector_sort(vector_t REQ_PTR(v), int(*sort_func)(const void *a, const void *b))
Sorts a vector using the and a sorting predicate.
void * vector_replace(vector_t REQ_PTR(v), void *new_elem, size_t index)
Replaces an element in the vector in-place.
void vector_insert(vector_t REQ_PTR(v), void *elem, size_t index)
Inserts a new element into the vector at a given index.
size_t vector_shrink(vector_t REQ_PTR(v))
Orders the vector to shrink to the nearest power-of-2 capacity suitable to hold its current contents.
void vector_insert_tail(vector_t REQ_PTR(v), void *elem)
Inserts a new element at the tail of the vector.
void * vector_tail(const vector_t REQ_PTR(v))
Retrieves the element at the tail of the vector, if any.
void * vector_remove_head(vector_t REQ_PTR(v))
Removes and returns the first element in a vector, if any.
void vector_sort_r(vector_t REQ_PTR(v), int(*sort_func)(const void *a, const void *b, void *userinfo), void *userinfo)
Sorts a vector using the and a thread-safe sorting predicate.
void * vector_get(const vector_t REQ_PTR(v), size_t index)
Retrieves elements within the vector.
opt_size_t vector_find(const vector_t REQ_PTR(v), const void *item)
Locates an element in the vector by value.
void vector_create_cap(vector_t REQ_PTR(v), size_t cap_hint)
Initializes a new vector_t with a capacity hint.
void * vector_head(const vector_t REQ_PTR(v))
Retrieves the element at the head of the vector, if any.
size_t vector_cap(const vector_t REQ_PTR(v))
Returns the current element capacity of the vector.
void vector_destroy(vector_t REQ_PTR(v))
Destroys a vector previously created using vector_create().