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
/*
Copyright (C) 2020 Daniel Schultz
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "n_poly.h"
void n_bpoly_stack_init(n_bpoly_stack_t S)
{
S->alloc = 0;
S->array = NULL;
S->top = 0;
}
void n_bpoly_stack_clear(n_bpoly_stack_t S)
{
slong i;
FLINT_ASSERT(S->top == 0);
for (i = 0; i < S->alloc; i++)
{
n_bpoly_clear(S->array[i]);
flint_free(S->array[i]);
}
if (S->array)
flint_free(S->array);
}
/* insure that k slots are available after top and return pointer to top */
n_bpoly_struct ** n_bpoly_stack_fit_request(n_bpoly_stack_t S, slong k)
{
slong newalloc, i;
FLINT_ASSERT(S->alloc >= S->top);
if (S->top + k > S->alloc)
{
newalloc = FLINT_MAX(WORD(1), S->top + k);
if (S->array)
{
S->array = (n_bpoly_struct **) flint_realloc(S->array,
newalloc*sizeof(n_bpoly_struct*));
}
else
{
S->array = (n_bpoly_struct **) flint_malloc(
newalloc*sizeof(n_bpoly_struct*));
}
for (i = S->alloc; i < newalloc; i++)
{
S->array[i] = (n_bpoly_struct *) flint_malloc(sizeof(n_bpoly_struct));
n_bpoly_init(S->array[i]);
}
S->alloc = newalloc;
}
return S->array + S->top;
}