26 #ifndef newgen_list_included
27 #define newgen_list_included
47 #define NIL ((list)NULL)
59 #define POP(l) ((l)=(l)->cdr)
66 #define ENDP(l) ((l)==NIL)
69 #define list_undefined ((cons *)-3)
75 #define list_undefined_p(c) ((c)==list_undefined)
92 #define CAR(pcons) ((pcons)->car)
111 #define CDR(pcons) ((pcons)->cdr)
119 #define REFCAR(pc) (&(CAR(pc).p))
150 #define CONS(_t_,_i_,_l_) gen_##_t_##_cons((_i_),(_l_))
179 #define FOREACH(_fe_CASTER, _fe_item, _fe_list) \
180 list NGMID(l) = (_fe_list); \
181 for( _fe_CASTER##_TYPE _fe_item; \
183 (_fe_item= _fe_CASTER##_CAST(CAR(NGMID(l)) )); \
186 #define VOLATILE_FOREACH(_fe_CASTER, _fe_item, _fe_list) \
187 volatile list NGMID(l) = (_fe_list); \
188 for( volatile _fe_CASTER##_TYPE _fe_item; \
190 (_fe_item= _fe_CASTER##_CAST(CAR(NGMID(l)) )); \
203 #define MAPL(_map_list_cp,_code,_l) \
205 list _map_list_cp = (_l) ; \
206 for(; !ENDP(_map_list_cp); POP(_map_list_cp)) \
226 #define MAP(_map_CASTER, _map_item, _map_code, _map_list) \
228 list _map_item##_list = (_map_list); \
229 _map_CASTER##_TYPE _map_item; \
230 for(; _map_item##_list; POP(_map_item##_list)) \
232 _map_item = _map_CASTER(CAR(_map_item##_list)); \
239 #define gen_BOOL_cons gen_bool_cons
243 #define gen_INT_cons gen_int_cons
250 #define gen_LIST_cons gen_list_cons
257 #define gen_CONSP_cons gen_list_cons
261 #define gen_STRING_cons gen_string_cons
268 extern void gen_copy(
void *,
void *);
269 extern bool gen_eq(
const void *,
const void *);
371 #define gen_sweep_forward_init(l, p1, p2) gen_sweep_init(l, gen_sweep_forward, p1, p2)
372 #define gen_sweep_backward_init(l, p1, p2) gen_sweep_init(l, gen_sweep_backward, p1, p2)
void *() gen_extract_func_t(const gen_chunk)
void * gen_chunk_identity(gen_chunk)
void * gen_identity(const void *)
Just return the argument.
list gen_make_list(int,...)
void gen_fprint(FILE *, const string, const list, gen_string_func_t)
list gen_insert_list(list, const void *, list, bool)
insert nl before or after item in list l, both initial lists are consumed
list gen_list_head(list *, int)
list gen_nreverse(list)
reverse a list in place
void gen_exchange_in_list(list, const void *, const void *)
exchange items i1 & i2 in the list
void gen_remove(list *, const void *)
remove all occurences of item o from list *cpp, which is thus modified.
void gen_list_and(list *, const list)
Compute A = A inter B: complexity in O(n2)
int gen_position(const void *, const list)
Element ranks are strictly positive as for first, second, and so on.
void gen_remove_once(list *, const void *)
Remove the first occurence of o in list pl:
list gen_concatenate(const list, const list)
concatenate two lists.
void gen_map(gen_iter_func_t, const list)
list gen_once(const void *, list)
Prepend an item to a list only if it is not already in the list.
struct cons cons
The structure used to build lists in NewGen.
list gen_VOID_STAR_cons(const void *, const list)
list gen_copy_seq(const list)
Copy a list structure.
size_t gen_length(const list)
list gen_cons(const void *, const list)
list gen_common_prefix(const list, const list)
return the common list prefix of lists l1 and l2.
void gen_list_and_not(list *, const list)
Compute A = A inter non B:
bool gen_once_p(const list)
FC: ARGH...O(n^2)!
void gen_free_string_list(list)
void gen_copy(void *, void *)
#define CONS(type,x,l) gen_cons((void*) (x), (l))
list gen_some(gen_filter_func_t, const list)
list gen_nconc(list, list)
physically concatenates CP1 and CP2 but do not duplicates the elements
list gen_list_cons(const list, const list)
void gen_free_list(list)
free the spine of the list
list gen_last(const list)
Return the last element of a list.
list gen_CHUNK_cons(const gen_chunk *, const list)
bool gen_in_list_p(const void *, const list)
tell whether vo belongs to lx
size_t list_own_allocated_memory(const list)
void * gen_find_if_from_end(gen_filter_func_t, list, gen_extract_func_t)
the last match is returned
void * gen_find_if(gen_filter_func_t, const list, gen_extract_func_t)
void * gen_find_eq(const void *, const list)
list gen_nthcdr(int, const list)
caution: the first item is 0! was: return( (n<=0) ? l : gen_nthcdr( n-1, CDR( l ))) ; if n>gen_length...
void * gen_find(const void *, const list, gen_filter2_func_t, gen_extract_func_t)
list gen_append(list, const list)
bool gen_list_cyclic_p(const list)
list gen_copy_string_list(const list)
of string
void gen_mapl(gen_iter_func_t, const list)
MAP.
int gen_occurences(const void *, const list)
count occurences of vo in l
gen_chunk gen_nth(int, const list)
to be used as ENTITY(gen_nth(3, l))...
void gen_list_patch(list, const void *, const void *)
Replace all the reference to x in list l by a reference to y:
list gen_string_cons(string, const list)
void gen_free_area(void **, int)
free an area.
void * gen_find_from_end(const void *, const list, gen_filter2_func_t, gen_extract_func_t)
list gen_full_copy_list(const list)
Copy a list structure with element copy.
void gen_sort_list(list, gen_cmp_func_t)
Sorts a list of gen_chunks in place, to avoid allocations...
void gen_substitute_chunk_by_list(list *pl, const void *o, list sl)
substitute item o by list sl in list *pl, which is modified as a side effect.
list gen_bool_cons(bool, const list)
typed cons for "basic" types
void * gen_car(const list)
void gen_insert_after(const void *, const void *, list)
bool gen_replace_in_list(list, const void *, const void *)
substitute all item s by t in list l
list gen_insert_before(const void *, const void *, list)
list gen_int_cons(_int, const list)
bool gen_equals(const list, const list, gen_eq_func_t)
compares two lists using the functor given in parameters returns true if for all n,...
bool gen_eq(const void *, const void *)
list gen_typed_cons(_int, const void *, const list)
CONS a list with minimal type checking this cannot be done within the CONS macro because possible fun...
list(* gen_closure_func_t)(gen_chunk *, list)
void * gen_find_tabulated(const char *, int)
void * gen_reduce(void *, void *(*)(void *, const list), const list)
void gen_sweep_done(gen_sweep_state)
void gen_closure(gen_closure_func_t, const list)
void gen_full_free_list(list)
struct __gen_sweep_state * gen_sweep_state
gen_sweep_state gen_sweep_init(list, gen_sweep_direction, list *, list *)
initialize list l sweep in direction dir, with pointers for head & tail
gen_sweep_direction
sweep a list...
void gen_mapc_tabulated(void(*)(gen_chunk *), int)
apply fp to domain...
bool gen_sweep_update(gen_sweep_state)
list gen_filter_tabulated(bool(*)(gen_chunk *), int)
returns the list of entities with this caracteristics.
bool(* gen_filter2_func_t)(const void *, const void *)
string(* gen_string_func_t)(const void *)
void(* gen_iter_func_t)(void *)
bool(* gen_filter_func_t)(const void *)
bool(* gen_eq_func_t)(const void *, const void *)
int(* gen_cmp_func_t)(const void *, const void *)
static hash_table pl
properties are stored in this hash table (string -> property) for fast accesses.
The structure used to build lists in NewGen.
struct cons * cdr
The pointer to the next element.
gen_chunk car
The data payload of a list element.
A gen_chunk is used to store every object.