stack_u64.h (1334B)
1 #ifndef STACK_U64_H 2 #define STACK_U64_H 3 4 #include <stdint.h> 5 #include <stdlib.h> 6 7 #define BASE_STACK_SIZE 256 8 #define STACK_U64_EMPTY_POP UINT64_MAX 9 10 typedef struct { 11 size_t nmemb; 12 size_t alloc; 13 14 uint64_t *data; 15 } stack_u64; 16 17 /** 18 * Initialization of stack. 19 * 20 * Initialises memory for the stack. Use clear. 21 * 22 * @param d pointer to the address where to write the new stack 23 */ 24 void stack_u64_init(stack_u64 *d); 25 26 /** 27 * Clear a stack 28 * 29 * @param d pointer to the stack to clear 30 */ 31 void stack_u64_clear(stack_u64 *d); 32 33 /** 34 * Pushes a uint64_t onto the stack. 35 * 36 * @param d pointer to the stack 37 * @param x the uint64_t to push 38 */ 39 void stack_u64_push(stack_u64 *d, const uint64_t x); 40 41 /** 42 * Gets the element at index i in the stack. 43 * 44 * @param d pointer to the stack 45 * @param i the index to get element at 46 * @return the value of the element at index i 47 */ 48 uint64_t stack_u64_get(const stack_u64 *d, const size_t i); 49 50 /** 51 * Get the last (top) element of a stack. 52 * 53 * @param d pointer to the stack 54 */ 55 uint64_t stack_u64_getlast(const stack_u64 *d); 56 57 /** 58 * Pop an element of the stack. 59 * 60 * Note that popping never decreases the amount of memory allocated. 61 * If memory is an issue the stacks have to be destroyed and replaced. 62 * 63 * @param d pointer to the stack 64 */ 65 uint64_t stack_u64_pop(stack_u64 *d); 66 67 #endif