libamxc
1.10.3
C Generic Data Containers
|
A stack implementation based on Array. More...
Typedefs | |
typedef amxc_array_t | amxc_astack_t |
The array stack structure. More... | |
typedef amxc_array_it_t | amxc_astack_it_t |
The array stack iterator structure. More... | |
typedef amxc_array_it_delete_t | amxc_astack_it_delete_t |
Definition of the item delete function. More... | |
Functions | |
AMXC_INLINE int | amxc_astack_new (amxc_astack_t **astack) |
Allocates an array stack. More... | |
AMXC_INLINE void | amxc_astack_delete (amxc_astack_t **astack, amxc_astack_it_delete_t func) |
Frees the previously allocated array stack. More... | |
AMXC_INLINE int | amxc_astack_init (amxc_astack_t *const astack) |
Initializes an array stack. More... | |
AMXC_INLINE void | amxc_astack_clean (amxc_astack_t *const astack, amxc_astack_it_delete_t func) |
Removes all items from the array stack. More... | |
AMXC_INLINE amxc_astack_it_t * | amxc_astack_push (amxc_astack_t *const astack, void *data) |
Adds an item to the array stack. More... | |
AMXC_INLINE void * | amxc_astack_pop (amxc_astack_t *const astack) |
Removes the last added data from the stack. More... | |
AMXC_INLINE void * | amxc_astack_peek (amxc_astack_t *const astack) |
Peek the top of the stack, without removing. More... | |
AMXC_INLINE size_t | amxc_astack_size (const amxc_astack_t *const astack) |
Calculate the number of items on the stack, expressed in number of items. More... | |
AMXC_INLINE bool | amxc_astack_is_empty (const amxc_astack_t *const astack) |
Checks that the array stack is empty. More... | |
A stack implementation based on Array.
The basic operators on a stack are push and pop.
Using the Array a stack can be created which has a initial size and can grow when needed.
It is possible to peek at the top of the stack, without removing the element, using amxc_astack_peek
When pushing data on the stack, the data will be put in the first empty bucket, if no empty bucket is available, the stack (bucket array) will grow.
When popping data, the last non empty bucket is returned.
Definition of the item delete function.
A pointer to a delete function is used in the following functions amxc_astack_delete, amxc_astack_clean
Definition at line 115 of file amxc_astack.h.
typedef amxc_array_it_t amxc_astack_it_t |
The array stack iterator structure.
Definition at line 105 of file amxc_astack.h.
typedef amxc_array_t amxc_astack_t |
The array stack structure.
Definition at line 98 of file amxc_astack.h.
AMXC_INLINE void amxc_astack_clean | ( | amxc_astack_t *const | astack, |
amxc_astack_it_delete_t | func | ||
) |
Removes all items from the array stack.
Removes all items from the array stack. If a delete function is provided, it is called for each item on the stack.
astack | a pointer to the array stack structure |
func | a pointer to a function that is called to free each item in the array stack |
Definition at line 205 of file amxc_astack.h.
AMXC_INLINE void amxc_astack_delete | ( | amxc_astack_t ** | astack, |
amxc_astack_it_delete_t | func | ||
) |
Frees the previously allocated array stack.
Removes all items from the array stack, if a delete function is provided, it is called for each item on the stack.
Frees the allocated memory and sets the pointer to NULL.
astack | a pointer to the location where the pointer to the array stack is be stored |
func | pointer to a function that is called to free each item in the array stack |
Definition at line 161 of file amxc_astack.h.
AMXC_INLINE int amxc_astack_init | ( | amxc_astack_t *const | astack | ) |
Initializes an array stack.
Initializes the array stack structure. All pointers are reset to NULL. This function is typically called for array stacks that are on the stack. Allocating and initializing an array stack on the heap can be done using amxc_astack_new
astack | a pointer to the array stack structure. |
Definition at line 188 of file amxc_astack.h.
AMXC_INLINE bool amxc_astack_is_empty | ( | const amxc_astack_t *const | astack | ) |
Checks that the array stack is empty.
astack | a pointer to the array stack structure |
Definition at line 286 of file amxc_astack.h.
AMXC_INLINE int amxc_astack_new | ( | amxc_astack_t ** | astack | ) |
Allocates an array stack.
Allocates and initializes memory to store an array stack. This function allocates memory from the heap, if an array stack is on the stack, it can be initialized using function amxc_astack_init
astack | a pointer to the location where the pointer to the new array stack can be stored |
Definition at line 137 of file amxc_astack.h.
AMXC_INLINE void* amxc_astack_peek | ( | amxc_astack_t *const | astack | ) |
Peek the top of the stack, without removing.
astack | a pointer to the array stack structure |
Definition at line 255 of file amxc_astack.h.
AMXC_INLINE void* amxc_astack_pop | ( | amxc_astack_t *const | astack | ) |
Removes the last added data from the stack.
astack | a pointer to the array stack structure |
Definition at line 239 of file amxc_astack.h.
AMXC_INLINE amxc_astack_it_t* amxc_astack_push | ( | amxc_astack_t *const | astack, |
void * | data | ||
) |
Adds an item to the array stack.
If the item is already in a stack, it is removed from that stack.
astack | a pointer to the array stack structure |
data | a pointer to the data that needs to be added to the stack |
Definition at line 223 of file amxc_astack.h.
AMXC_INLINE size_t amxc_astack_size | ( | const amxc_astack_t *const | astack | ) |
Calculate the number of items on the stack, expressed in number of items.
astack | a pointer to the array stack structure |
Definition at line 270 of file amxc_astack.h.