Vector 0.0.2
Loading...
Searching...
No Matches
vector.c File Reference

Implementation of the vector. More...

#include "vector.h"
Include dependency graph for vector.c:

Go to the source code of this file.

Data Structures

struct  vector_t
 Vector control structure type. More...
 

Functions

static size_t calculate_alloc_size (const size_t element_size, const size_t capacity, const size_t allocator_size, const size_t ext_header_size)
 Calculates allocation size for the vector.
 
static void * get_allocator (const vector_t *const vector)
 Access allocator region of the vector.
 
static void * binary_find (const vector_t *const vector, const void *const value, const size_t start, const size_t end, const compare_t cmp, void *const param)
 Performs binary search on a vectors range.
 
static ssize_t binary_find_index (const vector_t *const vector, const void *const value, const size_t start, const size_t end, const compare_t cmp, void *param)
 Performs binary search on a vectors range.
 
vector_tvector_create_ (const vector_opts_t *const opts)
 Vector contructor.
 
void vector_destroy (vector_t *const vector)
 Deallocates vector.
 
vector_tvector_clone (const vector_t *const vector)
 Duplicates a vector.
 
vector_status_t vector_resize (vector_t **const vector, const size_t capacity, const vector_status_t error)
 Performs allocation resize.
 
void * vector_get_ext_header (const vector_t *const vector)
 Provides a location where user can put a header for the derived class.
 
size_t vector_ext_header_size (const vector_t *const vector)
 Retrieves extended header size.
 
size_t vector_data_offset (const vector_t *const vector)
 Compute offset from vector_t::memory to first element.
 
alloc_opts_t vector_alloc_opts (const vector_t *const vector)
 Access allocator options.
 
size_t vector_element_size (const vector_t *const vector)
 Reports current element size.
 
size_t vector_capacity (const vector_t *const vector)
 Reports current capacity of the vector.
 
size_t vector_capacity_bytes (const vector_t *const vector)
 Reports current capacity of the vector in bytes.
 
void * vector_linear_find (const vector_t *const vector, const size_t limit, const predicate_t predicate, void *param)
 Simple linear search for unordered data.
 
void * vector_binary_find (const vector_t *const vector, const void *const value, const size_t limit, const compare_t cmp, void *param)
 Run binary search on the vector.
 
ssize_t vector_binary_find_index (const vector_t *const vector, const void *const value, const size_t limit, const compare_t cmp, void *const param)
 Run binary search on the vector.
 
char * vector_data (const vector_t *const vector)
 Gives a pointer to a location where elements' data begins.
 
void * vector_get (const vector_t *const vector, const size_t index)
 Returns pointer for the element at index.
 
void vector_set (vector_t *const vector, const size_t index, const void *const value)
 Sets element at given index to a value.
 
void vector_set_zero (vector_t *const vector, const size_t index)
 Sets element at given index to a zero value.
 
void vector_copy (const vector_t *const vector, char *const dest, const size_t offset, const size_t length)
 Copy element range to other location.
 
void vector_move (const vector_t *const vector, char *dest, const size_t offset, const size_t length)
 Moves range of the vector elements to another location.
 
void vector_part_copy (const vector_t *const vector, char *dest, const size_t offset, const size_t length, const size_t part_offset, const size_t part_length)
 Partial copying.
 
void vector_spread (vector_t *const vector, const size_t index, const size_t amount)
 Duplicates existing element across range.
 
void vector_shift (vector_t *const vector, const size_t offset, const size_t length, const ssize_t shift)
 Shift range of elements.
 
void vector_swap (vector_t *const vector, const size_t index_a, const size_t index_b)
 Swaps values of elements designated by indicies.
 
int vector_foreach (const vector_t *const vector, const size_t limit, const foreach_t func, void *const param)
 Perform immutable action on each element of the vector.
 
int vector_aggregate (const vector_t *const vector, const size_t limit, const aggregate_t func, void *const acc, void *const param)
 Perform immutable accamulating action on each element of the vector.
 
int vector_transform (vector_t *const vector, const size_t limit, const transform_t func, void *const param)
 Perform mutable transformation on each element of the vector.
 
size_t calc_aligned_size (const size_t size, const size_t alignment)
 Function calculates size of the element while respecting requirement for alignment.
 
ssize_t cmp_lex_asc (const void *value, const void *element, void *param)
 Performs comparison in lexicographical ascending order.
 
ssize_t cmp_lex_dsc (const void *value, const void *element, void *param)
 Performs comparison in lexicographical descending order.
 

Detailed Description

Implementation of the vector.

Author
Evgeni Semenov

Definition in file vector.c.

Function Documentation

◆ calculate_alloc_size()

static size_t calculate_alloc_size ( const size_t element_size,
const size_t capacity,
const size_t allocator_size,
const size_t ext_header_size )
static

Calculates allocation size for the vector.

Definition at line 467 of file vector.c.

◆ get_allocator()

static void * get_allocator ( const vector_t *const vector)
static

Access allocator region of the vector.

Definition at line 479 of file vector.c.

◆ binary_find()

static void * binary_find ( const vector_t *const vector,
const void *const value,
const size_t start,
const size_t end,
const compare_t cmp,
void *const param )
static

Performs binary search on a vectors range.

Returns
pointer to the found element on success or NULL otherwise.

Definition at line 486 of file vector.c.

Here is the call graph for this function:

◆ binary_find_index()

static ssize_t binary_find_index ( const vector_t *const vector,
const void *const value,
const size_t start,
const size_t end,
const compare_t cmp,
void * param )
static

Performs binary search on a vectors range.

Returns
index of the found element on success or -1 otherwise.

Definition at line 515 of file vector.c.

Here is the call graph for this function: