76 #define STACK_PTR_NULL ((_stack_ptr) NULL)
77 #define STACK_PTR_NULL_P(x) ((x)==STACK_PTR_NULL)
78 #define STACK_DEFAULT_SIZE 50
104 #define STACK_ITERATOR_END_P(i) STACK_PTR_NULL_P(i->bucket)
106 #define DEFINE_ITERATOR(i,blk,idx,dwn,lst) \
114 #define UPDATE_ITERATOR_DOWNWARD(i) \
115 if (i->index == (size_t) -1) \
117 i->bucket = i->bucket->succ; \
118 i->index = (i->bucket) ? (i->bucket->n_item)-1 : (size_t) -1; \
121 #define UPDATE_ITERATOR_UPWARD(i) \
122 if (i->index==i->bucket->n_item) \
123 update_iterator_upward(i);
125 #define NEXT_ITERATION(i) \
128 i->index--; UPDATE_ITERATOR_DOWNWARD(i); \
132 i->index++; UPDATE_ITERATOR_UPWARD(i); \
168 *pitem = (
void*) NULL;
208 x->items = (
void **)
malloc(
sizeof(
void *)*size);
302 #define STACK_OBSERVER(name, what) \
303 int stack_##name(const stack s) { STACK_CHECK(s); return(what); }
319 #undef STACK_OBSERVER
331 for(i=(
x->n_item)-1; i>=0; i--)
344 fprintf(
f,
"stack_info about stack %p\n", s);
358 fprintf(
f,
" - type %d, size %zd, max extent %zd\n",
360 fprintf(
f,
" - buckets: %d in use, %d available\n",
379 if (
x->n_item ==
x->max_items)
391 x->items[
x->n_item++] = item;
407 s->
stack = saved,
x = saved;
415 return x->items[--
x->n_item];
423 if (
x->n_item==0)
x =
x->succ;
428 return x->items[(
x->n_item)-1];
455 if (
x->n_item==0)
x =
x->succ;
460 old =
x->items[(
x->n_item)-1];
461 x->items[(
x->n_item)-1] = item;
struct _newgen_struct_type_ * type
void gen_free_area(void **p, int size)
free an area.
#define message_assert(msg, ex)
struct __stack_iterator * stack_iterator
#define STACK_NULL
defines for empty values
#define STACK_MAP_X(_item, _itemtype, _code, _stack, _downwards)
not needed
bool stack_empty_p(const stack)
struct __stack_head * stack
STACK MANAGEMENT – headers.
#define stack_undefined_p(s)
void(* gen_iter_func_t)(void *)
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
struct _newgen_struct_value_ * value
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
stack stack_make(int type, int bucket_size, int policy)
ALLOCATEs a new stack of type.
#define STACK_DEFAULT_SIZE
struct __stack_bucket * _stack_ptr
static void update_iterator_upward(stack_iterator i)
and also *stack_iterator (in headers)
static void stack_iterator_internal_init(const stack s, int down, stack_iterator i)
static void free_bucket(_stack_ptr x)
FREEs the stack.
struct __stack_iterator _stack_iterator
STACK ITERATOR.
bool stack_iterator_next_and_go(stack_iterator i, void **pitem)
X-ward.
static _stack_ptr find_or_allocate(stack s)
search for a new bucket, first in the available list, if none are available, a new bucket is allocate...
stack stack_copy(const stack s)
duplicate a stack with its contents.
#define UPDATE_ITERATOR_DOWNWARD(i)
static _stack_ptr allocate_bucket(int size)
allocates a bucket of size size
static void free_buckets(_stack_ptr x)
struct __stack_bucket _stack_bucket
STACK STRUCTURES.
stack_iterator stack_iterator_init(const stack s, bool down)
stack iterator
#define STACK_PTR_NULL
and also *stack (in headers)
void stack_iterator_end(stack_iterator *pi)
static int number_of_buckets(_stack_ptr x)
void stack_info(FILE *f, const stack s)
#define STACK_ITERATOR_END_P(i)
void stack_free(stack *ps)
type, bucket_size, policy
void * stack_head(const stack s)
returns the item on top of stack s
struct __stack_head _stack_head
the stack head
#define NEXT_ITERATION(i)
bool stack_iterator_end_p(stack_iterator i)
void * stack_nth(const stack s, int nskip)
returns the nth item starting from the head and counting from 1, when possible, or NULL,...
#define STACK_OBSERVER(name, what)
STACK MISCELLANEOUS.
void * stack_replace(void *item, stack s)
REPLACEs the item on top of stack s, and returns the old item.
void * stack_pop(stack s)
POPs one item from stack s.
#define STACK_PTR_NULL_P(x)
void stack_push(void *item, stack s)
STACK USE.
void stack_map(const stack s, gen_iter_func_t f)
APPLY f to all items of stack s;.
#define DEFINE_ITERATOR(i, blk, idx, dwn, lst)
struct __stack_bucket * succ
the items (only pointers at the moment)
void ** items
the max number of items of this bucket
size_t max_items
next available item in the bucket
int type
number of allocated buckets
int policy
as BASIC, LIST, EXTERNAL, CHUNK, domain?
_stack_ptr avail
buckets in use by the stack
_stack_ptr stack
maximum extension of the stack
size_t max_extent
current number of elements in stack
size_t n_buckets
reference bucket size for allocation
size_t bucket_size
allocated buckets not in use anymore
size_t index
true if downward iterations
bool downward
current bucket
_stack_ptr list
current index in bucket