Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions cvector.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/*
* Copyright (c) 2015 Evan Teran
*
* License: The MIT License (MIT)
*/

#ifndef CVECTOR_H_
#define CVECTOR_H_

/* cvector heap implemented using C library malloc() */
/**
* @copyright Copyright (c) 2015 Evan Teran,
* License: The MIT License (MIT)
* @brief cvector heap implemented using C library malloc()
* @file cvector.h
*/

/* in case C library malloc() needs extra protection,
* allow these defines to be overridden.
Expand Down Expand Up @@ -61,18 +59,19 @@ typedef struct cvector_metadata_t {

/**
* @brief cvector_vector_type - The vector type used in this library
* @param type The type of vector to act on.
*/
#define cvector_vector_type(type) type *

/**
* @brief cvector - Syntactic sugar to retrieve a vector type
*
* @param type The type of vector to act on.
*/
#define cvector(type) cvector_vector_type(type)

/*
/**
* @brief cvector_iterator - The iterator type used for cvector
* @param type The type of iterator to act on.
*/
#define cvector_iterator(type) cvector_vector_type(type)

Expand Down Expand Up @@ -144,8 +143,8 @@ typedef struct cvector_metadata_t {
} \
} while (0)

/*
* @brief cvector_init - Initialize a vector. The vector must be NULL for this to do anything.
/**
* @brief cvector_init - Initialize a vector. The vector must be NULL for this to do anything.
* @param vec - the vector
* @param capacity - vector capacity to reserve
* @param elem_destructor_fn - element destructor function
Expand Down Expand Up @@ -364,7 +363,7 @@ typedef struct cvector_metadata_t {
/**
* @brief cvector_set_size - For internal use, sets the size variable of the vector
* @param vec - the vector
* @param size - the new capacity to set
* @param _size - the new capacity to set
* @return void
* @internal
*/
Expand All @@ -390,7 +389,7 @@ typedef struct cvector_metadata_t {
} while (0)

/**
* @brief cvector_grow - For internal use, ensures that the vector is at least <count> elements big
* @brief cvector_grow - For internal use, ensures that the vector is at least `count` elements big
* @param vec - the vector
* @param count - the new capacity to set
* @return void
Expand Down Expand Up @@ -438,13 +437,15 @@ typedef struct cvector_metadata_t {

/**
* @brief cvector_front - returns a reference to the first element in the vector. Unlike member cvector_begin, which returns an iterator to this same element, this function returns a direct reference.
* @param vec - the vector
* @return a reference to the first element in the vector container.
*/
#define cvector_front(vec) \
((vec) ? ((cvector_size(vec) > 0) ? cvector_at(vec, 0) : NULL) : NULL)

/**
* @brief cvector_back - returns a reference to the last element in the vector.Unlike member cvector_end, which returns an iterator just past this element, this function returns a direct reference.
* @param vec - the vector
* @return a reference to the last element in the vector.
*/
#define cvector_back(vec) \
Expand Down
6 changes: 6 additions & 0 deletions cvector_utils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#ifndef CVECTOR_UTILS_H_
#define CVECTOR_UTILS_H_
/**
* @copyright Copyright (c) 2022 Evan Teran,
* License: The MIT License (MIT)
* @brief extends the cvector library
* @file cvector_utils.h
*/

/**
* @brief cvector_for_each_in - for header to iterate over vector each element's address
Expand Down
Loading