librdesc
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025-2026 Metehan Selvi <me@metehanselvi.com>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
24#ifndef RDESC_STACK_H
25#define RDESC_STACK_H
26
27#include <stddef.h>
28
29struct rdesc_stack;
30
31
41void rdesc_stack_init(struct rdesc_stack **stack, size_t element_size);
42
48void rdesc_stack_destroy(struct rdesc_stack *stack);
49
56void rdesc_stack_reset(struct rdesc_stack **stack);
57
67void *rdesc_stack_at(struct rdesc_stack *stack, size_t index);
68
84void *rdesc_stack_multipush(struct rdesc_stack **stack, void *elements, size_t count);
85
93void *rdesc_stack_push(struct rdesc_stack **stack, void *element);
94
104void *rdesc_stack_multipop(struct rdesc_stack **stack, size_t count);
105
113void *rdesc_stack_pop(struct rdesc_stack **stack);
114
116void *rdesc_stack_top(struct rdesc_stack *stack);
117
119size_t rdesc_stack_len(const struct rdesc_stack *stack);
120
121
122#endif
void rdesc_stack_reset(struct rdesc_stack **stack)
Clears the stack and resets capacity to initial size.
Definition stack.c:102
size_t rdesc_stack_len(const struct rdesc_stack *stack)
Returns the current number of elements in the stack.
Definition stack.c:164
void * rdesc_stack_at(struct rdesc_stack *stack, size_t index)
Returns pointer to the element at the specified index.
Definition stack.c:111
void * rdesc_stack_multipop(struct rdesc_stack **stack, size_t count)
Pops multiple elements from the stack, and returns pointer to the element that was at the bottom of t...
Definition stack.c:136
void * rdesc_stack_push(struct rdesc_stack **stack, void *element)
Pushes a single element onto the stack.
Definition stack.c:131
void * rdesc_stack_multipush(struct rdesc_stack **stack, void *elements, size_t count)
Pushes multiple elements onto the stack.
Definition stack.c:116
void * rdesc_stack_pop(struct rdesc_stack **stack)
Removes and returns the top element from the stack.
Definition stack.c:159
void rdesc_stack_init(struct rdesc_stack **stack, size_t element_size)
Initializes a new stack with the specified element size.
Definition stack.c:85
void * rdesc_stack_top(struct rdesc_stack *stack)
Returns the top element without removing it.
Definition stack.c:154
void rdesc_stack_destroy(struct rdesc_stack *stack)
Frees all memory allocated by the stack.
Definition stack.c:97
Default implementation of the stack.
Definition stack.c:36
size_t element_size
Definition stack.c:39
char elements[]
Definition stack.c:40