-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsE_Stack.h
More file actions
231 lines (182 loc) · 7.26 KB
/
IsE_Stack.h
File metadata and controls
231 lines (182 loc) · 7.26 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// --------------------------------------------------------
// Created by Egor Dolgodvorov (IsE_Katin, Krym4s) on 05.10.2020.
//
// This header contains declaration of functions, which work with stack for standart types
//
#ifndef STACK_ISE_STACK_H
#define STACK_ISE_STACK_H
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
typedef double stackType;
const stackType poison = NAN;
#define ARGNAME(x) #x
#define NCAN(a,b,c,d) a != CANARY_VALUE || b != CANARY_VALUE || c != CANARY_VALUE || d != CANARY_VALUE
#define asserted(x) || !printf ("[Error] on line number: %d\n" "return code: %s\n", __LINE__, x)
#define Debug
#ifdef Debug
#define DBG if (1)
#elif
#define DBG if (0)
#endif
const double ENLARGE_BIG_COEFFICIENT = 2;
const double ENLARGE_SMALL_COEFFICIENT = 1.5;
const double REDUCE_COEFFICIENT = 0.4;
const int MINIMUM_STACK_SIZE = 10;
const unsigned long long CANARY_VALUE = 0xBADADEEEBADADAAA;
enum StackErrorCode
{
NO_STACK_ERRORS = 0,
BAD_SIZE = 1,
UNACCEPTABLE_Member = 2,
BAD_MINIMUM_SIZE = 3,
CANARY_VALUE_CHANGED = 4,
BAD_HASH = 5
};
enum FunctionErrorCode
{
NO_FUNCTION_ERRORS = 0,
NO_FREE_MEMORY = -1,
NULL_POINTER_IN_ARGUMENT = -2,
BAD_ARGUMENT = -3
};
struct Stack;
//!----------------------------------------------------------
//! This function constructs structure Stack
//!
//! \param [out] thou - pointer to current Stack
//!
//! \return code of function or stack error
//!
//! \note every stack have it`s own minimum size that always is not more than capacity
//!----------------------------------------------------------------
int stackInit (struct Stack* thou);
//!----------------------------------------------------------
//! This function constructs structure Stack
//!
//! \param [out] thou - pointer to current Stack
//! \param [in] capacity - beginning capacity of stack structure
//!
//! \return code of function or stack error
//!
//! \note every stack have it`s own minimum size that always is not more than capacity
//!--------------------------------------------------------
int stackConstructor (struct Stack* thou, size_t capacity);
//!---------------------------------------------------------
//! Destructs current Stack
//! \param [in] thou - pointer to current Stack
//!
//! \note frees memory and makes pointers to adress to NULL
//!-------------------------------------------
void stackDestructor (struct Stack* thou);
//!-------------------------------------------------
//! Pushes new member to stack
//! \param [in] thou - pointer to current Stack
//! \param [in] newMember - member, which we push to stack
//!
//! \return code of function or stack error
//!-------------------------------------------------
int pushIntoStack (struct Stack* thou, stackType newMember);
//!---------------------------------------------------
//! Tries to enlarge stack capacity and fill new stack volume with poison
//! \param [in] thou - pointer to current stack
//!
//! \return code of function or stack error
//!
//! \note function tries to enlarge stack 4 times and after that return error code
//!---------------------------------------------------
int enlargeStack (struct Stack* thou);
//!---------------------------------------------------
//! Tries to reduce stack capacity
//! \param [in] thou - pointer to current stack
//!
//! \return code of function or stack error
//!---------------------------------------------------
int reduceStack (struct Stack* thou);
//!----------------------------------------------------
//! Put top member out of stack
//! \param [in] thou - pointer to current stack
//!
//! \return top member
//!
//! \note returns poison if stack buffer is empty
//!-----------------------------------------------------
stackType popFromStack (struct Stack* thou);
//!---------------------------------------------------
//! shows top member of stack
//! \param [in] thou - pointer to current stack
//!
//! \return top member
//!
//! \note returns poison if stack buffer is empty
//!-----------------------------------------------------
stackType topOfStack (struct Stack* thou);
//!----------------------------------------------------
//! checks if stack is correct or incorrect
//! \param [in] thou - pointer to current stack
//!
//! \return code of function or stack error
//!---------------------------------------------------
int stackError (struct Stack* thou);
//!---------------------------------------------------
//! Make logs
//! \param [in] thou - pointer to a current stack
//! \param [in] reason - name of error
//! \param [in] line - line in code, where function was executed
//! \return code of error of function
//!---------------------------------------------------
int stackDump (struct Stack* thou, char* reason, int line);
//!---------------------------------------------------
//! resizes data and change capacity of stack
//! \param [in] thou - pointer to a current stack
//! \param [in] newCapacity - capacity of changed stack
//! \return code of function or stack error
//!--------------------------------------------------
int stackResize (struct Stack* thou, size_t newCapacity);
//!---------------------------------------------
//! fill data members of stack from beginInd to endInd with poison
//! \param [in] thou - pointer to a current stack
//! \param [in] beginInd - index of first member
//! \param [in] endInd - index of last member
//!---------------------------------------------
void fillStackWithPoison (struct Stack* thou, int beginInd, int endInd);
//!----------------------------------------------
//! makes hash to identify stack
//! \param [in] thou - pointer to a current stack
//! \return hash
//!----------------------------------------------
long long makeHash (struct Stack* thou);
//!-------------------------------------
//! makes left cycle of bits
//! \param [in] value - input value
//! \return left cycle of bits
//!------------------------------------
long long ROL (long long value);
//!-------------------------------------
//! makes right cycle of bits
//! \param [in] value - input value
//! \return right cycle of bits
//!------------------------------------
long long ROR (long long value);
//!-----------------------------------
//! translates code of error to name of error
//! \param [in] errorCode - integer associated with error code
//! \return name of error
//!-----------------------------------
char* numOfErrorCode (int errorCode);
//!----------------------------------
//! Returns pointer to Stack with properate memory
//! \return pointer to Stack with properate memory
//!------------------------------------
struct Stack* newStack();
//!---------------------------------
//! enlarges stack, if we checked that it is possible
//! \param [in] condition - shows if enlarging is possible or not
//! \param [out] thou - pointer to stack
//!
//! \return code of stack or function error
//!---------------------------------
int resizeConfirm (int condition, struct Stack* thou);
void fLogsClose();
#endif //STACK_ISE_STACK_H