CVX
Loading...
Searching...
No Matches
array_iterator.h File Reference

An iterator that works on contiguous arrays. More...

Go to the source code of this file.

Data Structures

struct  cvx_container
 
struct  array_iterator
 

Typedefs

typedef struct cvx_container cvx_container
 

Enumerations

enum  cvx_flags {
  CVX_FLAG_OK = 0 , CVX_FLAG_VTAB = 1 , CVX_FLAG_WRONG_TAG = 2 , CVX_FLAG_ALLOC = 3 ,
  CVX_FLAG_EMPTY = 4 , CVX_FLAG_FULL = 5 , CVX_FLAG_RANGE = 6 , CVX_FLAG_NOT_FOUND = 7 ,
  CVX_FLAG_INVALID = 8 , CVX_FLAG_DUPLICATE = 9 , CVX_FLAG_ERROR = 10
}
 Status and error flags for the CVX library. More...
 
enum  cvx_heap_order { CVX_MAX_HEAP = 1 , CVX_MIN_HEAP = -1 }
 enum cvx_heap_order More...
 

Functions

struct array_iterator bi_start (TVal *buffer, size_t capacity, size_t count)
 
struct array_iterator bi_end (TVal *buffer, size_t capacity, size_t count)
 
_Bool bi_at_end (struct array_iterator *self)
 
_Bool bi_at_start (struct array_iterator *self)
 
void bi_to_end (struct array_iterator *self)
 
void bi_to_start (struct array_iterator *self)
 
void bi_next (struct array_iterator *self)
 
void bi_prev (struct array_iterator *self)
 
void bi_go_to (struct array_iterator *self)
 
void bi_forward (struct array_iterator *self, size_t steps)
 
void bi_backward (struct array_iterator *self, size_t steps)
 
size_t bi_index (struct array_iterator *self)
 
TVal bi_value (struct array_iterator *self)
 

Detailed Description

An iterator that works on contiguous arrays.

ITERATOR.

Author
Leonardo Vencovsky
Version
0.0.1

The implementation of the array iterator can be tuned depending on the underlying data structure. By default, this is an iterator that starts at the index 0 of an array and goes up to count. By specifying extra options, you can change the behaviour of the iterator. Only one of them can be defined.

Options

  • CIRCULAR: if defined, the pointer wraps around the array's capacity. The _start and _end functions now require an extra parameter to specify at which index the iterator starts or ends.
  • SPARSE(item): a function-like macro. If defined, the array contains "holes". This macro needs to return a boolean value that checks if the passed item is a hole or not.

Required Macros

  • V: Type name of the array (e.g. V *buffer).
  • SNAME: Prefix of all declared structs (e.g. struct SNAME, struct SNAME_vtabv, etc.).
  • PFX: Prefix of all functions, including implementation detail ones.
  • TAG: A unique integer tag that identifies this data structure.

Internally used macros

  • IT_ prefix macros: used by other data structures. Should not be used directly.
  • EMBEDDED: used by other data structures to automatically implement an iterator. When this is enabled, it changes the input macros and prefixes them all with "IT_".

Usage

for (struct darray_iter it = da_iter_start(&darr); !da_iter_at_end(&it); da_iter_next(&it))
{
printf("%s\t%s\n", da_iter_value(&it), da_iter_value(&it));
}
struct dynamic_array_iter da_iter_start(struct dynamic_array *self)
Definition dynamic_array.h:858
_Bool da_iter_at_end(struct dynamic_array_iter *self)
Definition dynamic_array.h:771
void da_iter_next(struct dynamic_array_iter *self)
Definition dynamic_array.h:795
TVal da_iter_value(struct dynamic_array_iter *self)
Definition dynamic_array.h:853
Author
Leonardo Vencovsky

An iterator that works on contiguous arrays.

Version
0.0.1

The implementation of the array iterator can be tuned depending on the underlying data structure. By default, this is an iterator that starts at the index 0 of an array and goes up to count. By specifying extra options, you can change the behaviour of the iterator. Only one of them can be defined.

Options

  • CIRCULAR: if defined, the pointer wraps around the array's capacity. The _start and _end functions now require an extra parameter to specify at which index the iterator starts or ends.
  • SPARSE(item): a function-like macro. If defined, the array contains "holes". This macro needs to return a boolean value that checks if the passed item is a hole or not.

