File: stack.h

package info (click to toggle)
dpdk 25.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 127,892 kB
  • sloc: ansic: 2,358,479; python: 16,426; sh: 4,474; makefile: 1,713; awk: 70
file content (116 lines) | stat: -rw-r--r-- 2,100 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2019-2023 Broadcom
 * All rights reserved.
 */
#ifndef _STACK_H_
#define _STACK_H_

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

/** Stack data structure
 */
struct stack {
	int max;         /**< Maximum number of entries */
	int top;         /**< maximum value in stack */
	uint32_t *items; /**< items in the stack */
};

/** Initialize stack of uint32_t elements
 *
 *  [in] num_entries
 *    maximum number of elements in the stack
 *
 *  [in] items
 *    pointer to items (must be sized to (uint32_t * num_entries)
 *
 *  s[in] st
 *    pointer to the stack structure
 *
 *  return
 *    0 for success
 */
int stack_init(int num_entries,
	       uint32_t *items,
	       struct stack *st);

/** Return the address of the stack contents
 *
 *  [in] st
 *    pointer to the stack
 *
 *  return
 *    pointer to the stack contents
 */
uint32_t *stack_items(struct stack *st);

/** Return the size of the stack
 *
 *  [in] st
 *    pointer to the stack
 *
 *  return
 *    number of elements
 */
int32_t stack_size(struct stack *st);

/** Check if the stack is empty
 *
 * [in] st
 *   pointer to the stack
 *
 * return
 *   true or false
 */
bool stack_is_empty(struct stack *st);

/** Check if the stack is full
 *
 * [in] st
 *   pointer to the stack
 *
 * return
 *   true or false
 */
bool stack_is_full(struct stack *st);

/** Add  element x to  the stack
 *
 * [in] st
 *   pointer to the stack
 *
 * [in] x
 *   value to push on the stack
 * return
 *  0 for success
 */
int stack_push(struct stack *st, uint32_t x);

/** Pop top element x from the stack and return
 * in user provided location.
 *
 * [in] st
 *   pointer to the stack
 *
 * [in, out] x
 *  pointer to where the value popped will be written
 *
 * return
 *  0 for success
 */
int stack_pop(struct stack *st, uint32_t *x);

/** Dump stack information
 *
 * Warning: Don't use for large stacks due to prints
 *
 * [in] st
 *   pointer to the stack
 *
 * return
 *    none
 */
void stack_dump(struct stack *st);
#endif /* _STACK_H_ */