Required Macros

  • V: Type name of the array (e.g. V *buffer).
  • SNAME: Prefix of all declared structs (e.g. struct SNAME, struct SNAME_vtabv, etc.).
  • PFX: Prefix of all functions, including implementation detail ones.
  • TAG: A unique integer tag that identifies this data structure.

Internally used macros

  • IT_ prefix macros: used by other data structures. Should not be used directly.
  • EMBEDDED: used by other data structures to automatically implement an iterator. When this is enabled, it changes the input macros and prefixes them all with "IT_".

Usage

for (struct darray_iter it = da_iter_start(&darr); !da_iter_at_end(&it); da_iter_next(&it))
{
printf("%s\t%s\n", da_iter_value(&it), da_iter_value(&it));
}
Author
Leonardo Vencovsky

An iterator that works on contiguous arrays.

Version
0.0.1

The implementation of the array iterator can be tuned depending on the underlying data structure. By default, this is an iterator that starts at the index 0 of an array and goes up to count. By specifying extra options, you can change the behaviour of the iterator. Only one of them can be defined.

Options

  • CIRCULAR: if defined, the pointer wraps around the array's capacity. The _start and _end functions now require an extra parameter to specify at which index the iterator starts or ends.
  • SPARSE(item): a function-like macro. If defined, the array contains "holes". This macro needs to return a boolean value that checks if the passed item is a hole or not.

Required Macros

  • V: Type name of the array (e.g. V *buffer).
  • SNAME: Prefix of all declared structs (e.g. struct SNAME, struct SNAME_vtabv, etc.).
  • PFX: Prefix of all functions, including implementation detail ones.
  • TAG: A unique integer tag that identifies this data structure.

Internally used macros

  • IT_ prefix macros: used by other data structures. Should not be used directly.
  • EMBEDDED: used by other data structures to automatically implement an iterator. When this is enabled, it changes the input macros and prefixes them all with "IT_".

Usage

for (struct darray_iter it = da_iter_start(&darr); !da_iter_at_end(&it); da_iter_next(&it))
{
printf("%s\t%s\n", da_iter_value(&it), da_iter_value(&it));
}

Typedef Documentation

◆ cvx_container

typedef struct cvx_container cvx_container

Enumeration Type Documentation

◆ cvx_flags

enum cvx_flags

Status and error flags for the CVX library.

Error Handling

Enumerator
CVX_FLAG_OK 

No errors.

CVX_FLAG_VTAB 

Required vtab function was not provided.

CVX_FLAG_WRONG_TAG 

Tags are checked so you don't pass the wrong struct to a function.

CVX_FLAG_ALLOC 

Allocation failed.

CVX_FLAG_EMPTY 

Operation can not proceed because the container is empty.

CVX_FLAG_FULL 

When a container that doesn't resize is full.

CVX_FLAG_RANGE 

Index out of range.

CVX_FLAG_NOT_FOUND 

Key or value not found.

CVX_FLAG_INVALID 

Invalid argument or operation.

CVX_FLAG_DUPLICATE 

Duplicate key or value.

CVX_FLAG_ERROR 

Generic error, or unknown error.

◆ cvx_heap_order

enum cvx_heap_order

Defines the two possible heaps:

  • Max Heap has the greatest element at the top
  • Min Heap has the smallest element at the top
Enumerator
CVX_MAX_HEAP 
CVX_MIN_HEAP 

Function Documentation

◆ bi_at_end()

_Bool bi_at_end ( struct array_iterator self)

◆ bi_at_start()

_Bool bi_at_start ( struct array_iterator self)

◆ bi_backward()

void bi_backward ( struct array_iterator self,
size_t  steps 
)

◆ bi_end()

struct array_iterator bi_end ( TVal *  buffer,
size_t  capacity,
size_t  count 
)

◆ bi_forward()

void bi_forward ( struct array_iterator self,
size_t  steps 
)

◆ bi_go_to()

void bi_go_to ( struct array_iterator self)

◆ bi_index()

size_t bi_index ( struct array_iterator self)

◆ bi_next()

void bi_next ( struct array_iterator self)

◆ bi_prev()

void bi_prev ( struct array_iterator self)

◆ bi_start()

struct array_iterator bi_start ( TVal *  buffer,
size_t  capacity,
size_t  count 
)

◆ bi_to_end()

void bi_to_end ( struct array_iterator self)

◆ bi_to_start()

void bi_to_start ( struct array_iterator self)

◆ bi_value()

TVal bi_value ( struct array_iterator self)